From 7a7e710b2a4fa3751fefe4d0f7029cceb93b237c Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Wed, 6 Mar 2019 17:50:40 +0100 Subject: [PATCH] Support for manual device addition for plugins (WIP). [CURA-6294] --- cura/UI/WelcomePagesModel.py | 7 ++++--- plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py | 5 +++++ resources/qml/WelcomePages/AddPrinterByIpContent.qml | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cura/UI/WelcomePagesModel.py b/cura/UI/WelcomePagesModel.py index b22fc31408..afcbee5f01 100644 --- a/cura/UI/WelcomePagesModel.py +++ b/cura/UI/WelcomePagesModel.py @@ -7,6 +7,7 @@ from PyQt5.QtCore import QUrl, Qt from UM.Qt.ListModel import ListModel from UM.Resources import Resources +from logging import Logger if TYPE_CHECKING: from PyQt5.QtCore import QObject @@ -17,6 +18,7 @@ class WelcomePagesModel(ListModel): PageUrlRole = Qt.UserRole + 2 # URL to the page's QML file NextPageIdRole = Qt.UserRole + 3 # The next page ID it should go to + def __init__(self, parent: Optional["QObject"] = None) -> None: super().__init__(parent) @@ -28,6 +30,7 @@ class WelcomePagesModel(ListModel): def initialize(self) -> None: from cura.CuraApplication import CuraApplication + # Add default welcome pages self._pages.append({"id": "welcome", "page_url": QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, @@ -51,9 +54,7 @@ class WelcomePagesModel(ListModel): }) self._pages.append({"id": "add_printer_by_ip", "page_url": QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, - os.path.join("WelcomePages", - "AddPrinterByIpContent.qml"))), - }) + os.path.join("WelcomePages", "AddPrinterByIpContent.qml")))}) self._pages.append({"id": "cloud", "page_url": QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, os.path.join("WelcomePages", diff --git a/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py b/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py index 4529b31c45..b49113b538 100644 --- a/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py +++ b/plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py @@ -15,6 +15,7 @@ from cura.CuraApplication import CuraApplication from cura.PrinterOutputDevice import ConnectionType from cura.Settings.GlobalStack import GlobalStack # typing from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin +from UM.OutputDevice.OutputDeviceManager import ManualDeviceAdditionAttempt from UM.Logger import Logger from UM.Signal import Signal, signalemitter from UM.Version import Version @@ -181,6 +182,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): self._zero_conf.close() self._cloud_output_device_manager.stop() + def canAddManualDevice(self, address: str) -> ManualDeviceAdditionAttempt: + return ManualDeviceAdditionAttempt.POSSIBLE + # TODO?: Check if address is a valid IP (by regexp?). + def removeManualDevice(self, key, address = None): if key in self._discovered_devices: if not address: diff --git a/resources/qml/WelcomePages/AddPrinterByIpContent.qml b/resources/qml/WelcomePages/AddPrinterByIpContent.qml index 25a6d532ce..465e02e1ff 100644 --- a/resources/qml/WelcomePages/AddPrinterByIpContent.qml +++ b/resources/qml/WelcomePages/AddPrinterByIpContent.qml @@ -148,6 +148,8 @@ Item { addPrinterByIpScreen.hasPushedAdd = true tempTimerRequest.running = true + + UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text) } }