Fix MachineManager connection to OutputDeviceManager signals late.

If a PrinterOutputDevice is able to connect quickly to a machine, then
by the time the MachineManager is created and connects to the signal,
it will be too late, and it might miss that there is already connected
devices.

# Conflicts:
#	plugins/USBPrinting/USBPrinterOutputDeviceManager.py
This commit is contained in:
Youness Alaoui 2016-09-14 14:57:43 -04:00 committed by fieldOfView
parent 391533e939
commit 7e7e15a12b
2 changed files with 10 additions and 18 deletions

View file

@ -91,6 +91,8 @@ class MachineManager(QObject):
self._printer_output_devices = [] self._printer_output_devices = []
Application.getInstance().getOutputDeviceManager().outputDevicesChanged.connect(self._onOutputDevicesChanged) Application.getInstance().getOutputDeviceManager().outputDevicesChanged.connect(self._onOutputDevicesChanged)
# There might already be some output devices by the time the signal is connected
self._onOutputDevicesChanged()
if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacks(id = active_machine_id): if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacks(id = active_machine_id):
# An active machine was saved, so restore it. # An active machine was saved, so restore it.

View file

@ -19,6 +19,7 @@ import platform
import glob import glob
import time import time
import os.path import os.path
import serial.tools.list_ports
from UM.Extension import Extension from UM.Extension import Extension
from PyQt5.QtQml import QQmlComponent, QQmlContext from PyQt5.QtQml import QQmlComponent, QQmlContext
@ -252,24 +253,13 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension):
# \param only_list_usb If true, only usb ports are listed # \param only_list_usb If true, only usb ports are listed
def getSerialPortList(self, only_list_usb = False): def getSerialPortList(self, only_list_usb = False):
base_list = [] base_list = []
if platform.system() == "Windows": for port in serial.tools.list_ports.comports():
import winreg # type: ignore @UnresolvedImport if not isinstance(port, tuple):
try: port = (port.device, port.description, port.hwid)
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") if only_list_usb and not port[2].startswith("USB"):
i = 0 continue
while True: base_list += [port[0]]
values = winreg.EnumValue(key, i)
if not only_list_usb or "USBSER" or "VCP" in values[0]:
base_list += [values[1]]
i += 1
except Exception as e:
pass
else:
if only_list_usb:
base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.usb*") + glob.glob("/dev/tty.wchusb*") + glob.glob("/dev/cu.wchusb*")
base_list = filter(lambda s: "Bluetooth" not in s, base_list) # Filter because mac sometimes puts them in the list
else:
base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/tty.wchusb*") + glob.glob("/dev/cu.wchusb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*")
return list(base_list) return list(base_list)
_instance = None # type: "USBPrinterOutputDeviceManager" _instance = None # type: "USBPrinterOutputDeviceManager"