CURA-2079: Using errorCode (WIP)

Sadly I don't see any reason why errorCode doesn't get updated in QML.
self._errorCode is accessible, but changes to it don't take any effect.
This commit is contained in:
Thomas Karl Pietrowski 2016-08-17 01:09:07 +02:00
parent b42ef49a4e
commit e72a10c97a
3 changed files with 80 additions and 55 deletions

View file

@ -32,40 +32,51 @@ UM.Dialog
} }
text: { text: {
if (manager.firmwareUpdateCompleteStatus && !manager.progress > 0) if (manager.errorCode == 0)
{ {
//: Firmware update status label if (manager.firmwareUpdateCompleteStatus)
return catalog.i18nc("@label","Firmware update completed.") {
} //: Firmware update status label
else if (manager.progress == -4) return catalog.i18nc("@label","Firmware update completed.")
}
if (manager.progress == 0)
{
//: Firmware update status label
return catalog.i18nc("@label","Starting firmware update, this may take a while.")
}
else
{
//: Firmware update status label
return catalog.i18nc("@label","Updating firmware.")
}
}
else
{ {
//: Firmware update status label if (manager.errorCode == 1)
return catalog.i18nc("@label","Firmware update failed due to missing firmware.") {
} //: Firmware update status label
else if (manager.progress == -3) return catalog.i18nc("@label","Firmware update failed due to an unknown error.")
{ }
//: Firmware update status label else if (manager.errorCode == 2)
return catalog.i18nc("@label","Firmware update failed due to an input/output error.") {
} //: Firmware update status label
else if (manager.progress == -2) return catalog.i18nc("@label","Firmware update failed due to an communication error.")
{ }
//: Firmware update status label else if (manager.errorCode == 3)
return catalog.i18nc("@label","Firmware update failed due to an communication error.") {
} //: Firmware update status label
else if (manager.progress == -1) return catalog.i18nc("@label","Firmware update failed due to an input/output error.")
{ }
//: Firmware update status label else if (manager.errorCode == 4)
return catalog.i18nc("@label","Firmware update failed due to an unknown error.") {
} //: Firmware update status label
else if (manager.progress == 0) return catalog.i18nc("@label","Firmware update failed due to missing firmware.")
{ }
//: Firmware update status label else
return catalog.i18nc("@label","Starting firmware update, this may take a while.") {
} //: Firmware update status label
else return catalog.i18nc("@label", "Unknown error code: %1").arg(manager.errorCode)
{ }
//: Firmware update status label
return catalog.i18nc("@label","Updating firmware.")
} }
} }

View file

