mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-30 07:44:22 +08:00
Merge pull request #5271 from Ultimaker/CL-1222_cloud_flow_pop_up
CL-1222 Cloud flow pop up
This commit is contained in:
commit
1163d8f442
@ -517,6 +517,18 @@ class MachineManager(QObject):
|
||||
return self._global_container_stack.getId()
|
||||
return ""
|
||||
|
||||
@pyqtProperty(str, notify = globalContainerChanged)
|
||||
def activeMachineFirmwareVersion(self) -> str:
|
||||
if not self._printer_output_devices[0]:
|
||||
return ""
|
||||
return self._printer_output_devices[0].firmwareVersion
|
||||
|
||||
@pyqtProperty(str, notify = globalContainerChanged)
|
||||
def activeMachineAddress(self) -> str:
|
||||
if not self._printer_output_devices[0]:
|
||||
return ""
|
||||
return self._printer_output_devices[0].address
|
||||
|
||||
@pyqtProperty(bool, notify = printerConnectedStatusChanged)
|
||||
def printerConnected(self) -> bool:
|
||||
return bool(self._printer_output_devices)
|
||||
|
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="291px" height="209px" viewBox="0 0 291 209" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: Sketch 52.5 (67469) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>Group 2</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="CC--Cloud-connection-succes" transform="translate(-570.000000, -132.000000)">
|
||||
<g id="Group-2" transform="translate(570.000000, 132.000000)">
|
||||
<g id="Icon/-group-printer/-connected" fill="#08073F" fill-rule="nonzero">
|
||||
<g id="printer-group">
|
||||
<g id="Group-Copy" transform="translate(0.000000, 0.218255)">
|
||||
<g id="UM3">
|
||||
<path d="M151.645765,136.481718 C149.925833,142.069331 149,148.004918 149,154.156745 C149,157.125641 149.215633,160.044173 149.632091,162.897534 L94.5646946,162.897534 C92.6599327,163.073639 90.7551708,163.778061 89.3698894,165.010799 L88.3309283,166.067432 C87.2919673,167.828487 85.2140452,168.180697 83.1361231,168.180697 L73.7854738,168.180697 C73.2659933,168.180697 72.7465127,167.652381 72.7465127,167.124065 L72.7465127,152.918227 L19.3939394,152.918227 C17.7008177,153.074764 16.007696,153.700917 14.7763348,154.796684 L13.8528138,155.735914 C12.9292929,157.301296 11.0822511,157.614372 9.23520921,157.614372 L0.923520928,157.614372 C0.461760462,157.614372 1.42108547e-13,157.144757 1.42108547e-13,156.675142 L1.42108547e-13,9.0596475 C1.42108547e-13,8.59003299 0.461760462,8.12041848 0.923520928,8.12041848 L72.7465127,8.12041848 L72.7465127,1.05663265 C72.7465127,0.528316328 73.2659933,-2.84217094e-14 73.7854738,-2.84217094e-14 L216.815777,-2.84217094e-14 C217.335257,-2.84217094e-14 217.854738,0.528316328 217.854738,1.05663265 L217.854738,8.12041848 L289.677732,8.12041848 C290.139493,8.12041848 290.601253,8.59003299 290.601253,9.0596475 L290.601253,156.675142 C290.601253,157.144757 290.139493,157.614372 289.677732,157.614372 L281.366043,157.614372 C279.672922,157.457833 277.9798,156.831681 276.748439,155.735914 L275.824918,154.796684 C274.901397,153.231303 273.054355,152.918227 271.207313,152.918227 L268.987471,152.918227 C268.818229,144.560013 266.939851,136.621364 263.687558,129.437501 L268.590671,129.437501 C272.900435,129.437501 276.440598,125.837123 276.440598,121.454054 L276.594519,121.454054 L276.594519,24.5569264 C276.594519,22.8350065 275.209237,21.5827012 273.670035,21.5827012 L217.854738,21.5827012 L217.854738,94.8055789 C214.965144,94.3781586 212.008429,94.1567452 209,94.1567452 C206.665515,94.1567452 204.362169,94.2900687 202.097162,94.5495169 L202.097162,21.5827012 L202.097162,18.4910714 C202.097162,16.5539116 200.538721,15.145068 198.807119,15.145068 L161.616164,15.145068 L128.985089,15.145068 L91.6209717,15.145068 C89.7162098,15.145068 88.3309283,16.730017 88.3309283,18.4910714 L88.3309283,21.5827012 L88.3309283,127.50034 C88.3309283,128.164624 88.4032089,128.812928 88.5401496,129.437501 C89.4197136,133.449106 92.9667866,136.481718 97.1620971,136.481718 L128.985089,136.481718 L151.645765,136.481718 Z M72.7465127,129.437501 L72.7465127,21.5827012 L16.7772968,21.5827012 C15.0841751,21.5827012 13.8528138,22.9915447 13.8528138,24.5569264 L13.8528138,121.454054 C13.8528138,125.837123 17.3929774,129.437501 21.7027417,129.437501 L72.7465127,129.437501 Z" id="Combined-Shape"></path>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="Group-cloud" transform="translate(156.000000, 103.000000)">
|
||||
<g id="Group" transform="translate(0.394933, 0.724044)">
|
||||
<circle id="Oval-Copy" fill="#3282FF" cx="52.6050671" cy="52.601776" r="52.1311475"></circle>
|
||||
<path d="M74.8002981,45.4035747 C74.1684054,39.8133538 69.4292101,35.538479 63.7421759,35.538479 C62.1624441,35.538479 60.8986587,35.8673156 59.6348733,36.5249886 C56.7913562,31.9212773 51.7362146,28.9617486 46.3651267,28.9617486 C37.5186289,28.9617486 30.5678092,36.1961521 30.5678092,45.4035747 C30.5678092,45.4035747 30.5678092,45.4035747 30.5678092,45.7324112 C25.1967213,46.3900842 21.0894188,51.322632 21.0894188,56.9128529 C21.0894188,63.1607468 26.1445604,68.4221311 32.147541,68.4221311 C36.8867362,68.4221311 67.533532,68.4221311 73.2205663,68.4221311 C79.2235469,68.4221311 84.2786885,63.1607468 84.2786885,56.9128529 C84.2786885,50.9937956 80.171386,46.3900842 74.8002981,45.4035747 Z" id="Path" fill="#FFFFFF"></path>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.6 KiB |
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="186px" height="57px" viewBox="0 0 186 57" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: Sketch 52.6 (67491) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>Cloud_connection-icon</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<g id="Cloud_connection-icon" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<path d="M38.6261428,52.7109865 L7.48755878,52.7109865 C6.85100215,52.7676651 6.21444551,52.994379 5.75149524,53.3911284 L5.40428251,53.7311992 C5.05706981,54.2979841 4.36264439,54.4113411 3.66821896,54.4113411 L0.543304569,54.4113411 C0.369698215,54.4113411 0.196091859,54.2413055 0.196091859,54.0712703 L0.196091859,0.623463283 C0.196091859,0.453427843 0.369698215,0.283392401 0.543304569,0.283392401 L48.3429212,0.283392401 C48.5165273,0.283392401 48.6901338,0.453427843 48.6901338,0.623463283 L48.6901338,26.0155943 C48.4613867,26.0052354 48.2313048,26 48,26 C46.4042274,26 44.8666558,26.2491876 43.4240742,26.7107738 L43.4240742,6.23463283 C43.4240742,5.61116956 42.9032553,5.15774169 42.3245675,5.15774169 L6.50378945,5.15774169 C5.86723281,5.15774169 5.40428251,5.66784803 5.40428251,6.23463283 L5.40428251,41.3186122 C5.40428251,42.9056095 6.73526457,44.2092147 8.35559054,44.2092147 L33.3440862,44.2092147 C34.087979,47.6221969 35.9937272,50.6011835 38.6261428,52.7109865 Z" id="Combined-Shape" fill="#08073F" fill-rule="nonzero"></path>
|
||||
<path d="M158.961954,52.7109865 L131.487559,52.7109865 C130.851002,52.7676651 130.214446,52.994379 129.751495,53.3911284 L129.404283,53.7311992 C129.05707,54.2979841 128.362644,54.4113411 127.668219,54.4113411 L124.543305,54.4113411 C124.369698,54.4113411 124.196092,54.2413055 124.196092,54.0712703 L124.196092,0.623463283 C124.196092,0.453427843 124.369698,0.283392401 124.543305,0.283392401 L172.342921,0.283392401 C172.516527,0.283392401 172.690134,0.453427843 172.690134,0.623463283 L172.690134,27.0854877 C172.13468,27.0289729 171.570805,27 171,27 C169.770934,27 168.574002,27.1343278 167.424074,27.3886981 L167.424074,6.23463283 C167.424074,5.61116956 166.903255,5.15774169 166.324567,5.15774169 L130.503789,5.15774169 C129.867233,5.15774169 129.404283,5.66784803 129.404283,6.23463283 L129.404283,41.3186122 C129.404283,42.9056095 130.735265,44.2092147 132.355591,44.2092147 L155.096113,44.2092147 C155.462794,47.4493334 156.859805,50.3873861 158.961954,52.7109865 Z" id="Combined-Shape" fill="#08073F" fill-rule="nonzero"></path>
|
||||
<path d="M171,56 C163.26057,56 157,49.9481159 157,42.5 C157,35.0518841 163.26057,29 171,29 C178.73943,29 185,35.0518841 185,42.5 C185,49.9481159 178.73943,56 171,56 Z M177.416667,40.7546296 C177.233333,39.1569444 175.858333,37.9351852 174.208333,37.9351852 C173.75,37.9351852 173.383333,38.0291667 173.016667,38.2171296 C172.191667,36.9013889 170.725,36.0555556 169.166667,36.0555556 C166.6,36.0555556 164.583333,38.1231482 164.583333,40.7546296 C164.583333,40.7546296 164.583333,40.7546296 164.583333,40.8486111 C163.025,41.0365741 161.833333,42.4462963 161.833333,44.0439815 C161.833333,45.8296296 163.3,47.3333333 165.041667,47.3333333 C166.416667,47.3333333 175.308333,47.3333333 176.958333,47.3333333 C178.7,47.3333333 180.166667,45.8296296 180.166667,44.0439815 C180.166667,42.3523148 178.975,41.0365741 177.416667,40.7546296 Z" id="Combined-Shape" fill="#3282FF" fill-rule="nonzero"></path>
|
||||
<path d="M48,54 C40.8202983,54 35,48.1797017 35,41 C35,33.8202983 40.8202983,28 48,28 C55.1797017,28 61,33.8202983 61,41 C61,48.1797017 55.1797017,54 48,54 Z M46.862511,41.4631428 L43.8629783,38.6111022 L41.1067187,41.5099007 L47.0308248,47.1427085 L55.8527121,37.698579 L52.9296286,34.9680877 L46.862511,41.4631428 Z" id="Combined-Shape" fill="#3282FF" fill-rule="nonzero"></path>
|
||||
<path d="M54.5,25 C53.6715729,25 53,24.3284271 53,23.5 C53,22.6715729 53.6715729,22 54.5,22 C55.3284271,22 56,22.6715729 56,23.5 C56,24.3284271 55.3284271,25 54.5,25 Z M78.5,25 C77.6715729,25 77,24.3284271 77,23.5 C77,22.6715729 77.6715729,22 78.5,22 C79.3284271,22 80,22.6715729 80,23.5 C80,24.3284271 79.3284271,25 78.5,25 Z M102.5,25 C101.671573,25 101,24.3284271 101,23.5 C101,22.6715729 101.671573,22 102.5,22 C103.328427,22 104,22.6715729 104,23.5 C104,24.3284271 103.328427,25 102.5,25 Z M62.5,25 C61.6715729,25 61,24.3284271 61,23.5 C61,22.6715729 61.6715729,22 62.5,22 C63.3284271,22 64,22.6715729 64,23.5 C64,24.3284271 63.3284271,25 62.5,25 Z M86.5,25 C85.6715729,25 85,24.3284271 85,23.5 C85,22.6715729 85.6715729,22 86.5,22 C87.3284271,22 88,22.6715729 88,23.5 C88,24.3284271 87.3284271,25 86.5,25 Z M110.5,25 C109.671573,25 109,24.3284271 109,23.5 C109,22.6715729 109.671573,22 110.5,22 C111.328427,22 112,22.6715729 112,23.5 C112,24.3284271 111.328427,25 110.5,25 Z M70.5,25 C69.6715729,25 69,24.3284271 69,23.5 C69,22.6715729 69.6715729,22 70.5,22 C71.3284271,22 72,22.6715729 72,23.5 C72,24.3284271 71.3284271,25 70.5,25 Z M94.5,25 C93.6715729,25 93,24.3284271 93,23.5 C93,22.6715729 93.6715729,22 94.5,22 C95.3284271,22 96,22.6715729 96,23.5 C96,24.3284271 95.3284271,25 94.5,25 Z M118.5,25 C117.671573,25 117,24.3284271 117,23.5 C117,22.6715729 117.671573,22 118.5,22 C119.328427,22 120,22.6715729 120,23.5 C120,24.3284271 119.328427,25 118.5,25 Z" id="Combined-Shape" fill="#3282FF" fill-rule="nonzero"></path>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 5.3 KiB |
@ -7,6 +7,7 @@ from PyQt5.QtCore import QTimer
|
||||
from UM import i18nCatalog
|
||||
from UM.Logger import Logger
|
||||
from UM.Message import Message
|
||||
from UM.Signal import Signal, signalemitter
|
||||
from cura.API import Account
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from cura.Settings.GlobalStack import GlobalStack
|
||||
@ -31,14 +32,17 @@ class CloudOutputDeviceManager:
|
||||
# The translation catalog for this device.
|
||||
I18N_CATALOG = i18nCatalog("cura")
|
||||
|
||||
addedCloudCluster = Signal()
|
||||
removedCloudCluster = Signal()
|
||||
|
||||
def __init__(self) -> None:
|
||||
# Persistent dict containing the remote clusters for the authenticated user.
|
||||
self._remote_clusters = {} # type: Dict[str, CloudOutputDevice]
|
||||
|
||||
application = CuraApplication.getInstance()
|
||||
self._output_device_manager = application.getOutputDeviceManager()
|
||||
self._application = CuraApplication.getInstance()
|
||||
self._output_device_manager = self._application.getOutputDeviceManager()
|
||||
|
||||
self._account = application.getCuraAPI().account # type: Account
|
||||
self._account = self._application.getCuraAPI().account # type: Account
|
||||
self._api = CloudApiClient(self._account, self._onApiError)
|
||||
|
||||
# Create a timer to update the remote cluster list
|
||||
@ -82,6 +86,7 @@ class CloudOutputDeviceManager:
|
||||
removed_cluster.disconnect()
|
||||
removed_cluster.close()
|
||||
self._output_device_manager.removeOutputDevice(removed_cluster.key)
|
||||
self.removedCloudCluster.emit()
|
||||
del self._remote_clusters[removed_cluster.key]
|
||||
|
||||
# Add an output device for each new remote cluster.
|
||||
@ -89,6 +94,7 @@ class CloudOutputDeviceManager:
|
||||
for added_cluster in added_clusters:
|
||||
device = CloudOutputDevice(self._api, added_cluster)
|
||||
self._remote_clusters[added_cluster.cluster_id] = device
|
||||
self.addedCloudCluster.emit()
|
||||
|
||||
for device, cluster in updates:
|
||||
device.clusterData = cluster
|
||||
@ -152,10 +158,9 @@ class CloudOutputDeviceManager:
|
||||
def start(self):
|
||||
if self._running:
|
||||
return
|
||||
application = CuraApplication.getInstance()
|
||||
self._account.loginStateChanged.connect(self._onLoginStateChanged)
|
||||
# When switching machines we check if we have to activate a remote cluster.
|
||||
application.globalContainerStackChanged.connect(self._connectToActiveMachine)
|
||||
self._application.globalContainerStackChanged.connect(self._connectToActiveMachine)
|
||||
self._update_timer.timeout.connect(self._getRemoteClusters)
|
||||
self._onLoginStateChanged(is_logged_in = self._account.isLoggedIn)
|
||||
|
||||
@ -163,9 +168,8 @@ class CloudOutputDeviceManager:
|
||||
def stop(self):
|
||||
if not self._running:
|
||||
return
|
||||
application = CuraApplication.getInstance()
|
||||
self._account.loginStateChanged.disconnect(self._onLoginStateChanged)
|
||||
# When switching machines we check if we have to activate a remote cluster.
|
||||
application.globalContainerStackChanged.disconnect(self._connectToActiveMachine)
|
||||
self._application.globalContainerStackChanged.disconnect(self._connectToActiveMachine)
|
||||
self._update_timer.timeout.disconnect(self._getRemoteClusters)
|
||||
self._onLoginStateChanged(is_logged_in = False)
|
||||
|
@ -54,6 +54,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
super().__init__(device_id = device_id, address = address, properties=properties, connection_type = ConnectionType.NetworkConnection, parent = parent)
|
||||
self._api_prefix = "/cluster-api/v1/"
|
||||
|
||||
self._application = CuraApplication.getInstance()
|
||||
|
||||
self._number_of_extruders = 2
|
||||
|
||||
self._dummy_lambdas = (
|
||||
@ -125,7 +127,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
def _spawnPrinterSelectionDialog(self):
|
||||
if self._printer_selection_dialog is None:
|
||||
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../resources/qml/PrintWindow.qml")
|
||||
self._printer_selection_dialog = CuraApplication.getInstance().createQmlComponent(path, {"OutputDevice": self})
|
||||
self._printer_selection_dialog = self._application.createQmlComponent(path, {"OutputDevice": self})
|
||||
if self._printer_selection_dialog is not None:
|
||||
self._printer_selection_dialog.show()
|
||||
|
||||
@ -211,7 +213,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
# Add user name to the print_job
|
||||
parts.append(self._createFormPart("name=owner", bytes(self._getUserName(), "utf-8"), "text/plain"))
|
||||
|
||||
file_name = CuraApplication.getInstance().getPrintInformation().jobName + "." + preferred_format["extension"]
|
||||
file_name = self._application.getPrintInformation().jobName + "." + preferred_format["extension"]
|
||||
|
||||
output = stream.getvalue() # Either str or bytes depending on the output mode.
|
||||
if isinstance(stream, io.StringIO):
|
||||
@ -250,6 +252,11 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
self._compressing_gcode = False
|
||||
self._sending_gcode = False
|
||||
|
||||
## The IP address of the printer.
|
||||
@pyqtProperty(str, constant = True)
|
||||
def address(self) -> str:
|
||||
return self._address
|
||||
|
||||
def _onUploadPrintJobProgress(self, bytes_sent: int, bytes_total: int) -> None:
|
||||
if bytes_total > 0:
|
||||
new_progress = bytes_sent / bytes_total * 100
|
||||
@ -284,7 +291,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
self._progress_message.hide()
|
||||
self._compressing_gcode = False
|
||||
self._sending_gcode = False
|
||||
CuraApplication.getInstance().getController().setActiveStage("PrepareStage")
|
||||
self._application.getController().setActiveStage("PrepareStage")
|
||||
|
||||
# After compressing the sliced model Cura sends data to printer, to stop receiving updates from the request
|
||||
# the "reply" should be disconnected
|
||||
@ -294,7 +301,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
|
||||
def _successMessageActionTriggered(self, message_id: Optional[str] = None, action_id: Optional[str] = None) -> None:
|
||||
if action_id == "View":
|
||||
CuraApplication.getInstance().getController().setActiveStage("MonitorStage")
|
||||
self._application.getController().setActiveStage("MonitorStage")
|
||||
|
||||
@pyqtSlot()
|
||||
def openPrintJobControlPanel(self) -> None:
|
||||
@ -552,7 +559,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
return result
|
||||
|
||||
def _createMaterialOutputModel(self, material_data: Dict[str, Any]) -> "MaterialOutputModel":
|
||||
material_manager = CuraApplication.getInstance().getMaterialManager()
|
||||
material_manager = self._application.getMaterialManager()
|
||||
material_group_list = None
|
||||
|
||||
# Avoid crashing if there is no "guid" field in the metadata
|
||||
@ -665,7 +672,6 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||
job = SendMaterialJob(device = self)
|
||||
job.run()
|
||||
|
||||
|
||||
def loadJsonFromReply(reply: QNetworkReply) -> Optional[List[Dict[str, Any]]]:
|
||||
try:
|
||||
result = json.loads(bytes(reply.readAll()).decode("utf-8"))
|
||||
|
@ -7,17 +7,25 @@ from time import time
|
||||
|
||||
from zeroconf import Zeroconf, ServiceBrowser, ServiceStateChange, ServiceInfo
|
||||
from PyQt5.QtNetwork import QNetworkRequest, QNetworkAccessManager
|
||||
from PyQt5.QtCore import QUrl
|
||||
from PyQt5.QtCore import pyqtSlot, QUrl, pyqtSignal, pyqtProperty, QObject
|
||||
from PyQt5.QtGui import QDesktopServices
|
||||
|
||||
from cura.CuraApplication import CuraApplication
|
||||
from cura.PrinterOutputDevice import ConnectionType
|
||||
from cura.Settings.GlobalStack import GlobalStack # typing
|
||||
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
|
||||
from UM.Logger import Logger
|
||||
from UM.Signal import Signal, signalemitter
|
||||
from UM.Version import Version
|
||||
from UM.Message import Message
|
||||
from UM.i18n import i18nCatalog
|
||||
|
||||
from . import ClusterUM3OutputDevice, LegacyUM3OutputDevice
|
||||
from .Cloud.CloudOutputDeviceManager import CloudOutputDeviceManager
|
||||
|
||||
from typing import Optional
|
||||
|
||||
i18n_catalog = i18nCatalog("cura")
|
||||
|
||||
## This plugin handles the connection detection & creation of output device objects for the UM3 printer.
|
||||
# Zero-Conf is used to detect printers, which are saved in a dict.
|
||||
@ -27,6 +35,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
addDeviceSignal = Signal()
|
||||
removeDeviceSignal = Signal()
|
||||
discoveredDevicesChanged = Signal()
|
||||
cloudFlowIsPossible = Signal()
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
@ -34,6 +43,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self._zero_conf = None
|
||||
self._zero_conf_browser = None
|
||||
|
||||
self._application = CuraApplication.getInstance()
|
||||
|
||||
# Create a cloud output device manager that abstracts all cloud connection logic away.
|
||||
self._cloud_output_device_manager = CloudOutputDeviceManager()
|
||||
|
||||
@ -41,7 +52,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self.addDeviceSignal.connect(self._onAddDevice)
|
||||
self.removeDeviceSignal.connect(self._onRemoveDevice)
|
||||
|
||||
CuraApplication.getInstance().globalContainerStackChanged.connect(self.reCheckConnections)
|
||||
self._application.globalContainerStackChanged.connect(self.reCheckConnections)
|
||||
|
||||
self._discovered_devices = {}
|
||||
|
||||
@ -49,6 +60,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self._network_manager.finished.connect(self._onNetworkRequestFinished)
|
||||
|
||||
self._min_cluster_version = Version("4.0.0")
|
||||
self._min_cloud_version = Version("5.2.0")
|
||||
|
||||
self._api_version = "1"
|
||||
self._api_prefix = "/api/v" + self._api_version + "/"
|
||||
@ -74,6 +86,26 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self._service_changed_request_thread = Thread(target=self._handleOnServiceChangedRequests, daemon=True)
|
||||
self._service_changed_request_thread.start()
|
||||
|
||||
self._account = self._application.getCuraAPI().account
|
||||
|
||||
# Check if cloud flow is possible when user logs in
|
||||
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
|
||||
self.cloudFlowIsPossible.connect(self._onCloudFlowPossible)
|
||||
|
||||
# Listen if cloud cluster was added
|
||||
self._cloud_output_device_manager.addedCloudCluster.connect(self._onCloudPrintingConfigured)
|
||||
|
||||
# Listen if cloud cluster was removed
|
||||
self._cloud_output_device_manager.removedCloudCluster.connect(self.checkCloudFlowIsPossible)
|
||||
|
||||
self._start_cloud_flow_message = None # type: Optional[Message]
|
||||
self._cloud_flow_complete_message = None # type: Optional[Message]
|
||||
|
||||
def getDiscoveredDevices(self):
|
||||
return self._discovered_devices
|
||||
|
||||
@ -138,6 +170,7 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
um_network_key = CuraApplication.getInstance().getGlobalContainerStack().getMetaDataEntry("um_network_key")
|
||||
if key == um_network_key:
|
||||
self.getOutputDeviceManager().addOutputDevice(self._discovered_devices[key])
|
||||
self.checkCloudFlowIsPossible()
|
||||
else:
|
||||
self.getOutputDeviceManager().removeOutputDevice(key)
|
||||
|
||||
@ -370,3 +403,113 @@ class UM3OutputDevicePlugin(OutputDevicePlugin):
|
||||
self.removeDeviceSignal.emit(str(name))
|
||||
|
||||
return True
|
||||
|
||||
## Check if the prerequsites are in place to start the cloud flow
|
||||
def checkCloudFlowIsPossible(self) -> None:
|
||||
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 # type: Optional["GlobalStack"]
|
||||
if active_machine:
|
||||
|
||||
# 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
|
||||
|
||||
# Check 2: User did not already say "Don't ask me again"
|
||||
if active_machine.getMetaDataEntry("show_cloud_message", "value") is False:
|
||||
Logger.log("d", "Active machine shouldn't ask about cloud anymore.")
|
||||
return
|
||||
|
||||
# Check 3: User is logged in with an Ultimaker account
|
||||
if not self._account.isLoggedIn:
|
||||
Logger.log("d", "Cloud Flow not possible: User not logged in!")
|
||||
return
|
||||
|
||||
# Check 4: Machine is configured for network connectivity
|
||||
if not self._application.getMachineManager().activeMachineHasActiveNetworkConnection:
|
||||
Logger.log("d", "Cloud Flow not possible: Machine is not connected!")
|
||||
return
|
||||
|
||||
# Check 5: Machine has correct firmware version
|
||||
firmware_version = self._application.getMachineManager().activeMachineFirmwareVersion # type: str
|
||||
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)",
|
||||
firmware_version,
|
||||
self._min_cloud_version)
|
||||
return
|
||||
|
||||
Logger.log("d", "Cloud flow is possible!")
|
||||
self.cloudFlowIsPossible.emit()
|
||||
|
||||
def _onCloudFlowPossible(self) -> None:
|
||||
# Cloud flow is possible, so show the message
|
||||
if not self._start_cloud_flow_message:
|
||||
self._start_cloud_flow_message = Message(
|
||||
text = i18n_catalog.i18nc("@info:status", "Pair your printer to your Ultimaker account and start print jobs from anywhere."),
|
||||
image_source = "../../../../../Cura/plugins/UM3NetworkPrinting/resources/svg/cloud-flow-start.svg",
|
||||
image_caption = i18n_catalog.i18nc("@info:status", "Connect to cloud"),
|
||||
option_text = i18n_catalog.i18nc("@action", "Don't ask me again for this printer."),
|
||||
option_state = False
|
||||
)
|
||||
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.actionTriggered.connect(self._onCloudFlowStarted)
|
||||
self._start_cloud_flow_message.show()
|
||||
return
|
||||
|
||||
def _onCloudPrintingConfigured(self) -> None:
|
||||
if self._start_cloud_flow_message:
|
||||
self._start_cloud_flow_message.hide()
|
||||
self._start_cloud_flow_message = None
|
||||
|
||||
# Show the successful pop-up
|
||||
if not self._start_cloud_flow_message:
|
||||
self._cloud_flow_complete_message = Message(
|
||||
text = i18n_catalog.i18nc("@info:status", "You can now send and monitor print jobs from anywhere using your Ultimaker account."),
|
||||
lifetime = 30,
|
||||
image_source = "../../../../../Cura/plugins/UM3NetworkPrinting/resources/svg/cloud-flow-completed.svg",
|
||||
image_caption = i18n_catalog.i18nc("@info:status", "Connected!")
|
||||
)
|
||||
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, messageId: str, checked: bool) -> None:
|
||||
active_machine = self._application.getMachineManager().activeMachine # type: Optional["GlobalStack"]
|
||||
if active_machine:
|
||||
active_machine.setMetaDataEntry("show_cloud_message", False)
|
||||
Logger.log("d", "Will not ask the user again to cloud connect for current printer.")
|
||||
return
|
||||
|
||||
def _onCloudFlowStarted(self, messageId: str, actionId: str) -> None:
|
||||
address = self._application.getMachineManager().activeMachineAddress # type: str
|
||||
if address:
|
||||
QDesktopServices.openUrl(QUrl("http://" + address + "/cloud_connect"))
|
||||
if self._start_cloud_flow_message:
|
||||
self._start_cloud_flow_message.hide()
|
||||
self._start_cloud_flow_message = None
|
||||
return
|
||||
|
||||
def _onReviewCloudConnection(self, messageId: str, actionId: str) -> None:
|
||||
address = self._application.getMachineManager().activeMachineAddress # type: str
|
||||
if address:
|
||||
QDesktopServices.openUrl(QUrl("http://" + address + "/settings"))
|
||||
return
|
||||
|
||||
def _onMachineSwitched(self) -> None:
|
||||
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