mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-01 00:04:27 +08:00
Improve conditions for starting cloud flow
Contributes to CL-1222
This commit is contained in:
parent
3a4fcb354a
commit
162fdad4e4
@ -11,6 +11,7 @@ from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QObject
|
|||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
|
from cura.PrinterOutputDevice import ConnectionType
|
||||||
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Signal import Signal, signalemitter
|
from UM.Signal import Signal, signalemitter
|
||||||
@ -89,9 +90,15 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||||||
# Check if cloud flow is possible when user logs in
|
# Check if cloud flow is possible when user logs in
|
||||||
self._account.loginStateChanged.connect(self.checkCloudFlowIsPossible)
|
self._account.loginStateChanged.connect(self.checkCloudFlowIsPossible)
|
||||||
|
|
||||||
|
# Check if cloud flow is possible when user switches machines
|
||||||
|
self._application.globalContainerStackChanged.connect(self._onMachineSwitched)
|
||||||
|
|
||||||
# Listen for when cloud flow is possible
|
# Listen for when cloud flow is possible
|
||||||
self.cloudFlowIsPossible.connect(self._onCloudFlowPossible)
|
self.cloudFlowIsPossible.connect(self._onCloudFlowPossible)
|
||||||
|
|
||||||
|
self._start_cloud_flow_message = None # type: Optional[Message]
|
||||||
|
self._cloud_flow_complete_message = None # type: Optional[Message]
|
||||||
|
|
||||||
def getDiscoveredDevices(self):
|
def getDiscoveredDevices(self):
|
||||||
return self._discovered_devices
|
return self._discovered_devices
|
||||||
|
|
||||||
@ -156,6 +163,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||||||
um_network_key = CuraApplication.getInstance().getGlobalContainerStack().getMetaDataEntry("um_network_key")
|
um_network_key = CuraApplication.getInstance().getGlobalContainerStack().getMetaDataEntry("um_network_key")
|
||||||
if key == um_network_key:
|
if key == um_network_key:
|
||||||
self.getOutputDeviceManager().addOutputDevice(self._discovered_devices[key])
|
self.getOutputDeviceManager().addOutputDevice(self._discovered_devices[key])
|
||||||
|
self.checkCloudFlowIsPossible()
|
||||||
else:
|
else:
|
||||||
self.getOutputDeviceManager().removeOutputDevice(key)
|
self.getOutputDeviceManager().removeOutputDevice(key)
|
||||||
|
|
||||||
@ -391,85 +399,92 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||||||
|
|
||||||
## 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):
|
||||||
|
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
|
||||||
active_machine = self._application.getMachineManager().activeMachine
|
active_machine = self._application.getMachineManager().activeMachine
|
||||||
|
|
||||||
if active_machine:
|
if active_machine:
|
||||||
# Skip if already complete
|
|
||||||
if active_machine.getMetaDataEntry("cloud_flow_complete", "value") is not None:
|
# Check 1: Printer isn't already configured for cloud
|
||||||
|
if ConnectionType.CloudConnection.value in active_machine.configuredConnectionTypes:
|
||||||
|
Logger.log("d", "Active machine was already configured for cloud.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Skip if user said don't remind me
|
# Check 2: User did not already say "Don't ask me again"
|
||||||
if active_machine.getMetaDataEntry("show_cloud_message", "value") is False:
|
if active_machine.getMetaDataEntry("show_cloud_message", "value") is False:
|
||||||
|
Logger.log("d", "Active machine shouldn't ask about cloud anymore.")
|
||||||
return
|
return
|
||||||
|
|
||||||
Logger.log("d", "Checking if cloud connection is possible...")
|
# Check 3: User is logged in with an Ultimaker account
|
||||||
|
|
||||||
# Check #1: User is logged in with an Ultimaker account
|
|
||||||
if not self._account.isLoggedIn:
|
if not self._account.isLoggedIn:
|
||||||
Logger.log("d", "Cloud Flow not possible: User not logged in!")
|
Logger.log("d", "Cloud Flow not possible: User not logged in!")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check #2: Machine has a network connection
|
# Check 4: Machine is configured for network connectivity
|
||||||
if not self._application.getMachineManager().activeMachineHasActiveNetworkConnection:
|
if not self._application.getMachineManager().activeMachineHasActiveNetworkConnection:
|
||||||
Logger.log("d", "Cloud Flow not possible: Machine is not connected!")
|
Logger.log("d", "Cloud Flow not possible: Machine is not connected!")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check #3: Machine has correct firmware version
|
# Check 5: Machine has correct firmware version
|
||||||
firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion
|
# firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion
|
||||||
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,
|
||||||
self._min_cloud_version)
|
# self._min_cloud_version)
|
||||||
return
|
# return
|
||||||
|
|
||||||
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):
|
||||||
# Cloud flow is possible, so show the message
|
# Cloud flow is possible, so show the message
|
||||||
self._start_cloud_flow_message = Message(
|
if not self._start_cloud_flow_message:
|
||||||
i18n_catalog.i18nc("@info:status", "Pair your printer to your Ultimaker account and start print jobs from anywhere."),
|
self._start_cloud_flow_message = Message(
|
||||||
0, # Lifetime
|
i18n_catalog.i18nc("@info:status", "Pair your printer to your Ultimaker account and start print jobs from anywhere."),
|
||||||
True, # Dismissable?
|
0, # Lifetime
|
||||||
None, # Progress
|
True, # Dismissable?
|
||||||
"", # Title
|
None, # Progress
|
||||||
None, # Parent
|
"", # Title
|
||||||
True, # Use inactivity timer
|
None, # Parent
|
||||||
"../../../../../Cura/plugins/UM3NetworkPrinting/resources/svg/cloud-flow-start.svg", # Image souce
|
True, # Use inactivity timer
|
||||||
i18n_catalog.i18nc("@info:status", "Connect to cloud"), # image caption
|
"../../../../../Cura/plugins/UM3NetworkPrinting/resources/svg/cloud-flow-start.svg", # Image souce
|
||||||
i18n_catalog.i18nc("@action", "Don't ask me again for this printer."), # Toggle text
|
i18n_catalog.i18nc("@info:status", "Connect to cloud"), # image caption
|
||||||
False # Toggle default state
|
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.optionToggled.connect(self._onDontAskMeAgain)
|
self._start_cloud_flow_message.addAction("", i18n_catalog.i18nc("@action", "Get started"), "", "")
|
||||||
self._start_cloud_flow_message.actionTriggered.connect(self._onCloudFlowStarted)
|
self._start_cloud_flow_message.optionToggled.connect(self._onDontAskMeAgain)
|
||||||
self._start_cloud_flow_message.show()
|
self._start_cloud_flow_message.actionTriggered.connect(self._onCloudFlowStarted)
|
||||||
return
|
self._start_cloud_flow_message.show()
|
||||||
|
return
|
||||||
|
|
||||||
def _onCloudPrintingConfigured(self):
|
def _onCloudPrintingConfigured(self):
|
||||||
if self._start_cloud_flow_message:
|
if self._start_cloud_flow_message:
|
||||||
self._start_cloud_flow_message.hide()
|
self._start_cloud_flow_message.hide()
|
||||||
# Show the successful pop-up
|
self._start_cloud_flow_message = None
|
||||||
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."),
|
|
||||||
30, # Lifetime
|
|
||||||
True, # Dismissable?
|
|
||||||
None, # Progress
|
|
||||||
"", # 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._start_cloud_flow_message.actionTriggered.connect(self._onReviewCloudConnection)
|
|
||||||
self._cloud_flow_complete_message.show()
|
|
||||||
|
|
||||||
# Set the machine's cloud flow as complete so we don't ask the user again and again for cloud connected printers
|
# Show the successful pop-up
|
||||||
active_machine = self._application.getMachineManager().activeMachine
|
if not self._start_cloud_flow_message:
|
||||||
if active_machine:
|
self._cloud_flow_complete_message = Message(
|
||||||
active_machine.setMetaDataEntry("cloud_flow_complete", True)
|
i18n_catalog.i18nc("@info:status", "You can now send and monitor print jobs from anywhere using your Ultimaker account."),
|
||||||
return
|
30, # Lifetime
|
||||||
|
True, # Dismissable?
|
||||||
|
None, # Progress
|
||||||
|
"", # 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.actionTriggered.connect(self._onReviewCloudConnection)
|
||||||
|
self._cloud_flow_complete_message.show()
|
||||||
|
|
||||||
|
# Set the machine's cloud flow as complete so we don't ask the user again and again for cloud connected printers
|
||||||
|
active_machine = self._application.getMachineManager().activeMachine
|
||||||
|
if active_machine:
|
||||||
|
active_machine.setMetaDataEntry("cloud_flow_complete", True)
|
||||||
|
return
|
||||||
|
|
||||||
def _onDontAskMeAgain(self, message):
|
def _onDontAskMeAgain(self, message):
|
||||||
active_machine = self._application.getMachineManager().activeMachine
|
active_machine = self._application.getMachineManager().activeMachine
|
||||||
@ -484,6 +499,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||||||
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:
|
||||||
self._start_cloud_flow_message.hide()
|
self._start_cloud_flow_message.hide()
|
||||||
|
self._start_cloud_flow_message = None
|
||||||
return
|
return
|
||||||
|
|
||||||
def _onReviewCloudConnection(self, message, action):
|
def _onReviewCloudConnection(self, message, action):
|
||||||
@ -491,3 +507,13 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
|||||||
if address:
|
if address:
|
||||||
QDesktopServices.openUrl(QUrl("http://" + address + "/settings"))
|
QDesktopServices.openUrl(QUrl("http://" + address + "/settings"))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _onMachineSwitched(self):
|
||||||
|
if self._start_cloud_flow_message is not None:
|
||||||
|
self._start_cloud_flow_message.hide()
|
||||||
|
self._start_cloud_flow_message = None
|
||||||
|
if self._cloud_flow_complete_message is not None:
|
||||||
|
self._cloud_flow_complete_message.hide()
|
||||||
|
self._cloud_flow_complete_message = None
|
||||||
|
|
||||||
|
self.checkCloudFlowIsPossible()
|
Loading…
x
Reference in New Issue
Block a user