WIP: Add printers via network

This commit is contained in:
Lipu Fei 2019-03-08 11:02:30 +01:00
parent a55808b24a
commit 940a833e73
9 changed files with 145 additions and 46 deletions

View file

@ -4,7 +4,7 @@
import time
import re
import unicodedata
from typing import Any, List, Dict, TYPE_CHECKING, Optional, cast, NamedTuple, Callable
from typing import Any, List, Dict, TYPE_CHECKING, Optional, cast
from UM.ConfigurationErrorMessage import ConfigurationErrorMessage
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
@ -49,8 +49,6 @@ 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:
@ -136,9 +134,6 @@ 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()
@ -178,30 +173,6 @@ class MachineManager(QObject):
self.outputDevicesChanged.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)
self.discoveredPrintersChanged.emit()
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]
self.discoveredPrintersChanged.emit()
@pyqtProperty("QVariantList", notify = discoveredPrintersChanged)
def discoveredPrinters(self):
return list(self._discovered_printers.values())
@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:
return self._current_printer_configuration