mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56:22 -06:00
Add the discovered printer functionality
This can be used in the add machine wizard to short circuit the creation of a printer. So instead of first selecting a printer and then connecting it, it will be possible to have a list that contains all network discovered printers (from all plugins that can do this). This means we can select one of those printers and directly add it (thus no longer needing that step) CURA-6179
This commit is contained in:
parent
5c354eb6a3
commit
21c6bba1ce
3 changed files with 33 additions and 4 deletions
|
@ -745,6 +745,8 @@ class CuraApplication(QtApplication):
|
|||
# Initialize Cura API
|
||||
self._cura_API.initialize()
|
||||
|
||||
self._output_device_manager.start()
|
||||
|
||||
# Detect in which mode to run and execute that mode
|
||||
if self._is_headless:
|
||||
self.runWithoutGUI()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import time
|
||||
import re
|
||||
import unicodedata
|
||||
from typing import Any, List, Dict, TYPE_CHECKING, Optional, cast
|
||||
from typing import Any, List, Dict, TYPE_CHECKING, Optional, cast, NamedTuple, Callable
|
||||
|
||||
from UM.ConfigurationErrorMessage import ConfigurationErrorMessage
|
||||
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
|
||||
|
@ -49,6 +49,8 @@ if TYPE_CHECKING:
|
|||
from cura.Machines.QualityChangesGroup import QualityChangesGroup
|
||||
from cura.Machines.QualityGroup import QualityGroup
|
||||
|
||||
DiscoveredPrinter = NamedTuple("DiscoveredPrinter", [("key", str), ("name", str), ("create_callback", Callable[[str], None]), ("machine_type", "str")])
|
||||
|
||||
|
||||
class MachineManager(QObject):
|
||||
def __init__(self, application: "CuraApplication", parent: Optional["QObject"] = None) -> None:
|
||||
|
@ -134,6 +136,9 @@ class MachineManager(QObject):
|
|||
self.globalContainerChanged.connect(self.printerConnectedStatusChanged)
|
||||
self.outputDevicesChanged.connect(self.printerConnectedStatusChanged)
|
||||
|
||||
# This will contain all discovered network printers
|
||||
self._discovered_printers = {} # type: Dict[str, DiscoveredPrinter]
|
||||
|
||||
activeQualityGroupChanged = pyqtSignal()
|
||||
activeQualityChangesGroupChanged = pyqtSignal()
|
||||
|
||||
|
@ -171,7 +176,24 @@ class MachineManager(QObject):
|
|||
self._printer_output_devices.append(printer_output_device)
|
||||
|
||||
self.outputDevicesChanged.emit()
|
||||
self.printerConnectedStatusChanged.emit()
|
||||
|
||||
# Discovered printers are all the printers that were found on the network, which provide a more convenient way
|
||||
# to add networked printers (Plugin finds a bunch of printers, user can select one from the list, plugin can then
|
||||
# add that printer to Cura as the active one).
|
||||
def addDiscoveredPrinter(self, key: str, name: str, create_callback: Callable[[str], None], machine_type: str) -> None:
|
||||
if key not in self._discovered_printers:
|
||||
self._discovered_printers[key] = DiscoveredPrinter(key, name, create_callback, machine_type)
|
||||
else:
|
||||
Logger.log("e", "Printer with the key %s was already in the discovered printer list", key)
|
||||
|
||||
def removeDiscoveredPrinter(self, key: str) -> None:
|
||||
if key in self._discovered_printers:
|
||||
del self._discovered_printers[key]
|
||||
|
||||
@pyqtSlot(str)
|
||||
def addMachineFromDiscoveredPrinter(self, key: str) -> None:
|
||||
if key in self._discovered_printers:
|
||||
self._discovered_printers[key].create_callback(key)
|
||||
|
||||
@pyqtProperty(QObject, notify = currentConfigurationChanged)
|
||||
def currentConfiguration(self) -> ConfigurationModel:
|
||||
|
|
|
@ -213,6 +213,11 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
|
||||
self._checkManualDevice(address)
|
||||
|
||||
def _createMachineFromDiscoveredPrinter(self, key: str) -> None:
|
||||
# TODO: This needs to be implemented. It's supposed to create a machine given a unique key as already discovered
|
||||
# by this plugin.
|
||||
pass
|
||||
|
||||
def _checkManualDevice(self, address):
|
||||
# Check if a UM3 family device exists at this address.
|
||||
# If a printer responds, it will replace the preliminary printer created above
|
||||
|
@ -293,7 +298,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
except TypeError:
|
||||
# Disconnect already happened.
|
||||
pass
|
||||
|
||||
self._application.getMachineManager().removeDiscoveredPrinter(device.getId())
|
||||
self.discoveredDevicesChanged.emit()
|
||||
|
||||
def _onAddDevice(self, name, address, properties):
|
||||
|
@ -318,7 +323,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||
device = ClusterUM3OutputDevice.ClusterUM3OutputDevice(name, address, properties)
|
||||
else:
|
||||
device = LegacyUM3OutputDevice.LegacyUM3OutputDevice(name, address, properties)
|
||||
|
||||
self._application.getMachineManager().addDiscoveredPrinter(device.getId(), name, self._createMachineFromDiscoveredPrinter, properties[b"printer_type"].decode("utf-8"))
|
||||
self._discovered_devices[device.getId()] = device
|
||||
self.discoveredDevicesChanged.emit()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue