mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Implement Adding, Editing and Removing manual printers
CURA-2384
This commit is contained in:
parent
eba49ee8c2
commit
578b4d3826
3 changed files with 42 additions and 8 deletions
|
@ -52,6 +52,22 @@ class DiscoverUM3Action(MachineAction):
|
|||
else:
|
||||
self._network_plugin.startDiscovery()
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def removeManualPrinter(self, key, address):
|
||||
if not self._network_plugin:
|
||||
return
|
||||
|
||||
self._network_plugin.removeManualPrinter(key, address)
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def setManualPrinter(self, key, address):
|
||||
if key != "":
|
||||
# This manual printer replaces a current manual printer
|
||||
self._network_plugin.removeManualPrinter(key)
|
||||
|
||||
if address != "":
|
||||
self._network_plugin.addManualPrinter(address)
|
||||
|
||||
def _onPrinterDiscoveryChanged(self, *args):
|
||||
self._last_zeroconf_event_time = time.time()
|
||||
self.printersChanged.emit()
|
||||
|
|
|
@ -96,7 +96,7 @@ Cura.MachineAction
|
|||
id: removeButton
|
||||
text: catalog.i18nc("@action:button", "Remove")
|
||||
enabled: base.selectedPrinter && base.selectedPrinter.getKey().substr(0,7) =="manual:"
|
||||
onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey())
|
||||
onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress)
|
||||
}
|
||||
|
||||
Button
|
||||
|
|
|
@ -39,9 +39,9 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
Application.getInstance().globalContainerStackChanged.connect(self.reCheckConnections)
|
||||
|
||||
# Get list of manual printers from preferences
|
||||
preferences = Preferences.getInstance()
|
||||
preferences.addPreference("um3networkprinting/manual_instances", "") # A comma-separated list of ip adresses or hostnames
|
||||
self._manual_instances = preferences.getValue("um3networkprinting/manual_instances").split(",")
|
||||
self._preferences = Preferences.getInstance()
|
||||
self._preferences.addPreference("um3networkprinting/manual_instances", "") # A comma-separated list of ip adresses or hostnames
|
||||
self._manual_instances = self._preferences.getValue("um3networkprinting/manual_instances").split(",")
|
||||
|
||||
addPrinterSignal = Signal()
|
||||
removePrinterSignal = Signal()
|
||||
|
@ -65,11 +65,17 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
self.addManualPrinter(address)
|
||||
|
||||
def addManualPrinter(self, address):
|
||||
# Add a preliminary printer instance
|
||||
if address not in self._manual_instances:
|
||||
self._manual_instances.append(address)
|
||||
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
|
||||
|
||||
name = address
|
||||
instance_name = "manual:%s" % address
|
||||
properties = { b"name": name.encode("UTF-8") }
|
||||
self.addPrinter(instance_name, address, properties)
|
||||
|
||||
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
|
||||
|
@ -77,6 +83,16 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
name_request = QNetworkRequest(url)
|
||||
self._network_manager.get(name_request)
|
||||
|
||||
def removeManualPrinter(self, key, address = None):
|
||||
if key in self._printers:
|
||||
if not address:
|
||||
address = self._printers[key].ipAddress
|
||||
self.removePrinter(key)
|
||||
|
||||
if address in self._manual_instances:
|
||||
self._manual_instances.remove(address)
|
||||
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
|
||||
|
||||
## Handler for all requests that have finished.
|
||||
def _onNetworkRequestFinished(self, reply):
|
||||
reply_url = reply.url().toString()
|
||||
|
@ -91,8 +107,10 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
|||
|
||||
instance_name = "manual:%s" % address
|
||||
properties = { b"name": name.encode("UTF-8") }
|
||||
self.removePrinter(instance_name)
|
||||
self.addPrinter(instance_name, address, properties)
|
||||
if instance_name in self._printers:
|
||||
# Only replace the printer if it is still in the list of (manual) printers
|
||||
self.removePrinter(instance_name)
|
||||
self.addPrinter(instance_name, address, properties)
|
||||
|
||||
## Stop looking for devices on network.
|
||||
def stop(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue