Set stage icon for monitor depending on output device state, prevent crash when accessing back-end from unloaded component

This commit is contained in:
ChrisTerBeke 2017-12-07 10:38:06 +01:00
parent dd92d8d5e0
commit f91a4db617
3 changed files with 38 additions and 41 deletions

View File

@ -16,7 +16,8 @@ class MonitorStage(CuraStage):
# Wait until QML engine is created, otherwise creating the new QML components will fail # Wait until QML engine is created, otherwise creating the new QML components will fail
Application.getInstance().engineCreatedSignal.connect(self._setComponents) Application.getInstance().engineCreatedSignal.connect(self._setComponents)
# TODO: connect output device state to icon source # Update the status icon when the output device is changed
Application.getInstance().getOutputDeviceManager().activeDeviceChanged.connect(self._setIconSource)
def _setComponents(self): def _setComponents(self):
self._setMainOverlay() self._setMainOverlay()
@ -34,41 +35,39 @@ class MonitorStage(CuraStage):
def _setIconSource(self): def _setIconSource(self):
if Application.getInstance().getTheme() is not None: if Application.getInstance().getTheme() is not None:
self.setIconSource(Application.getInstance().getTheme().getIcon("tab_status_connected")) icon_name = self._getActiveOutputDeviceStatusIcon()
self.setIconSource(Application.getInstance().getTheme().getIcon(icon_name))
# property string iconSource: ## Find the correct status icon depending on the active output device state
# // { def _getActiveOutputDeviceStatusIcon(self):
# // if (!printerConnected) output_device = Application.getInstance().getOutputDeviceManager().getActiveDevice()
# // {
# // return UM.Theme.getIcon("tab_status_unknown"); if not output_device:
# // } return "tab_status_unknown"
# // else if (!printerAcceptsCommands)
# // { if hasattr(output_device, "acceptsCommands") and not output_device.acceptsCommands:
# // return UM.Theme.getIcon("tab_status_unknown"); return "tab_status_unknown"
# // }
# // if not hasattr(output_device, "printerState") or not hasattr(output_device, "jobState"):
# // if (Cura.MachineManager.printerOutputDevices[0].printerState == "maintenance") return "tab_status_unknown"
# // {
# // return UM.Theme.getIcon("tab_status_busy"); # TODO: refactor to use enum instead of hardcoded strings?
# // } if output_device.printerState == "maintenance":
# // return "tab_status_busy"
# // switch (Cura.MachineManager.printerOutputDevices[0].jobState)
# // { if output_device.jobState in ["printing", "pre_print", "pausing", "resuming"]:
# // case "printing": return "tab_status_busy"
# // case "pre_print":
# // case "pausing": if output_device.jobState == "wait_cleanup":
# // case "resuming": return "tab_status_finished"
# // return UM.Theme.getIcon("tab_status_busy");
# // case "wait_cleanup": if output_device.jobState in ["ready", ""]:
# // return UM.Theme.getIcon("tab_status_finished"); return "tab_status_connected"
# // case "ready":
# // case "": if output_device.jobState == "paused":
# // return UM.Theme.getIcon("tab_status_connected") return "tab_status_paused"
# // case "paused":
# // return UM.Theme.getIcon("tab_status_paused") if output_device.jobState == "error":
# // case "error": return "tab_status_stopped"
# // return UM.Theme.getIcon("tab_status_stopped")
# // default: return "tab_status_unknown"
# // return UM.Theme.getIcon("tab_status_unknown")
# // }
# // }

View File

@ -378,7 +378,6 @@ UM.MainWindow
z: 1 z: 1
source: UM.Controller.activeStage.sidebarComponent source: UM.Controller.activeStage.sidebarComponent
asynchronous: true
} }
Loader Loader
@ -402,7 +401,6 @@ UM.MainWindow
} }
source: UM.Controller.activeStage.mainComponent source: UM.Controller.activeStage.mainComponent
asynchronous: true
} }
UM.MessageStack UM.MessageStack

View File

@ -46,7 +46,7 @@ Item {
} }
function sliceOrStopSlicing() { function sliceOrStopSlicing() {
if ([1, 5].indexOf(UM.Backend.state) != -1) { if (backend != "undefined" && [1, 5].indexOf(UM.Backend.state) != -1) {
backend.forceSlice(); backend.forceSlice();
} else { } else {
backend.stopSlicing(); backend.stopSlicing();