From 58b216828a52f1c6b138a5d480753b0d83754803 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 14 Apr 2016 11:06:11 +0200 Subject: [PATCH] Added handling for when connection was never correctly added to list CURA-1339 --- plugins/USBPrinting/USBPrinterManager.py | 14 +++++++++----- plugins/USBPrinting/USBPrinterOutputDevice.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/USBPrinting/USBPrinterManager.py b/plugins/USBPrinting/USBPrinterManager.py index f49cafeb04..6e1ef07c0d 100644 --- a/plugins/USBPrinting/USBPrinterManager.py +++ b/plugins/USBPrinting/USBPrinterManager.py @@ -197,11 +197,15 @@ class USBPrinterManager(QObject, SignalEmitter, OutputDevicePlugin, Extension): self._printer_connections[serial_port] = connection def _onPrinterConnectionStateChanged(self, serial_port): - if self._printer_connections[serial_port].connectionState == ConnectionState.CONNECTED: - self.getOutputDeviceManager().addOutputDevice(self._printer_connections[serial_port]) - else: - self.getOutputDeviceManager().removeOutputDevice(serial_port) - self.printerConnectionStateChanged.emit() + try: + if self._printer_connections[serial_port].connectionState == ConnectionState.CONNECTED: + self.getOutputDeviceManager().addOutputDevice(self._printer_connections[serial_port]) + else: + self.getOutputDeviceManager().removeOutputDevice(serial_port) + self.printerConnectionStateChanged.emit() + except KeyError: + pass # no output device by this device_id found in connection list. + @pyqtProperty(QObject , notify = printerConnectionStateChanged) def connectedPrinterList(self): diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index db988b8b6b..59402f4fa7 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -117,7 +117,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): def _homeBed(self): self._sendCommand("G28 Z") - + @pyqtSlot() def startPrint(self): self.writeStarted.emit(self)