From 216b1a7a14c1cfd093b9af28a4bf4473ead1232b Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 20 Jul 2017 11:39:12 +0200 Subject: [PATCH 1/2] Added control item to printOutputDevice CURA-4057 --- cura/PrinterOutputDevice.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index e23efc0f5a..60df3c3f6e 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -65,6 +65,11 @@ class PrinterOutputDevice(QObject, OutputDevice): self._monitor_view_qml_path = "" self._monitor_component = None self._monitor_item = None + + self._control_view_qml_path = "" + self._control_component = None + self._control_item = None + self._qml_context = None def requestWrite(self, nodes, file_name = None, filter_by_machine = False, file_handler = None): @@ -131,6 +136,29 @@ class PrinterOutputDevice(QObject, OutputDevice): return self._monitor_item + @pyqtProperty(QObject, constant=True) + def controlItem(self): + if not self._control_component: + self._createControlViewFromQML() + + return self._control_item + + def _createControlViewFromQML(self): + path = QUrl.fromLocalFile(self._monitor_view_qml_path) + + # Because of garbage collection we need to keep this referenced by python. + self._control_component = QQmlComponent(Application.getInstance()._engine, path) + + # Check if the context was already requested before (Printer output device might have multiple items in the future) + if self._qml_context is None: + self._qml_context = QQmlContext(Application.getInstance()._engine.rootContext()) + self._qml_context.setContextProperty("OutputDevice", self) + + self._control_item = self._control_component.create(self._qml_context) + if self._control_item is None: + Logger.log("e", "QQmlComponent status %s", self._control_component.status()) + Logger.log("e", "QQmlComponent error string %s", self._control_component.errorString()) + def _createMonitorViewFromQML(self): path = QUrl.fromLocalFile(self._monitor_view_qml_path) From 6e55bf2d8fb6117a86ef0037b0ddb505f161b04a Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 20 Jul 2017 13:30:57 +0200 Subject: [PATCH 2/2] If output device has a contorl item, that one is used. If a printerOutput device does not define anything, the fallback is used. CURA-4057 --- cura/PrinterOutputDevice.py | 2 +- .../NetworkPrinterOutputDevice.py | 1 - resources/qml/Sidebar.qml | 41 ++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index 60df3c3f6e..bf013e4b9f 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -144,7 +144,7 @@ class PrinterOutputDevice(QObject, OutputDevice): return self._control_item def _createControlViewFromQML(self): - path = QUrl.fromLocalFile(self._monitor_view_qml_path) + path = QUrl.fromLocalFile(self._control_view_qml_path) # Because of garbage collection we need to keep this referenced by python. self._control_component = QQmlComponent(Application.getInstance()._engine, path) diff --git a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py index b309691e81..03636fd0b0 100755 --- a/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/NetworkPrinterOutputDevice.py @@ -179,7 +179,6 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): self._compressing_print = False self._monitor_view_qml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "MonitorItem.qml") - printer_type = self._properties.get(b"machine", b"").decode("utf-8") if printer_type.startswith("9511"): self._updatePrinterType("ultimaker3_extended") diff --git a/resources/qml/Sidebar.qml b/resources/qml/Sidebar.qml index b57b56c292..db5f60862d 100755 --- a/resources/qml/Sidebar.qml +++ b/resources/qml/Sidebar.qml @@ -20,6 +20,7 @@ Rectangle // Is there an output device for this printer? property bool printerConnected: Cura.MachineManager.printerOutputDevices.length != 0 property bool printerAcceptsCommands: printerConnected && Cura.MachineManager.printerOutputDevices[0].acceptsCommands + property var connectedPrinter: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null property int backendState: UM.Backend.state; property bool monitoringPrint: false @@ -344,12 +345,48 @@ Rectangle Loader { + id: controlItem anchors.bottom: footerSeparator.top anchors.top: headerSeparator.bottom anchors.left: base.left anchors.right: base.right - source: monitoringPrint ? "PrintMonitor.qml": "SidebarContents.qml" - } + sourceComponent: + { + if(monitoringPrint && connectedPrinter != null) + { + if(connectedPrinter.controlItem != null) + { + return connectedPrinter.controlItem + } + } + return null + } + } + + Loader + { + anchors.bottom: footerSeparator.top + anchors.top: headerSeparator.bottom + anchors.left: base.left + anchors.right: base.right + source: + { + if(controlItem.sourceComponent == null) + { + if(monitoringPrint) + { + return "PrintMonitor.qml" + } else + { + return "SidebarContents.qml" + } + } + else + { + return "" + } + } + } Rectangle {