blob: 27c5ef66388dc4cf81140eb5ed7fa75926655930 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
from cura.MachineAction import MachineAction
from UM.Application import Application
from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
class DiscoverUM3Action(MachineAction):
def __init__(self):
super().__init__("DiscoverUM3Action", catalog.i18nc("@action","Connect via Network"))
self._qml_url = "DiscoverUM3Action.qml"
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:
printers = self._network_plugin.getPrinters()
return list(printers.values())
else:
return []
@pyqtSlot(str)
def setKey(self, key):
global_container_stack = Application.getInstance().getGlobalContainerStack()
if global_container_stack:
if "um_network_key" in global_container_stack.getMetaData():
global_container_stack.setMetaDataEntry("um_network_key", key)
else:
global_container_stack.addMetaDataEntry("um_network_key", key)
if self._network_plugin:
# Ensure that the connection states are refreshed.
self._network_plugin.reCheckConnections()
|