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

This commit is contained in:
Remco Burema 2019-03-06 17:50:40 +01:00
parent 48cc9b3c1d
commit 7a7e710b2a
3 changed files with 11 additions and 3 deletions

View File

@ -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",

View File

@ -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:

View File

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