Add some typings

Contributes to CL-1222
This commit is contained in:
Ian Paschal 2019-02-08 12:54:10 +01:00
parent 2b6bab9552
commit 2d77792988

View file

@ -402,11 +402,11 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
return True return True
## Check if the prerequsites are in place to start the cloud flow ## Check if the prerequsites are in place to start the cloud flow
def checkCloudFlowIsPossible(self): def checkCloudFlowIsPossible(self) -> None:
Logger.log("d", "Checking if cloud connection is possible...") Logger.log("d", "Checking if cloud connection is possible...")
# Pre-Check: Skip if active machine already has been cloud connected or you said don't ask again # Pre-Check: Skip if active machine already has been cloud connected or you said don't ask again
active_machine = self._application.getMachineManager().activeMachine active_machine = self._application.getMachineManager().activeMachine # type: Optional["GlobalStack"]
if active_machine: if active_machine:
# Check 1: Printer isn't already configured for cloud # Check 1: Printer isn't already configured for cloud
@ -430,7 +430,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
return return
# Check 5: Machine has correct firmware version # Check 5: Machine has correct firmware version
firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion # type: str
if not Version(firmware_version) > self._min_cloud_version: if not Version(firmware_version) > self._min_cloud_version:
Logger.log("d", "Cloud Flow not possible: Machine firmware (%s) is too low! (Requires version %s)", Logger.log("d", "Cloud Flow not possible: Machine firmware (%s) is too low! (Requires version %s)",
firmware_version, firmware_version,
@ -440,21 +440,15 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
Logger.log("d", "Cloud flow is possible!") Logger.log("d", "Cloud flow is possible!")
self.cloudFlowIsPossible.emit() self.cloudFlowIsPossible.emit()
def _onCloudFlowPossible(self): def _onCloudFlowPossible(self) -> None:
# Cloud flow is possible, so show the message # Cloud flow is possible, so show the message
if not self._start_cloud_flow_message: if not self._start_cloud_flow_message:
self._start_cloud_flow_message = Message( self._start_cloud_flow_message = Message(
i18n_catalog.i18nc("@info:status", "Pair your printer to your Ultimaker account and start print jobs from anywhere."), text = i18n_catalog.i18nc("@info:status", "Pair your printer to your Ultimaker account and start print jobs from anywhere."),
0, # Lifetime image_source = "../../../../../Cura/plugins/UM3NetworkPrinting/resources/svg/cloud-flow-start.svg",
True, # Dismissable? image_caption = i18n_catalog.i18nc("@info:status", "Connect to cloud"),
None, # Progress option_text = i18n_catalog.i18nc("@action", "Don't ask me again for this printer."),
"", # Title option_state = False
None, # Parent
True, # Use inactivity timer
"../../../../../Cura/plugins/UM3NetworkPrinting/resources/svg/cloud-flow-start.svg", # Image souce
i18n_catalog.i18nc("@info:status", "Connect to cloud"), # image caption
i18n_catalog.i18nc("@action", "Don't ask me again for this printer."), # Toggle text
False # Toggle default state
) )
self._start_cloud_flow_message.addAction("", i18n_catalog.i18nc("@action", "Get started"), "", "") self._start_cloud_flow_message.addAction("", i18n_catalog.i18nc("@action", "Get started"), "", "")
self._start_cloud_flow_message.optionToggled.connect(self._onDontAskMeAgain) self._start_cloud_flow_message.optionToggled.connect(self._onDontAskMeAgain)
@ -462,7 +456,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
self._start_cloud_flow_message.show() self._start_cloud_flow_message.show()
return return
def _onCloudPrintingConfigured(self): def _onCloudPrintingConfigured(self) -> None:
if self._start_cloud_flow_message: if self._start_cloud_flow_message:
self._start_cloud_flow_message.hide() self._start_cloud_flow_message.hide()
self._start_cloud_flow_message = None self._start_cloud_flow_message = None
@ -470,15 +464,10 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
# Show the successful pop-up # Show the successful pop-up
if not self._start_cloud_flow_message: if not self._start_cloud_flow_message:
self._cloud_flow_complete_message = Message( self._cloud_flow_complete_message = Message(
i18n_catalog.i18nc("@info:status", "You can now send and monitor print jobs from anywhere using your Ultimaker account."), text = i18n_catalog.i18nc("@info:status", "You can now send and monitor print jobs from anywhere using your Ultimaker account."),
30, # Lifetime lifetime = 30,
True, # Dismissable? image_source = "../../../../../Cura/plugins/UM3NetworkPrinting/resources/svg/cloud-flow-completed.svg",
None, # Progress image_caption = i18n_catalog.i18nc("@info:status", "Connected!")
"", # Title
None, # Parent
True, # Use inactivity timer
"../../../../../Cura/plugins/UM3NetworkPrinting/resources/svg/cloud-flow-completed.svg", # Image souce
i18n_catalog.i18nc("@info:status", "Connected!") # image caption
) )
self._cloud_flow_complete_message.addAction("", i18n_catalog.i18nc("@action", "Review your connection"), "", "", 1) # TODO: Icon self._cloud_flow_complete_message.addAction("", i18n_catalog.i18nc("@action", "Review your connection"), "", "", 1) # TODO: Icon
self._cloud_flow_complete_message.actionTriggered.connect(self._onReviewCloudConnection) self._cloud_flow_complete_message.actionTriggered.connect(self._onReviewCloudConnection)
@ -490,15 +479,15 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
active_machine.setMetaDataEntry("cloud_flow_complete", True) active_machine.setMetaDataEntry("cloud_flow_complete", True)
return return
def _onDontAskMeAgain(self, message): def _onDontAskMeAgain(self, messageId: str, checked: bool) -> None:
active_machine = self._application.getMachineManager().activeMachine active_machine = self._application.getMachineManager().activeMachine # type: Optional["GlobalStack"]
if active_machine: if active_machine:
active_machine.setMetaDataEntry("show_cloud_message", False) active_machine.setMetaDataEntry("show_cloud_message", False)
Logger.log("d", "Will not ask the user again to cloud connect for current printer.") Logger.log("d", "Will not ask the user again to cloud connect for current printer.")
return return
def _onCloudFlowStarted(self, message, action): def _onCloudFlowStarted(self, messageId: str, actionId: str) -> None:
address = self._application.getMachineManager().activeMachineAddress address = self._application.getMachineManager().activeMachineAddress # type: str
if address: if address:
QDesktopServices.openUrl(QUrl("http://" + address + "/cloud_connect")) QDesktopServices.openUrl(QUrl("http://" + address + "/cloud_connect"))
if self._start_cloud_flow_message: if self._start_cloud_flow_message:
@ -506,13 +495,13 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
self._start_cloud_flow_message = None self._start_cloud_flow_message = None
return return
def _onReviewCloudConnection(self, message, action): def _onReviewCloudConnection(self, messageId: str, actionId: str) -> None:
address = self._application.getMachineManager().activeMachineAddress address = self._application.getMachineManager().activeMachineAddress # type: str
if address: if address:
QDesktopServices.openUrl(QUrl("http://" + address + "/settings")) QDesktopServices.openUrl(QUrl("http://" + address + "/settings"))
return return
def _onMachineSwitched(self): def _onMachineSwitched(self) -> None:
if self._start_cloud_flow_message is not None: if self._start_cloud_flow_message is not None:
self._start_cloud_flow_message.hide() self._start_cloud_flow_message.hide()
self._start_cloud_flow_message = None self._start_cloud_flow_message = None