diff --git a/DiscoverUM3Action.qml b/DiscoverUM3Action.qml index 0cd4ba0481..4daeaa1c37 100644 --- a/DiscoverUM3Action.qml +++ b/DiscoverUM3Action.qml @@ -11,6 +11,7 @@ Cura.MachineAction id: base anchors.fill: parent; property var selectedPrinter: null + property bool completeProperties: true property var connectingToPrinter: null Connections @@ -84,7 +85,7 @@ Cura.MachineAction { id: editButton text: catalog.i18nc("@action:button", "Edit") - enabled: base.selectedPrinter && base.selectedPrinter.getKey().substr(0,7) =="manual:" + enabled: base.selectedPrinter != null && (base.selectedPrinter.getKey().substr(0,7) =="manual:") onClicked: { manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress); @@ -95,7 +96,7 @@ Cura.MachineAction { id: removeButton text: catalog.i18nc("@action:button", "Remove") - enabled: base.selectedPrinter && base.selectedPrinter.getKey().substr(0,7) =="manual:" + enabled: base.selectedPrinter != null && (base.selectedPrinter.getKey().substr(0,7) =="manual:") onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress) } @@ -150,7 +151,12 @@ Cura.MachineAction } width: parent.width currentIndex: -1 - onCurrentIndexChanged: base.selectedPrinter = listview.model[currentIndex] + onCurrentIndexChanged: + { + 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 != ""); + } Component.onCompleted: manager.startDiscovery() delegate: Rectangle { @@ -252,7 +258,7 @@ Cura.MachineAction Button { text: catalog.i18nc("@action:button", "Connect") - enabled: base.selectedPrinter ? true : false + enabled: (base.selectedPrinter && base.completeProperties) ? true : false onClicked: connectToPrinter() } } diff --git a/NetworkPrinterOutputDevicePlugin.py b/NetworkPrinterOutputDevicePlugin.py index 96c43d5d0d..4843ab8975 100644 --- a/NetworkPrinterOutputDevicePlugin.py +++ b/NetworkPrinterOutputDevicePlugin.py @@ -63,7 +63,8 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): # Look for manual instances from preference for address in self._manual_instances: - self.addManualPrinter(address) + if address: + self.addManualPrinter(address) def addManualPrinter(self, address): if address not in self._manual_instances: @@ -72,17 +73,13 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): name = address instance_name = "manual:%s" % address - properties = { b"name": name.encode("UTF-8") } + properties = { b"name": name.encode("UTF-8"), b"incomplete": True } if instance_name not in self._printers: # Add a preliminary printer instance self.addPrinter(instance_name, address, properties) - # Check if a printer exists at this address - # If a printer responds, it will replace the preliminary printer created above - url = QUrl("http://" + address + self._api_prefix + "system") - name_request = QNetworkRequest(url) - self._network_manager.get(name_request) + self.checkManualPrinter(address) def removeManualPrinter(self, key, address = None): if key in self._printers: @@ -94,6 +91,13 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin): self._manual_instances.remove(address) self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances)) + def checkManualPrinter(self, address): + # Check if a printer exists at this address + # If a printer responds, it will replace the preliminary printer created above + url = QUrl("http://" + address + self._api_prefix + "system") + name_request = QNetworkRequest(url) + self._network_manager.get(name_request) + ## Handler for all requests that have finished. def _onNetworkRequestFinished(self, reply): reply_url = reply.url().toString()