diff --git a/DiscoverUM3Action.py b/DiscoverUM3Action.py index 89b024b8bd..48cd3de247 100644 --- a/DiscoverUM3Action.py +++ b/DiscoverUM3Action.py @@ -1,9 +1,32 @@ from cura.MachineAction import MachineAction +from UM.Application import Application + +from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot + class DiscoverUM3Action(MachineAction): def __init__(self): super().__init__("DiscoverUM3Action", "Discover printers") self._qml_url = "DiscoverUM3Action.qml" - def _execute(self): - pass \ No newline at end of file + self._network_plugin = None + + printerDetected = pyqtSignal() + + @pyqtSlot() + def startDiscovery(self): + if not self._network_plugin: + self._network_plugin = Application.getInstance().getOutputDeviceManager().getOutputDevicePlugin("JediWifiPrintingPlugin") + self._network_plugin.addPrinterSignal.connect(self._onPrinterAdded) + self.printerDetected.emit() + + def _onPrinterAdded(self, *args): + self.printerDetected.emit() + + @pyqtProperty("QVariantList", notify = printerDetected) + def foundDevices(self): + if self._network_plugin: + print(list(self._network_plugin.getPrinters().keys())) + return list(self._network_plugin.getPrinters().keys()) + else: + return [] diff --git a/DiscoverUM3Action.qml b/DiscoverUM3Action.qml index 1d26d143f8..7935298008 100644 --- a/DiscoverUM3Action.qml +++ b/DiscoverUM3Action.qml @@ -22,5 +22,10 @@ Cura.MachineAction wrapMode: Text.WordWrap font.pointSize: 18; } + Button + { + text: "Start looking!" + onClicked: manager.startDiscovery() + } } } \ No newline at end of file diff --git a/NetworkPrinterOutputDevicePlugin.py b/NetworkPrinterOutputDevicePlugin.py index fed761b772..cd4de6e4f8 100644 --- a/NetworkPrinterOutputDevicePlugin.py +++ b/NetworkPrinterOutputDevicePlugin.py @@ -31,6 +31,9 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): def stop(self): self._zero_conf.close() + def getPrinters(self): + return self._printers + def _onGlobalStackChanged(self): active_machine = Application.getInstance().getGlobalContainerStack() if not active_machine: