From 4252b956039f4875e63735944ee8d1f36d5c1cb8 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Fri, 14 Dec 2018 11:28:18 +0100 Subject: [PATCH] Make ConnectionType Enum type accessible to QML CURA-6011 --- cura/CuraApplication.py | 3 +++ cura/PrinterOutputDevice.py | 8 +++++++- resources/qml/PrinterSelector/MachineSelectorList.qml | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 7e11fd4d59..a50d7d55c8 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -113,6 +113,7 @@ from cura.Settings.CuraFormulaFunctions import CuraFormulaFunctions from cura.ObjectsModel import ObjectsModel +from cura.PrinterOutputDevice import PrinterOutputDevice from cura.PrinterOutput.NetworkMJPGImage import NetworkMJPGImage from UM.FlameProfiler import pyqtSlot @@ -975,6 +976,8 @@ class CuraApplication(QtApplication): qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.getInstance) qmlRegisterType(SidebarCustomMenuItemsModel, "Cura", 1, 0, "SidebarCustomMenuItemsModel") + qmlRegisterType(PrinterOutputDevice, "Cura", 1, 0, "PrinterOutputDevice") + from cura.API import CuraAPI qmlRegisterSingletonType(CuraAPI, "Cura", 1, 1, "API", self.getCuraAPI) diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index 2db03a4e87..298c690b01 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -4,7 +4,7 @@ from UM.Decorators import deprecated from UM.i18n import i18nCatalog from UM.OutputDevice.OutputDevice import OutputDevice -from PyQt5.QtCore import pyqtProperty, pyqtSignal, QObject, QTimer, QUrl +from PyQt5.QtCore import pyqtProperty, pyqtSignal, QObject, QTimer, QUrl, Q_ENUMS from PyQt5.QtWidgets import QMessageBox from UM.Logger import Logger @@ -54,6 +54,12 @@ class ConnectionType(IntEnum): # For all other uses it should be used in the same way as a "regular" OutputDevice. @signalemitter class PrinterOutputDevice(QObject, OutputDevice): + + # Put ConnectionType here with Q_ENUMS() so it can be registered as a QML type and accessible via QML, and there is + # no need to remember what those Enum integer values mean. + ConnectionType = ConnectionType + Q_ENUMS(ConnectionType) + printersChanged = pyqtSignal() connectionStateChanged = pyqtSignal(str) acceptsCommandsChanged = pyqtSignal() diff --git a/resources/qml/PrinterSelector/MachineSelectorList.qml b/resources/qml/PrinterSelector/MachineSelectorList.qml index 3324b9948b..bc3fe105a2 100644 --- a/resources/qml/PrinterSelector/MachineSelectorList.qml +++ b/resources/qml/PrinterSelector/MachineSelectorList.qml @@ -30,9 +30,16 @@ Column model: UM.ContainerStacksModel { id: networkedPrintersModel + property var umConnectionTypes: [Cura.PrinterOutputDevice.NetworkConnection, + Cura.PrinterOutputDevice.ClusterConnection, + Cura.PrinterOutputDevice.CloudConnection + ] filter: { - "type": "machine", "um_network_key": "*", "hidden": "False", "um_connection_type": "[2,3,4]" + "type": "machine", + "um_network_key": "*", + "hidden": "False", + "um_connection_type": "[" + umConnectionTypes.join(",") + "]" } }