Added property to indicate if output device accepts commands

Instead of how this was previously done, it's now tied to the auth state.

CL-541
This commit is contained in:
Jaime van Kessel 2017-11-23 17:07:24 +01:00
parent 0b91112d72
commit 1c2c4d4163
3 changed files with 25 additions and 0 deletions

View file

@ -1,3 +1,6 @@
# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from UM.Application import Application from UM.Application import Application
from UM.Logger import Logger from UM.Logger import Logger

View file

@ -34,6 +34,7 @@ i18n_catalog = i18nCatalog("cura")
class PrinterOutputDevice(QObject, OutputDevice): class PrinterOutputDevice(QObject, OutputDevice):
printersChanged = pyqtSignal() printersChanged = pyqtSignal()
connectionStateChanged = pyqtSignal(str) connectionStateChanged = pyqtSignal(str)
acceptsCommandsChanged = pyqtSignal()
def __init__(self, device_id, parent = None): def __init__(self, device_id, parent = None):
super().__init__(device_id = device_id, parent = parent) super().__init__(device_id = device_id, parent = parent)
@ -49,6 +50,7 @@ class PrinterOutputDevice(QObject, OutputDevice):
self._control_item = None self._control_item = None
self._qml_context = None self._qml_context = None
self._accepts_commands = False
self._update_timer = QTimer() self._update_timer = QTimer()
self._update_timer.setInterval(2000) # TODO; Add preference for update interval self._update_timer.setInterval(2000) # TODO; Add preference for update interval
@ -152,6 +154,17 @@ class PrinterOutputDevice(QObject, OutputDevice):
def __del__(self): def __del__(self):
self.close() self.close()
@pyqtProperty(bool, notify=acceptsCommandsChanged)
def acceptsCommands(self):
return self._accepts_commands
## Set a flag to signal the UI that the printer is not (yet) ready to receive commands
def setAcceptsCommands(self, accepts_commands):
if self._accepts_commands != accepts_commands:
self._accepts_commands = accepts_commands
self.acceptsCommandsChanged.emit()
## The current processing state of the backend. ## The current processing state of the backend.
class ConnectionState(IntEnum): class ConnectionState(IntEnum):

View file

@ -65,6 +65,15 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
self._compressing_gcode = False self._compressing_gcode = False
self._gcode = [] self._gcode = []
self.authenticationStateChanged.connect(self._onAuthenticationStateChanged)
def _onAuthenticationStateChanged(self):
# We only accept commands if we are authenticated.
if self._authentication_state == AuthState.Authenticated:
self.setAcceptsCommands(True)
else:
self.setAcceptsCommands(False)
def _setupMessages(self): def _setupMessages(self):
self._authentication_requested_message = Message(i18n_catalog.i18nc("@info:status", self._authentication_requested_message = Message(i18n_catalog.i18nc("@info:status",
"Access to the printer requested. Please approve the request on the printer"), "Access to the printer requested. Please approve the request on the printer"),