@ -14,7 +14,7 @@ from UM.Logger import Logger
from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState
from UM.Message import Message from UM.Message import Message
from PyQt5.QtCore import QUrl, pyqtSlot, pyqtSignal from PyQt5.QtCore import QUrl, pyqtSlot, pyqtSignal, pyqtProperty
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
@ -173,6 +173,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
## Private function (threaded) that actually uploads the firmware. ## Private function (threaded) that actually uploads the firmware.
def _updateFirmware(self): def _updateFirmware(self):
self._errorCode = 0
self.setProgress(0, 100) self.setProgress(0, 100)
self._firmware_update_finished = False self._firmware_update_finished = False
@ -198,7 +199,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
if not programmer.isConnected(): if not programmer.isConnected():
Logger.log("e", "Unable to connect with serial. Could not update firmware") Logger.log("e", "Unable to connect with serial. Could not update firmware")
self._updateFirmware_completed_communication_error() self._updateFirmware_failed_communication_error()
return return
self._updating_firmware = True self._updating_firmware = True
@ -208,11 +209,11 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
self._updating_firmware = False self._updating_firmware = False
except serial.SerialException as e: except serial.SerialException as e:
Logger.log("e", "SerialException while trying to update firmware: <%s>" %(repr(e))) Logger.log("e", "SerialException while trying to update firmware: <%s>" %(repr(e)))
self._updateFirmware_completed_io_error() self._updateFirmware_failed_io_error()
return return
except Exception as e: except Exception as e:
Logger.log("e", "Exception while trying to update firmware: <%s>" %(repr(e))) Logger.log("e", "Exception while trying to update firmware: <%s>" %(repr(e)))
self._updateFirmware_completed_unknown() self._updateFirmware_failed_unknown()
return return
programmer.close() programmer.close()
@ -220,35 +221,42 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
return return
## Private function which makes sure that firmware update process has failed by missing firmware ## Private function which makes sure that firmware update process has failed by missing firmware
def _updateFirmware_completed_missing_firmware(self): def _updateFirmware_failed_missing_firmware(self):
return self._updateFirmware_completed_common(progress = -4) return self._updateFirmware_failed_common(4)
## Private function which makes sure that firmware update process has failed by an IO error ## Private function which makes sure that firmware update process has failed by an IO error
def _updateFirmware_completed_io_error(self): def _updateFirmware_failed_io_error(self):
return self._updateFirmware_completed_common(progress = -3) return self._updateFirmware_failed_common(3)
## Private function which makes sure that firmware update process has failed by a communication problem ## Private function which makes sure that firmware update process has failed by a communication problem
def _updateFirmware_completed_communication_error(self): def _updateFirmware_failed_communication_error(self):
return self._updateFirmware_completed_common(progress = -2) return self._updateFirmware_failed_common(2)
## Private function which makes sure that firmware update process has failed by an unknown error ## Private function which makes sure that firmware update process has failed by an unknown error
def _updateFirmware_completed_unknown(self): def _updateFirmware_failed_unknown(self):
return self._updateFirmware_completed_common(progress = -1) return self._updateFirmware_failed_common(1)
## Private function which makes sure that firmware update process has sucessfully completed/ended ## Private function which makes sure that firmware update process has successfully completed
def _updateFirmware_completed_sucessfully(self): def _updateFirmware_completed_sucessfully(self):
return self._updateFirmware_completed_common(progress = 100) self.setProgress(100, 100)
## Private common function which makes sure that firmware update process has completed/ended with a set progress state
def _updateFirmware_completed_common(self, progress, max_progress = 100):
if not progress:
raise Exception("Progress not set!")
self.setProgress(progress, max_progress = max_progress)
self._firmware_update_finished = True self._firmware_update_finished = True
self.resetFirmwareUpdate(update_has_finished=True) self.resetFirmwareUpdate(update_has_finished = True)
self.firmwareUpdateComplete.emit() self.firmwareUpdateComplete.emit()
return
## Private common function which makes sure that firmware update process has completed/ended with a set progress state
def _updateFirmware_failed_common(self, code):
if not code:
raise Exception("Error code not set!")
self._errorCode = code
self._firmware_update_finished = True
self.resetFirmwareUpdate(update_has_finished = True)
self.progressChanged.emit()
self.firmwareUpdateComplete.emit()
return return
## Upload new firmware to machine ## Upload new firmware to machine

View file

@ -38,6 +38,8 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension):
self._update_thread = threading.Thread(target = self._updateThread) self._update_thread = threading.Thread(target = self._updateThread)
self._update_thread.setDaemon(True) self._update_thread.setDaemon(True)
self._errorCode = 0
self._check_updates = True self._check_updates = True
self._firmware_view = None self._firmware_view = None
@ -57,6 +59,10 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension):
progress += device.progress progress += device.progress
return progress / len(self._usb_output_devices) return progress / len(self._usb_output_devices)
@pyqtProperty(int, notify = progressChanged)
def errorCode(self):
return self._errorCode
## Return True if all printers finished firmware update ## Return True if all printers finished firmware update
@pyqtProperty(float, notify = firmwareUpdateChange) @pyqtProperty(float, notify = firmwareUpdateChange)
def firmwareUpdateCompleteStatus(self): def firmwareUpdateCompleteStatus(self):