diff --git a/DiscoverUM3Action.qml b/DiscoverUM3Action.qml index 5bac7d89ba..159d72a821 100644 --- a/DiscoverUM3Action.qml +++ b/DiscoverUM3Action.qml @@ -85,7 +85,7 @@ Cura.MachineAction { id: editButton text: catalog.i18nc("@action:button", "Edit") - enabled: base.selectedPrinter != null && (base.selectedPrinter.getKey().substr(0,7) =="manual:") + enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true" onClicked: { manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress); @@ -96,7 +96,7 @@ Cura.MachineAction { id: removeButton text: catalog.i18nc("@action:button", "Remove") - enabled: base.selectedPrinter != null && (base.selectedPrinter.getKey().substr(0,7) =="manual:") + enabled: base.selectedPrinter != null && base.selectedPrinter.getProperty("manual") == "true" onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress) } @@ -155,7 +155,7 @@ Cura.MachineAction { base.selectedPrinter = listview.model[currentIndex]; // Only allow connecting if the printer has responded to API query since the last refresh - base.completeProperties = base.selectedPrinter != null && (base.selectedPrinter.firmwareVersion != ""); + base.completeProperties = base.selectedPrinter != null && base.selectedPrinter.getProperty("incomplete") != "true"; } Component.onCompleted: manager.startDiscovery() delegate: Rectangle diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index e2fe36f118..e3eb15f859 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -36,11 +36,12 @@ class AuthState(IntEnum): ## Network connected (wifi / lan) printer that uses the Ultimaker API @signalemitter class NetworkPrinterOutputDevice(PrinterOutputDevice): - def __init__(self, key, address, properties): + def __init__(self, key, address, properties, api_prefix): super().__init__(key) self._address = address self._key = key self._properties = properties # Properties dict as provided by zero conf + self._api_prefix = api_prefix self._gcode = None self._print_finished = True # _print_finsihed == False means we're halfway in a print @@ -94,8 +95,6 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._material_ids = [""] * self._num_extruders self._hotend_ids = [""] * self._num_extruders - self._api_version = "1" - self._api_prefix = "/api/v" + self._api_version + "/" self.setPriority(2) # Make sure the output device gets selected above local file output self.setName(key) self.setShortDescription(i18n_catalog.i18nc("@action:button", "Print over network")) @@ -187,6 +186,14 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): def getProperties(self): return self._properties + @pyqtSlot(str, result = str) + def getProperty(self, key): + key = key.encode("utf-8") + if key in self._properties: + return self._properties.get(key, b"").decode("utf-8") + else: + return "" + ## Get the unique key of this machine # \return key String containing the key of the machine. @pyqtSlot(result = str) diff --git a/NetworkPrinterOutputDevicePlugin.py b/NetworkPrinterOutputDevicePlugin.py index 4843ab8975..8dc3cd8646 100644 --- a/NetworkPrinterOutputDevicePlugin.py +++ b/NetworkPrinterOutputDevicePlugin.py @@ -73,7 +73,7 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): name = address instance_name = "manual:%s" % address - properties = { b"name": name.encode("UTF-8"), b"incomplete": True } + properties = { b"name": name.encode("utf-8"), b"manual": b"true", b"incomplete": b"true" } if instance_name not in self._printers: # Add a preliminary printer instance @@ -111,7 +111,7 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): name = ("%s (%s)" % (system_info["name"], address)) instance_name = "manual:%s" % address - properties = { b"name": name.encode("UTF-8"), b"firmware_version": system_info["firmware"].encode("UTF-8") } + properties = { b"name": name.encode("utf-8"), b"firmware_version": system_info["firmware"].encode("utf-8"), b"manual": b"true" } if instance_name in self._printers: # Only replace the printer if it is still in the list of (manual) printers self.removePrinter(instance_name) @@ -139,7 +139,7 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): ## Because the model needs to be created in the same thread as the QMLEngine, we use a signal. def addPrinter(self, name, address, properties): - printer = NetworkPrinterOutputDevice.NetworkPrinterOutputDevice(name, address, properties) + printer = NetworkPrinterOutputDevice.NetworkPrinterOutputDevice(name, address, properties, self._api_prefix) self._printers[printer.getKey()] = printer global_container_stack = Application.getInstance().getGlobalContainerStack() if global_container_stack and printer.getKey() == global_container_stack.getMetaDataEntry("um_network_key"):