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

View file

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

View file

@ -38,6 +38,8 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension):
self._update_thread = threading.Thread(target = self._updateThread)
self._update_thread.setDaemon(True)
self._errorCode = 0
self._check_updates = True
self._firmware_view = None
@ -57,6 +59,10 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension):
progress += device.progress
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
@pyqtProperty(float, notify = firmwareUpdateChange)
def firmwareUpdateCompleteStatus(self):