diff --git a/cura/API/Machines.py b/cura/API/Machines.py index 3fd7d9138a..cc67d8ab54 100644 --- a/cura/API/Machines.py +++ b/cura/API/Machines.py @@ -25,8 +25,8 @@ class Machines(QObject): super().__init__(parent) self._application = application - @pyqtSlot(result=dict) - def getCurrentMachine(self) -> dict: + @pyqtSlot(result="QVariantMap") + def getCurrentMachine(self) -> "QVariantMap": # Since Cura doesn't have a machine class, we're going to make a fake one to make our # lives a little bit easier. fake_machine = { diff --git a/cura/API/__init__.py b/cura/API/__init__.py index 8e73680dfe..0a5eab9535 100644 --- a/cura/API/__init__.py +++ b/cura/API/__init__.py @@ -62,7 +62,7 @@ class CuraAPI(QObject): def backups(self) -> "Backups": return self._backups - @property + @pyqtProperty(QObject) def machines(self) -> "Machines": return self._machines diff --git a/plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml b/plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml index ecec87ef02..c250c1feb4 100644 --- a/plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml +++ b/plugins/UM3NetworkPrinting/resources/qml/DiscoverUM3Action.qml @@ -27,13 +27,14 @@ Cura.MachineAction { var printerKey = base.selectedDevice.key var printerName = base.selectedDevice.name // TODO To change when the groups have a name - if (manager.getStoredKey() != printerKey) + if (Cura.API.machines.getCurrentMachine()["um_network_key"] != printerKey) { // Check if there is another instance with the same key if (!manager.existsKey(printerKey)) { - manager.associateActiveMachineWithPrinterDevice(base.selectedDevice) - manager.setGroupName(printerName) // TODO To change when the groups have a name + Cura.API.machines.addOutputDeviceToCurrentMachine(base.selectedDevice) + Cura.API.machines.setCurrentMachineGroupName(printerName) // TODO To change when the groups have a name + manager.refreshConnections() completed() } else @@ -156,7 +157,7 @@ Cura.MachineAction var selectedKey = manager.getLastManualEntryKey() // If there is no last manual entry key, then we select the stored key (if any) if (selectedKey == "") - selectedKey = manager.getStoredKey() + selectedKey = Cura.API.machines.getCurrentMachine()["um_network_key"] for(var i = 0; i < model.length; i++) { if(model[i].key == selectedKey) { diff --git a/plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py b/plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py index 04f3c7f25a..6b6e466219 100644 --- a/plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py +++ b/plugins/UM3NetworkPrinting/src/DiscoverUM3Action.py @@ -108,27 +108,32 @@ class DiscoverUM3Action(MachineAction): else: return [] - # TODO: Should be able to just access the API from QML. - @pyqtSlot(str) - def setGroupName(self, group_name: str) -> None: - self._api.machines.setCurrentMachineGroupName(group_name) + # # TODO: Should be able to just access the API from QML. + # @pyqtSlot(str) + # def setGroupName(self, group_name: str) -> None: + # self._api.machines.setCurrentMachineGroupName(group_name) + # if self._network_plugin: + # self._network_plugin.refreshConnections() + + # # TODO: Should be able to just access the API from QML. + # @pyqtSlot(QObject) + # def associateActiveMachineWithPrinterDevice(self, output_device: Optional["PrinterOutputDevice"]) -> None: + # self._api.machines.addOutputDeviceToCurrentMachine(output_device) + + @pyqtSlot() + def refreshConnections(self) -> None: if self._network_plugin: self._network_plugin.refreshConnections() - # TODO: Should be able to just access the API from QML. - @pyqtSlot(QObject) - def associateActiveMachineWithPrinterDevice(self, output_device: Optional["PrinterOutputDevice"]) -> None: - self._api.machines.addOutputDeviceToCurrentMachine(output_device) - if self._network_plugin: - self._network_plugin.refreshConnections() - - # TODO: Better naming needed. Stored where? This is current machine's key. - # TODO: CHANGE TO HOSTNAME - # TODO: Should be able to just access the API from QML. - @pyqtSlot(result = str) - def getStoredKey(self) -> str: - current_machine = self._api.machines.getCurrentMachine() - return current_machine["um_network_key"] + # # TODO: Better naming needed. Stored where? This is current machine's key. + # # TODO: CHANGE TO HOSTNAME + # # TODO: Should be able to just access the API from QML. + # @pyqtSlot(result = str) + # def getStoredKey(self) -> str: + # current_machine = self._api.machines.getCurrentMachine() + # if current_machine: + # return current_machine["um_network_key"] + # return "" # TODO: CHANGE TO HOSTNAME @pyqtSlot(result = str)