mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Don't rely on key prefix, remove code duplication (_api_prefix)
CURA-2384
This commit is contained in:
parent
b25b92a81b
commit
042ebe76ba
3 changed files with 16 additions and 9 deletions
|
@ -85,7 +85,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
id: editButton
|
id: editButton
|
||||||
text: catalog.i18nc("@action:button", "Edit")
|
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:
|
onClicked:
|
||||||
{
|
{
|
||||||
manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
|
manualPrinterDialog.showDialog(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress);
|
||||||
|
@ -96,7 +96,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
id: removeButton
|
id: removeButton
|
||||||
text: catalog.i18nc("@action:button", "Remove")
|
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)
|
onClicked: manager.removeManualPrinter(base.selectedPrinter.getKey(), base.selectedPrinter.ipAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ Cura.MachineAction
|
||||||
{
|
{
|
||||||
base.selectedPrinter = listview.model[currentIndex];
|
base.selectedPrinter = listview.model[currentIndex];
|
||||||
// Only allow connecting if the printer has responded to API query since the last refresh
|
// 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()
|
Component.onCompleted: manager.startDiscovery()
|
||||||
delegate: Rectangle
|
delegate: Rectangle
|
||||||
|
|
|
@ -36,11 +36,12 @@ class AuthState(IntEnum):
|
||||||
## Network connected (wifi / lan) printer that uses the Ultimaker API
|
## Network connected (wifi / lan) printer that uses the Ultimaker API
|
||||||
@signalemitter
|
@signalemitter
|
||||||
class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
def __init__(self, key, address, properties):
|
def __init__(self, key, address, properties, api_prefix):
|
||||||
super().__init__(key)
|
super().__init__(key)
|
||||||
self._address = address
|
self._address = address
|
||||||
self._key = key
|
self._key = key
|
||||||
self._properties = properties # Properties dict as provided by zero conf
|
self._properties = properties # Properties dict as provided by zero conf
|
||||||
|
self._api_prefix = api_prefix
|
||||||
|
|
||||||
self._gcode = None
|
self._gcode = None
|
||||||
self._print_finished = True # _print_finsihed == False means we're halfway in a print
|
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._material_ids = [""] * self._num_extruders
|
||||||
self._hotend_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.setPriority(2) # Make sure the output device gets selected above local file output
|
||||||
self.setName(key)
|
self.setName(key)
|
||||||
self.setShortDescription(i18n_catalog.i18nc("@action:button", "Print over network"))
|
self.setShortDescription(i18n_catalog.i18nc("@action:button", "Print over network"))
|
||||||
|
@ -187,6 +186,14 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
def getProperties(self):
|
def getProperties(self):
|
||||||
return self._properties
|
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
|
## Get the unique key of this machine
|
||||||
# \return key String containing the key of the machine.
|
# \return key String containing the key of the machine.
|
||||||
@pyqtSlot(result = str)
|
@pyqtSlot(result = str)
|
||||||
|
|
|
@ -73,7 +73,7 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
|
|
||||||
name = address
|
name = address
|
||||||
instance_name = "manual:%s" % 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:
|
if instance_name not in self._printers:
|
||||||
# Add a preliminary printer instance
|
# Add a preliminary printer instance
|
||||||
|
@ -111,7 +111,7 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
name = ("%s (%s)" % (system_info["name"], address))
|
name = ("%s (%s)" % (system_info["name"], address))
|
||||||
|
|
||||||
instance_name = "manual:%s" % 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:
|
if instance_name in self._printers:
|
||||||
# Only replace the printer if it is still in the list of (manual) printers
|
# Only replace the printer if it is still in the list of (manual) printers
|
||||||
self.removePrinter(instance_name)
|
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.
|
## Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
|
||||||
def addPrinter(self, name, address, properties):
|
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
|
self._printers[printer.getKey()] = printer
|
||||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
if global_container_stack and printer.getKey() == global_container_stack.getMetaDataEntry("um_network_key"):
|
if global_container_stack and printer.getKey() == global_container_stack.getMetaDataEntry("um_network_key"):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue