Browse Source

Support for manual device addition for plugins (WIP). [CURA-6294]

Remco Burema 6 years ago
parent
commit
7a7e710b2a

+ 4 - 3
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",

+ 5 - 0
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:

+ 2 - 0
resources/qml/WelcomePages/AddPrinterByIpContent.qml

@@ -148,6 +148,8 @@ Item
                         {
                             addPrinterByIpScreen.hasPushedAdd = true
                             tempTimerRequest.running = true
+
+                            UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text)
                         }
                     }