mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Added signalemitter
CURA-49
This commit is contained in:
parent
025bdba516
commit
bd413b9a2b
2 changed files with 7 additions and 5 deletions
|
@ -5,6 +5,7 @@ import requests
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
from UM.Signal import signalemitter
|
||||||
|
|
||||||
from UM.Message import Message
|
from UM.Message import Message
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ i18n_catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
|
||||||
## Network connected (wifi / lan) printer that uses the Ultimaker API
|
## Network connected (wifi / lan) printer that uses the Ultimaker API
|
||||||
|
@signalemitter
|
||||||
class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
class NetworkPrinterOutputDevice(PrinterOutputDevice):
|
||||||
def __init__(self, key, address, info):
|
def __init__(self, key, address, info):
|
||||||
super().__init__(key)
|
super().__init__(key)
|
||||||
|
|
|
@ -2,14 +2,15 @@ from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
||||||
from . import NetworkPrinterOutputDevice
|
from . import NetworkPrinterOutputDevice
|
||||||
|
|
||||||
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange
|
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange
|
||||||
from UM.Signal import Signal, SignalEmitter
|
from UM.Signal import Signal, signalemitter
|
||||||
from UM.Application import Application
|
from UM.Application import Application
|
||||||
|
|
||||||
|
|
||||||
## 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.
|
||||||
class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin, SignalEmitter):
|
@signalemitter
|
||||||
|
class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._zero_conf = Zeroconf()
|
self._zero_conf = Zeroconf()
|
||||||
|
@ -37,17 +38,16 @@ class NetworkPrinterOutputDevicePlugin(OutputDevicePlugin, SignalEmitter):
|
||||||
return
|
return
|
||||||
|
|
||||||
for key in self._printers:
|
for key in self._printers:
|
||||||
if key == active_machine.getKey():
|
if key == active_machine.getMetaDataEntry("key"):
|
||||||
self._printers[key].connect()
|
self._printers[key].connect()
|
||||||
self._printers[key].connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
|
self._printers[key].connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
|
||||||
else:
|
|
||||||
self._printers[key].close()
|
self._printers[key].close()
|
||||||
|
|
||||||
## Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
|
## Because the model needs to be created in the same thread as the QMLEngine, we use a signal.
|
||||||
def addPrinter(self, name, address, properties):
|
def addPrinter(self, name, address, properties):
|
||||||
printer = NetworkPrinterOutputDevice.NetworkPrinterOutputDevice(name, address, properties)
|
printer = NetworkPrinterOutputDevice.NetworkPrinterOutputDevice(name, address, properties)
|
||||||
self._printers[printer.getKey()] = printer
|
self._printers[printer.getKey()] = printer
|
||||||
if printer.getKey() == Application.getInstance().getGlobalContainerStack().getKey():
|
if printer.getKey() == Application.getInstance().getGlobalContainerStack().getMetaDataEntry("key"):
|
||||||
self._printers[printer.getKey()].connect()
|
self._printers[printer.getKey()].connect()
|
||||||
printer.connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
|
printer.connectionStateChanged.connect(self._onPrinterConnectionStateChanged)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue