mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 07:33:57 -06:00
Merge branch 'CURA-6483_fix_manual_printer_discovery' into 4.1
This commit is contained in:
commit
1fb336ed3d
5 changed files with 190 additions and 105 deletions
|
@ -217,7 +217,7 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
self._machine_settings_manager = MachineSettingsManager(self, parent = self)
|
self._machine_settings_manager = MachineSettingsManager(self, parent = self)
|
||||||
|
|
||||||
self._discovered_printer_model = DiscoveredPrintersModel(parent = self)
|
self._discovered_printer_model = DiscoveredPrintersModel(self, parent = self)
|
||||||
self._first_start_machine_actions_model = FirstStartMachineActionsModel(self, parent = self)
|
self._first_start_machine_actions_model = FirstStartMachineActionsModel(self, parent = self)
|
||||||
self._welcome_pages_model = WelcomePagesModel(self, parent = self)
|
self._welcome_pages_model = WelcomePagesModel(self, parent = self)
|
||||||
self._add_printer_pages_model = AddPrinterPagesModel(self, parent = self)
|
self._add_printer_pages_model = AddPrinterPagesModel(self, parent = self)
|
||||||
|
|
|
@ -3,15 +3,17 @@
|
||||||
|
|
||||||
from typing import Callable, Dict, List, Optional, TYPE_CHECKING
|
from typing import Callable, Dict, List, Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject
|
from PyQt5.QtCore import pyqtSlot, pyqtProperty, pyqtSignal, QObject, QTimer
|
||||||
|
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Util import parseBool
|
from UM.Util import parseBool
|
||||||
|
from UM.OutputDevice.OutputDeviceManager import ManualDeviceAdditionAttempt
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from PyQt5.QtCore import QObject
|
from PyQt5.QtCore import QObject
|
||||||
|
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
||||||
|
from cura.CuraApplication import CuraApplication
|
||||||
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
|
from cura.PrinterOutput.NetworkedPrinterOutputDevice import NetworkedPrinterOutputDevice
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +47,10 @@ class DiscoveredPrinter(QObject):
|
||||||
self._name = name
|
self._name = name
|
||||||
self.nameChanged.emit()
|
self.nameChanged.emit()
|
||||||
|
|
||||||
|
@pyqtProperty(str, constant = True)
|
||||||
|
def address(self) -> str:
|
||||||
|
return self._ip_address
|
||||||
|
|
||||||
machineTypeChanged = pyqtSignal()
|
machineTypeChanged = pyqtSignal()
|
||||||
|
|
||||||
@pyqtProperty(str, notify = machineTypeChanged)
|
@pyqtProperty(str, notify = machineTypeChanged)
|
||||||
|
@ -105,13 +111,87 @@ class DiscoveredPrinter(QObject):
|
||||||
#
|
#
|
||||||
class DiscoveredPrintersModel(QObject):
|
class DiscoveredPrintersModel(QObject):
|
||||||
|
|
||||||
def __init__(self, parent: Optional["QObject"] = None) -> None:
|
def __init__(self, application: "CuraApplication", parent: Optional["QObject"] = None) -> None:
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self._application = application
|
||||||
self._discovered_printer_by_ip_dict = dict() # type: Dict[str, DiscoveredPrinter]
|
self._discovered_printer_by_ip_dict = dict() # type: Dict[str, DiscoveredPrinter]
|
||||||
|
|
||||||
|
self._plugin_for_manual_device = None # type: Optional[OutputDevicePlugin]
|
||||||
|
self._manual_device_address = ""
|
||||||
|
|
||||||
|
self._manual_device_request_timeout_in_seconds = 5 # timeout for adding a manual device in seconds
|
||||||
|
self._manual_device_request_timer = QTimer()
|
||||||
|
self._manual_device_request_timer.setInterval(self._manual_device_request_timeout_in_seconds * 1000)
|
||||||
|
self._manual_device_request_timer.setSingleShot(True)
|
||||||
|
self._manual_device_request_timer.timeout.connect(self._onManualRequestTimeout)
|
||||||
|
|
||||||
discoveredPrintersChanged = pyqtSignal()
|
discoveredPrintersChanged = pyqtSignal()
|
||||||
|
|
||||||
|
@pyqtSlot(str)
|
||||||
|
def checkManualDevice(self, address: str) -> None:
|
||||||
|
if self.hasManualDeviceRequestInProgress:
|
||||||
|
Logger.log("i", "A manual device request for address [%s] is still in progress, do nothing",
|
||||||
|
self._manual_device_address)
|
||||||
|
return
|
||||||
|
|
||||||
|
priority_order = [
|
||||||
|
ManualDeviceAdditionAttempt.PRIORITY,
|
||||||
|
ManualDeviceAdditionAttempt.POSSIBLE,
|
||||||
|
] # type: List[ManualDeviceAdditionAttempt]
|
||||||
|
|
||||||
|
all_plugins_dict = self._application.getOutputDeviceManager().getAllOutputDevicePlugins()
|
||||||
|
|
||||||
|
can_add_manual_plugins = [item for item in filter(
|
||||||
|
lambda plugin_item: plugin_item.canAddManualDevice(address) in priority_order,
|
||||||
|
all_plugins_dict.values())]
|
||||||
|
|
||||||
|
if not can_add_manual_plugins:
|
||||||
|
Logger.log("d", "Could not find a plugin to accept adding %s manually via address.", address)
|
||||||
|
return
|
||||||
|
|
||||||
|
plugin = max(can_add_manual_plugins, key = lambda p: priority_order.index(p.canAddManualDevice(address)))
|
||||||
|
self._plugin_for_manual_device = plugin
|
||||||
|
self._plugin_for_manual_device.addManualDevice(address, callback = self._onManualDeviceRequestFinished)
|
||||||
|
self._manual_device_address = address
|
||||||
|
self._manual_device_request_timer.start()
|
||||||
|
self.hasManualDeviceRequestInProgressChanged.emit()
|
||||||
|
|
||||||
|
@pyqtSlot()
|
||||||
|
def cancelCurrentManualDeviceRequest(self) -> None:
|
||||||
|
self._manual_device_request_timer.stop()
|
||||||
|
|
||||||
|
if self._manual_device_address:
|
||||||
|
if self._plugin_for_manual_device is not None:
|
||||||
|
self._plugin_for_manual_device.removeManualDevice(self._manual_device_address, address = self._manual_device_address)
|
||||||
|
self._manual_device_address = ""
|
||||||
|
self._plugin_for_manual_device = None
|
||||||
|
self.hasManualDeviceRequestInProgressChanged.emit()
|
||||||
|
self.manualDeviceRequestFinished.emit(False)
|
||||||
|
|
||||||
|
def _onManualRequestTimeout(self) -> None:
|
||||||
|
Logger.log("w", "Manual printer [%s] request timed out. Cancel the current request.", self._manual_device_address)
|
||||||
|
self.cancelCurrentManualDeviceRequest()
|
||||||
|
|
||||||
|
hasManualDeviceRequestInProgressChanged = pyqtSignal()
|
||||||
|
|
||||||
|
@pyqtProperty(bool, notify = hasManualDeviceRequestInProgressChanged)
|
||||||
|
def hasManualDeviceRequestInProgress(self) -> bool:
|
||||||
|
return self._manual_device_address != ""
|
||||||
|
|
||||||
|
manualDeviceRequestFinished = pyqtSignal(bool, arguments = ["success"])
|
||||||
|
|
||||||
|
def _onManualDeviceRequestFinished(self, success: bool, address: str) -> None:
|
||||||
|
self._manual_device_request_timer.stop()
|
||||||
|
if address == self._manual_device_address:
|
||||||
|
self._manual_device_address = ""
|
||||||
|
self.hasManualDeviceRequestInProgressChanged.emit()
|
||||||
|
self.manualDeviceRequestFinished.emit(success)
|
||||||
|
|
||||||
|
@pyqtProperty("QVariantMap", notify = discoveredPrintersChanged)
|
||||||
|
def discoveredPrintersByAddress(self) -> Dict[str, DiscoveredPrinter]:
|
||||||
|
return self._discovered_printer_by_ip_dict
|
||||||
|
|
||||||
@pyqtProperty(list, notify = discoveredPrintersChanged)
|
@pyqtProperty(list, notify = discoveredPrintersChanged)
|
||||||
def discoveredPrinters(self) -> List["DiscoveredPrinter"]:
|
def discoveredPrinters(self) -> List["DiscoveredPrinter"]:
|
||||||
item_list = list(
|
item_list = list(
|
||||||
|
@ -168,11 +248,3 @@ class DiscoveredPrintersModel(QObject):
|
||||||
@pyqtSlot("QVariant")
|
@pyqtSlot("QVariant")
|
||||||
def createMachineFromDiscoveredPrinter(self, discovered_printer: "DiscoveredPrinter") -> None:
|
def createMachineFromDiscoveredPrinter(self, discovered_printer: "DiscoveredPrinter") -> None:
|
||||||
discovered_printer.create_callback(discovered_printer.getKey())
|
discovered_printer.create_callback(discovered_printer.getKey())
|
||||||
|
|
||||||
@pyqtSlot(str)
|
|
||||||
def createMachineFromDiscoveredPrinterAddress(self, ip_address: str) -> None:
|
|
||||||
if ip_address not in self._discovered_printer_by_ip_dict:
|
|
||||||
Logger.log("i", "Key [%s] does not exist in the discovered printers list.", ip_address)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.createMachineFromDiscoveredPrinter(self._discovered_printer_by_ip_dict[ip_address])
|
|
||||||
|
|
|
@ -5,11 +5,11 @@ import os
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
from time import time
|
from time import time
|
||||||
from typing import Optional, TYPE_CHECKING, Dict
|
from typing import Optional, TYPE_CHECKING, Dict, Callable
|
||||||
|
|
||||||
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo
|
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo
|
||||||
|
|
||||||
from PyQt5.QtNetwork import QNetworkRequest, QNetworkAccessManager
|
from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManager
|
||||||
from PyQt5.QtCore import QUrl
|
from PyQt5.QtCore import QUrl
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
|
|
||||||
|
@ -39,6 +39,22 @@ if TYPE_CHECKING:
|
||||||
i18n_catalog = i18nCatalog("cura")
|
i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Represents a request for adding a manual printer. It has the following fields:
|
||||||
|
# - address: The string of the (IP) address of the manual printer
|
||||||
|
# - callback: (Optional) Once the HTTP request to the printer to get printer information is done, whether successful
|
||||||
|
# or not, this callback will be invoked to notify about the result. The callback must have a signature of
|
||||||
|
# func(success: bool, address: str) -> None
|
||||||
|
# - network_reply: This is the QNetworkReply instance for this request if the request has been issued and still in
|
||||||
|
# progress. It is kept here so we can cancel a request when needed.
|
||||||
|
#
|
||||||
|
class ManualPrinterRequest:
|
||||||
|
def __init__(self, address: str, callback: Optional[Callable[[bool, str], None]] = None) -> None:
|
||||||
|
self.address = address
|
||||||
|
self.callback = callback
|
||||||
|
self.network_reply = None # type: Optional["QNetworkReply"]
|
||||||
|
|
||||||
|
|
||||||
## This plugin handles the connection detection & creation of output device objects for the UM3 printer.
|
## This plugin handles the connection detection & creation of output device objects for the UM3 printer.
|
||||||
# Zero-Conf is used to detect printers, which are saved in a dict.
|
# Zero-Conf is used to detect printers, which are saved in a dict.
|
||||||
# If we discover a printer that has the same key as the active machine instance a connection is made.
|
# If we discover a printer that has the same key as the active machine instance a connection is made.
|
||||||
|
@ -84,10 +100,12 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
self._preferences.addPreference("um3networkprinting/manual_instances",
|
self._preferences.addPreference("um3networkprinting/manual_instances",
|
||||||
"") # A comma-separated list of ip adresses or hostnames
|
"") # A comma-separated list of ip adresses or hostnames
|
||||||
|
|
||||||
self._manual_instances = self._preferences.getValue("um3networkprinting/manual_instances").split(",")
|
manual_instances = self._preferences.getValue("um3networkprinting/manual_instances").split(",")
|
||||||
|
self._manual_instances = {address: ManualPrinterRequest(address)
|
||||||
|
for address in manual_instances} # type: Dict[str, ManualPrinterRequest]
|
||||||
|
|
||||||
# Store the last manual entry key
|
# Store the last manual entry key
|
||||||
self._last_manual_entry_key = "" # type: str
|
self._last_manual_entry_key = "" # type: str
|
||||||
|
|
||||||
# The zero-conf service changed requests are handled in a separate thread, so we can re-schedule the requests
|
# The zero-conf service changed requests are handled in a separate thread, so we can re-schedule the requests
|
||||||
# which fail to get detailed service info.
|
# which fail to get detailed service info.
|
||||||
|
@ -185,8 +203,6 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
self.checkCloudFlowIsPossible(None)
|
self.checkCloudFlowIsPossible(None)
|
||||||
else:
|
else:
|
||||||
self.getOutputDeviceManager().removeOutputDevice(key)
|
self.getOutputDeviceManager().removeOutputDevice(key)
|
||||||
if key.startswith("manual:"):
|
|
||||||
self.removeManualDeviceSignal.emit(self.getPluginId(), key, self._discovered_devices[key].address)
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self._zero_conf is not None:
|
if self._zero_conf is not None:
|
||||||
|
@ -198,7 +214,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
# This plugin should always be the fallback option (at least try it):
|
# This plugin should always be the fallback option (at least try it):
|
||||||
return ManualDeviceAdditionAttempt.POSSIBLE
|
return ManualDeviceAdditionAttempt.POSSIBLE
|
||||||
|
|
||||||
def removeManualDevice(self, key, address = None):
|
def removeManualDevice(self, key: str, address: Optional[str] = None) -> None:
|
||||||
|
if key not in self._discovered_devices and address is not None:
|
||||||
|
key = "manual:%s" % address
|
||||||
|
|
||||||
if key in self._discovered_devices:
|
if key in self._discovered_devices:
|
||||||
if not address:
|
if not address:
|
||||||
address = self._discovered_devices[key].ipAddress
|
address = self._discovered_devices[key].ipAddress
|
||||||
|
@ -206,15 +225,22 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
self.resetLastManualDevice()
|
self.resetLastManualDevice()
|
||||||
|
|
||||||
if address in self._manual_instances:
|
if address in self._manual_instances:
|
||||||
self._manual_instances.remove(address)
|
manual_printer_request = self._manual_instances.pop(address)
|
||||||
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
|
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances.keys()))
|
||||||
|
|
||||||
self.removeManualDeviceSignal.emit(self.getPluginId(), key, address)
|
if manual_printer_request.network_reply is not None:
|
||||||
|
manual_printer_request.network_reply.abort()
|
||||||
|
|
||||||
def addManualDevice(self, address):
|
if manual_printer_request.callback is not None:
|
||||||
if address not in self._manual_instances:
|
self._application.callLater(manual_printer_request.callback, False, address)
|
||||||
self._manual_instances.append(address)
|
|
||||||
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances))
|
def addManualDevice(self, address: str, callback: Optional[Callable[[bool, str], None]] = None) -> None:
|
||||||
|
if address in self._manual_instances:
|
||||||
|
Logger.log("i", "Manual printer with address [%s] has already been added, do nothing", address)
|
||||||
|
return
|
||||||
|
|
||||||
|
self._manual_instances[address] = ManualPrinterRequest(address, callback = callback)
|
||||||
|
self._preferences.setValue("um3networkprinting/manual_instances", ",".join(self._manual_instances.keys()))
|
||||||
|
|
||||||
instance_name = "manual:%s" % address
|
instance_name = "manual:%s" % address
|
||||||
properties = {
|
properties = {
|
||||||
|
@ -230,7 +256,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
self._onAddDevice(instance_name, address, properties)
|
self._onAddDevice(instance_name, address, properties)
|
||||||
self._last_manual_entry_key = instance_name
|
self._last_manual_entry_key = instance_name
|
||||||
|
|
||||||
self._checkManualDevice(address)
|
reply = self._checkManualDevice(address)
|
||||||
|
self._manual_instances[address].network_reply = reply
|
||||||
|
|
||||||
def _createMachineFromDiscoveredPrinter(self, key: str) -> None:
|
def _createMachineFromDiscoveredPrinter(self, key: str) -> None:
|
||||||
discovered_device = self._discovered_devices.get(key)
|
discovered_device = self._discovered_devices.get(key)
|
||||||
|
@ -287,13 +314,13 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
|
|
||||||
self.refreshConnections()
|
self.refreshConnections()
|
||||||
|
|
||||||
def _checkManualDevice(self, address: str) -> None:
|
def _checkManualDevice(self, address: str) -> "QNetworkReply":
|
||||||
# Check if a UM3 family device exists at this address.
|
# Check if a UM3 family device exists at this address.
|
||||||
# If a printer responds, it will replace the preliminary printer created above
|
# If a printer responds, it will replace the preliminary printer created above
|
||||||
# origin=manual is for tracking back the origin of the call
|
# origin=manual is for tracking back the origin of the call
|
||||||
url = QUrl("http://" + address + self._api_prefix + "system")
|
url = QUrl("http://" + address + self._api_prefix + "system")
|
||||||
name_request = QNetworkRequest(url)
|
name_request = QNetworkRequest(url)
|
||||||
self._network_manager.get(name_request)
|
return self._network_manager.get(name_request)
|
||||||
|
|
||||||
def _onNetworkRequestFinished(self, reply: "QNetworkReply") -> None:
|
def _onNetworkRequestFinished(self, reply: "QNetworkReply") -> None:
|
||||||
reply_url = reply.url().toString()
|
reply_url = reply.url().toString()
|
||||||
|
@ -319,6 +346,12 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
Logger.log("e", "Something went wrong converting the JSON.")
|
Logger.log("e", "Something went wrong converting the JSON.")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if address in self._manual_instances:
|
||||||
|
manual_printer_request = self._manual_instances[address]
|
||||||
|
manual_printer_request.network_reply = None
|
||||||
|
if manual_printer_request.callback is not None:
|
||||||
|
self._application.callLater(manual_printer_request.callback, True, address)
|
||||||
|
|
||||||
has_cluster_capable_firmware = Version(system_info["firmware"]) > self._min_cluster_version
|
has_cluster_capable_firmware = Version(system_info["firmware"]) > self._min_cluster_version
|
||||||
instance_name = "manual:%s" % address
|
instance_name = "manual:%s" % address
|
||||||
properties = {
|
properties = {
|
||||||
|
@ -362,10 +395,6 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
self._onRemoveDevice(instance_name)
|
self._onRemoveDevice(instance_name)
|
||||||
self._onAddDevice(instance_name, address, properties)
|
self._onAddDevice(instance_name, address, properties)
|
||||||
|
|
||||||
if device and address in self._manual_instances:
|
|
||||||
self.getOutputDeviceManager().addOutputDevice(device)
|
|
||||||
self.addManualDeviceSignal.emit(self.getPluginId(), device.getId(), address, properties)
|
|
||||||
|
|
||||||
def _onRemoveDevice(self, device_id: str) -> None:
|
def _onRemoveDevice(self, device_id: str) -> None:
|
||||||
device = self._discovered_devices.pop(device_id, None)
|
device = self._discovered_devices.pop(device_id, None)
|
||||||
if device:
|
if device:
|
||||||
|
@ -401,7 +430,9 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||||
device = ClusterUM3OutputDevice.ClusterUM3OutputDevice(name, address, properties)
|
device = ClusterUM3OutputDevice.ClusterUM3OutputDevice(name, address, properties)
|
||||||
else:
|
else:
|
||||||
device = LegacyUM3OutputDevice.LegacyUM3OutputDevice(name, address, properties)
|
device = LegacyUM3OutputDevice.LegacyUM3OutputDevice(name, address, properties)
|
||||||
self._application.getDiscoveredPrintersModel().addDiscoveredPrinter(address, device.getId(), name, self._createMachineFromDiscoveredPrinter, properties[b"printer_type"].decode("utf-8"), device)
|
self._application.getDiscoveredPrintersModel().addDiscoveredPrinter(
|
||||||
|
address, device.getId(), properties[b"name"].decode("utf-8"), self._createMachineFromDiscoveredPrinter,
|
||||||
|
properties[b"printer_type"].decode("utf-8"), device)
|
||||||
self._discovered_devices[device.getId()] = device
|
self._discovered_devices[device.getId()] = device
|
||||||
self.discoveredDevicesChanged.emit()
|
self.discoveredDevicesChanged.emit()
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,22 @@ Item
|
||||||
|
|
||||||
id: addPrinterByIpScreen
|
id: addPrinterByIpScreen
|
||||||
|
|
||||||
// Whether an IP address is currently being resolved.
|
// If there's a manual address resolve request in progress.
|
||||||
property bool hasSentRequest: false
|
property bool hasRequestInProgress: CuraApplication.getDiscoveredPrintersModel().hasManualDeviceRequestInProgress
|
||||||
// Whether the IP address user entered can be resolved as a recognizable printer.
|
// Indicates if a request has finished.
|
||||||
property bool haveConnection: false
|
property bool hasRequestFinished: false
|
||||||
// True when a request comes back, but the device hasn't responded.
|
|
||||||
property bool deviceUnresponsive: false
|
property var discoveredPrinter: null
|
||||||
|
property var isPrinterDiscovered: discoveredPrinter != null
|
||||||
|
|
||||||
|
// Make sure to cancel the current request when this page closes.
|
||||||
|
onVisibleChanged:
|
||||||
|
{
|
||||||
|
if (!visible)
|
||||||
|
{
|
||||||
|
CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
|
@ -85,10 +95,12 @@ Item
|
||||||
|
|
||||||
validator: RegExpValidator
|
validator: RegExpValidator
|
||||||
{
|
{
|
||||||
regExp: /[a-fA-F0-9\.\:]*/
|
regExp: /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$))?/
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled: { ! (addPrinterByIpScreen.hasSentRequest || addPrinterByIpScreen.haveConnection) }
|
placeholderText: catalog.i18nc("@text", "Place enter your printer's IP address.")
|
||||||
|
|
||||||
|
enabled: { ! (addPrinterByIpScreen.hasRequestInProgress || addPrinterByIpScreen.isPrinterDiscovered) }
|
||||||
onAccepted: addPrinterButton.clicked()
|
onAccepted: addPrinterButton.clicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,22 +111,21 @@ Item
|
||||||
anchors.left: hostnameField.right
|
anchors.left: hostnameField.right
|
||||||
anchors.leftMargin: UM.Theme.getSize("default_margin").width
|
anchors.leftMargin: UM.Theme.getSize("default_margin").width
|
||||||
text: catalog.i18nc("@button", "Add")
|
text: catalog.i18nc("@button", "Add")
|
||||||
|
enabled: !addPrinterByIpScreen.hasRequestInProgress && !addPrinterByIpScreen.isPrinterDiscovered && (hostnameField.state != "invalid" && hostnameField.text != "")
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
if (hostnameField.text.trim() != "")
|
const address = hostnameField.text
|
||||||
{
|
|
||||||
enabled = false;
|
|
||||||
addPrinterByIpScreen.deviceUnresponsive = false;
|
|
||||||
UM.OutputDeviceManager.addManualDevice(hostnameField.text, hostnameField.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
busy: !enabled && !addPrinterByIpScreen.hasSentRequest && !addPrinterByIpScreen.haveConnection
|
|
||||||
|
|
||||||
Connections
|
// This address is already in the discovered printer model, no need to add a manual discovery.
|
||||||
{
|
if (CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address])
|
||||||
target: UM.OutputDeviceManager
|
{
|
||||||
onManualDeviceChanged: { addPrinterButton.enabled = ! UM.OutputDeviceManager.hasManualDevice }
|
addPrinterByIpScreen.discoveredPrinter = CuraApplication.getDiscoveredPrintersModel().discoveredPrintersByAddress[address]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
CuraApplication.getDiscoveredPrintersModel().checkManualDevice(address)
|
||||||
}
|
}
|
||||||
|
busy: addPrinterByIpScreen.hasRequestInProgress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,14 +144,10 @@ Item
|
||||||
color: UM.Theme.getColor("text")
|
color: UM.Theme.getColor("text")
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
|
|
||||||
visible:
|
visible: addPrinterByIpScreen.hasRequestInProgress || (addPrinterByIpScreen.hasRequestFinished && !addPrinterByIpScreen.isPrinterDiscovered)
|
||||||
{
|
|
||||||
(addPrinterByIpScreen.hasSentRequest && ! addPrinterByIpScreen.haveConnection)
|
|
||||||
|| addPrinterByIpScreen.deviceUnresponsive
|
|
||||||
}
|
|
||||||
text:
|
text:
|
||||||
{
|
{
|
||||||
if (addPrinterByIpScreen.deviceUnresponsive)
|
if (addPrinterByIpScreen.hasRequestFinished)
|
||||||
{
|
{
|
||||||
catalog.i18nc("@label", "Could not connect to device.")
|
catalog.i18nc("@label", "Could not connect to device.")
|
||||||
}
|
}
|
||||||
|
@ -157,7 +164,7 @@ Item
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.margins: UM.Theme.getSize("default_margin").width
|
anchors.margins: UM.Theme.getSize("default_margin").width
|
||||||
|
|
||||||
visible: addPrinterByIpScreen.haveConnection && ! addPrinterByIpScreen.deviceUnresponsive
|
visible: addPrinterByIpScreen.isPrinterDiscovered
|
||||||
|
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
|
@ -167,7 +174,7 @@ Item
|
||||||
color: UM.Theme.getColor("text")
|
color: UM.Theme.getColor("text")
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
|
|
||||||
text: "???"
|
text: !addPrinterByIpScreen.isPrinterDiscovered ? "???" : addPrinterByIpScreen.discoveredPrinter.name
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayout
|
GridLayout
|
||||||
|
@ -188,7 +195,7 @@ Item
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
id: typeText
|
id: typeText
|
||||||
text: "?"
|
text: !addPrinterByIpScreen.isPrinterDiscovered ? "?" : addPrinterByIpScreen.discoveredPrinter.readableMachineType
|
||||||
font: UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
color: UM.Theme.getColor("text")
|
color: UM.Theme.getColor("text")
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
|
@ -204,7 +211,7 @@ Item
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
id: firmwareText
|
id: firmwareText
|
||||||
text: "0.0.0.0"
|
text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.device.getProperty("firmware_version")
|
||||||
font: UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
color: UM.Theme.getColor("text")
|
color: UM.Theme.getColor("text")
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
|
@ -220,52 +227,25 @@ Item
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
id: addressText
|
id: addressText
|
||||||
text: "0.0.0.0"
|
text: !addPrinterByIpScreen.isPrinterDiscovered ? "0.0.0.0" : addPrinterByIpScreen.discoveredPrinter.address
|
||||||
font: UM.Theme.getFont("default")
|
font: UM.Theme.getFont("default")
|
||||||
color: UM.Theme.getColor("text")
|
color: UM.Theme.getColor("text")
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections
|
|
||||||
{
|
|
||||||
target: UM.OutputDeviceManager
|
|
||||||
onManualDeviceChanged:
|
|
||||||
{
|
|
||||||
if (UM.OutputDeviceManager.hasManualDevice)
|
|
||||||
{
|
|
||||||
const type_id = UM.OutputDeviceManager.manualDeviceProperty("printer_type")
|
|
||||||
var readable_type = Cura.MachineManager.getMachineTypeNameFromId(type_id)
|
|
||||||
readable_type = (readable_type != "") ? readable_type : catalog.i18nc("@label", "Unknown")
|
|
||||||
typeText.text = readable_type
|
|
||||||
firmwareText.text = UM.OutputDeviceManager.manualDeviceProperty("firmware_version")
|
|
||||||
addressText.text = UM.OutputDeviceManager.manualDeviceProperty("address")
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
typeText.text = ""
|
|
||||||
firmwareText.text = ""
|
|
||||||
addressText.text = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections
|
Connections
|
||||||
{
|
{
|
||||||
target: UM.OutputDeviceManager
|
target: CuraApplication.getDiscoveredPrintersModel()
|
||||||
onManualDeviceChanged:
|
onManualDeviceRequestFinished:
|
||||||
{
|
{
|
||||||
if (UM.OutputDeviceManager.hasManualDevice)
|
var discovered_printers_model = CuraApplication.getDiscoveredPrintersModel()
|
||||||
|
var printer = discovered_printers_model.discoveredPrintersByAddress[hostnameField.text]
|
||||||
|
if (printer)
|
||||||
{
|
{
|
||||||
printerNameLabel.text = UM.OutputDeviceManager.manualDeviceProperty("name")
|
addPrinterByIpScreen.discoveredPrinter = printer
|
||||||
addPrinterByIpScreen.haveConnection = true
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
addPrinterByIpScreen.hasSentRequest = false
|
|
||||||
addPrinterByIpScreen.haveConnection = false
|
|
||||||
addPrinterByIpScreen.deviceUnresponsive = true
|
|
||||||
}
|
}
|
||||||
|
addPrinterByIpScreen.hasRequestFinished = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,7 +259,11 @@ Item
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
text: catalog.i18nc("@button", "Back")
|
text: catalog.i18nc("@button", "Back")
|
||||||
onClicked: base.showPreviousPage()
|
onClicked:
|
||||||
|
{
|
||||||
|
CuraApplication.getDiscoveredPrintersModel().cancelCurrentManualDeviceRequest()
|
||||||
|
base.showPreviousPage()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Cura.PrimaryButton
|
Cura.PrimaryButton
|
||||||
|
@ -290,12 +274,10 @@ Item
|
||||||
text: catalog.i18nc("@button", "Connect")
|
text: catalog.i18nc("@button", "Connect")
|
||||||
onClicked:
|
onClicked:
|
||||||
{
|
{
|
||||||
CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinterAddress(
|
CuraApplication.getDiscoveredPrintersModel().createMachineFromDiscoveredPrinter(discoveredPrinter)
|
||||||
UM.OutputDeviceManager.manualDeviceProperty("address"))
|
|
||||||
UM.OutputDeviceManager.setActiveDevice(UM.OutputDeviceManager.manualDeviceProperty("device_id"))
|
|
||||||
base.showNextPage()
|
base.showNextPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
enabled: addPrinterByIpScreen.haveConnection
|
enabled: addPrinterByIpScreen.isPrinterDiscovered
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ from cura.Machines.Models.DiscoveredPrintersModel import DiscoveredPrintersModel
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def discovered_printer_model(application) -> DiscoveredPrintersModel:
|
def discovered_printer_model(application) -> DiscoveredPrintersModel:
|
||||||
return DiscoveredPrintersModel()
|
return DiscoveredPrintersModel(application)
|
||||||
|
|
||||||
|
|
||||||
def test_discoveredPrinters(discovered_printer_model):
|
def test_discoveredPrinters(discovered_printer_model):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue