Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Edwards <s.edwards@ultimaker.com>2017-10-12 13:41:21 +0300
committerSimon Edwards <s.edwards@ultimaker.com>2017-10-12 13:41:21 +0300
commit427afdbe23c45604ecc28c2fe287e18733d7b4be (patch)
treee0ffbfcad0b087af85a243abd845d59d81005a24
parentbb1dd0e3d4ceeca5b7b9109ab43c76255b96fe1d (diff)
Correctly set up the cluster output device instances with the cluster size
This fixes the Cura Connect messages shown in the network printer selection dialog. CL-555
-rw-r--r--plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py
index ab9fbc64a8..24d65b47a8 100644
--- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py
+++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevicePlugin.py
@@ -153,7 +153,18 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin):
if status_code == 200:
# We know it's a cluster printer
Logger.log("d", "Cluster printer detected: [%s]", reply.url())
+
+ try:
+ cluster_printers_list = json.loads(bytes(reply.readAll()).decode("utf-8"))
+ except json.JSONDecodeError:
+ Logger.log("e", "Printer returned invalid JSON.")
+ return
+ except UnicodeDecodeError:
+ Logger.log("e", "Printer returned incorrect UTF-8.")
+ return
+
self._network_requests_buffer[address]["cluster"] = True
+ self._network_requests_buffer[address]["cluster_size"] = len(cluster_printers_list)
else:
Logger.log("d", "This url is not from a cluster printer: [%s]", reply.url())
self._network_requests_buffer[address]["cluster"] = False
@@ -165,7 +176,6 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin):
instance_name = "manual:%s" % address
system_info = self._network_requests_buffer[address]["system"]
- is_cluster = self._network_requests_buffer[address]["cluster"]
machine = "unknown"
if "variant" in system_info:
variant = system_info["variant"]
@@ -181,10 +191,14 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin):
b"manual": b"true",
b"machine": machine.encode("utf-8")
}
+
+ if self._network_requests_buffer[address]["cluster"]:
+ properties[b"cluster_size"] = self._network_requests_buffer[address]["cluster_size"]
+
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, force_cluster=is_cluster)
+ self.addPrinter(instance_name, address, properties)
del self._network_requests_buffer[address]
@@ -215,9 +229,9 @@ class NetworkPrinterOutputDevicePlugin(QObject, OutputDevicePlugin):
self._printers[key].connectionStateChanged.disconnect(self._onPrinterConnectionStateChanged)
## Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
- def addPrinter(self, name, address, properties, force_cluster=False):
+ def addPrinter(self, name, address, properties):
cluster_size = int(properties.get(b"cluster_size", -1))
- if force_cluster or cluster_size >= 0:
+ if cluster_size >= 0:
printer = NetworkClusterPrinterOutputDevice.NetworkClusterPrinterOutputDevice(
name, address, properties, self._api_prefix)
else: