Connection states changes are now tied into the UI again

CL-541
This commit is contained in:
Jaime van Kessel 2017-11-21 15:12:23 +01:00
parent 9cfe9769d3
commit 0f78b05802
4 changed files with 19 additions and 13 deletions

View file

@ -27,7 +27,7 @@ i18n_catalog = i18nCatalog("cura")
@signalemitter @signalemitter
class PrinterOutputDevice(QObject, OutputDevice): class PrinterOutputDevice(QObject, OutputDevice):
printersChanged = pyqtSignal() printersChanged = pyqtSignal()
connectionStateChanged = pyqtSignal() connectionStateChanged = pyqtSignal(str)
def __init__(self, device_id, parent = None): def __init__(self, device_id, parent = None):
super().__init__(device_id = device_id, parent = parent) super().__init__(device_id = device_id, parent = parent)
@ -54,8 +54,10 @@ class PrinterOutputDevice(QObject, OutputDevice):
def isConnected(self): def isConnected(self):
return self._connection_state != ConnectionState.closed and self._connection_state != ConnectionState.error return self._connection_state != ConnectionState.closed and self._connection_state != ConnectionState.error
def setConnectionState(self, new_state): def setConnectionState(self, connection_state):
self._connection_state = new_state if self._connection_state != connection_state:
self._connection_state = connection_state
self.connectionStateChanged.emit(self._id)
def _update(self): def _update(self):
pass pass

View file

@ -133,17 +133,17 @@ class MachineManager(QObject):
outputDevicesChanged = pyqtSignal() outputDevicesChanged = pyqtSignal()
def _onOutputDevicesChanged(self) -> None: def _onOutputDevicesChanged(self) -> None:
for printer_output_device in self._printer_output_devices: '''for printer_output_device in self._printer_output_devices:
printer_output_device.hotendIdChanged.disconnect(self._onHotendIdChanged) printer_output_device.hotendIdChanged.disconnect(self._onHotendIdChanged)
printer_output_device.materialIdChanged.disconnect(self._onMaterialIdChanged) printer_output_device.materialIdChanged.disconnect(self._onMaterialIdChanged)'''
self._printer_output_devices.clear() self._printer_output_devices.clear()
for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices(): for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices():
if isinstance(printer_output_device, PrinterOutputDevice): if isinstance(printer_output_device, PrinterOutputDevice):
self._printer_output_devices.append(printer_output_device) self._printer_output_devices.append(printer_output_device)
printer_output_device.hotendIdChanged.connect(self._onHotendIdChanged) #printer_output_device.hotendIdChanged.connect(self._onHotendIdChanged)
printer_output_device.materialIdChanged.connect(self._onMaterialIdChanged) #printer_output_device.materialIdChanged.connect(self._onMaterialIdChanged)
self.outputDevicesChanged.emit() self.outputDevicesChanged.emit()

View file

@ -84,7 +84,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
def _onDeviceConnectionStateChanged(self, key): def _onDeviceConnectionStateChanged(self, key):
if key not in self._discovered_devices: if key not in self._discovered_devices:
return return
print("STATE CHANGED", key)
if self._discovered_devices[key].isConnected(): if self._discovered_devices[key].isConnected():
self.getOutputDeviceManager().addOutputDevice(self._discovered_devices[key]) self.getOutputDeviceManager().addOutputDevice(self._discovered_devices[key])
else: else:
@ -95,8 +95,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
Logger.log("d", "zeroconf close...") Logger.log("d", "zeroconf close...")
self._zero_conf.close() self._zero_conf.close()
def _onRemoveDevice(self, name): def _onRemoveDevice(self, device_id):
device = self._discovered_devices.pop(name, None) device = self._discovered_devices.pop(device_id, None)
if device: if device:
if device.isConnected(): if device.isConnected():
device.disconnect() device.disconnect()
@ -108,10 +108,12 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
# Check what kind of device we need to add; Depending on the firmware we either add a "Connect"/"Cluster" # Check what kind of device we need to add; Depending on the firmware we either add a "Connect"/"Cluster"
# or "Legacy" UM3 device. # or "Legacy" UM3 device.
cluster_size = int(properties.get(b"cluster_size", -1)) cluster_size = int(properties.get(b"cluster_size", -1))
if cluster_size > 0: # TODO: For debug purposes; force it to be legacy printer.
device = LegacyUM3OutputDevice.LegacyUM3OutputDevice(name, address, properties)
'''if cluster_size > 0:
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._discovered_devices[device.getId()] = device self._discovered_devices[device.getId()] = device
self.discoveredDevicesChanged.emit() self.discoveredDevicesChanged.emit()

View file

@ -12,7 +12,9 @@ import Cura 1.0 as Cura
Column Column
{ {
id: printMonitor id: printMonitor
property var connectedPrinter: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null property var connectedDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
property var activePrinter: connectedDevice != null ? connectedDevice.activePrinter : null
Cura.ExtrudersModel Cura.ExtrudersModel
{ {