diff options
author | Ghostkeeper <rubend@tutanota.com> | 2021-10-27 15:21:05 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2021-10-27 15:21:05 +0300 |
commit | 88d08b27d13bc6a0e005381ca75863292d59d707 (patch) | |
tree | c5da950b57293392dfa937b2bb2fa7cdc834e9f9 /cura | |
parent | 273e93314581c5d78ce3291167ebaaf3b8800128 (diff) | |
parent | 101056bca68c9f36630e0267867836ec88a6e912 (diff) |
Merge branch 'master' into CURA-8609_sync_materials_to_printer
Conflicts:
cura/Machines/Models/MaterialManagementModel.py -> On Master we had temporarily reverted the action of this button because it became apparent that the sync wasn't going to be in 4.12. That revert is no longer necessary if this is merged.
Diffstat (limited to 'cura')
-rw-r--r-- | cura/API/Account.py | 17 | ||||
-rw-r--r-- | cura/Machines/Models/ExtrudersModel.py | 6 | ||||
-rw-r--r-- | cura/Machines/Models/MaterialManagementModel.py | 60 |
3 files changed, 81 insertions, 2 deletions
diff --git a/cura/API/Account.py b/cura/API/Account.py index f922c89977..2d4b204333 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -1,7 +1,7 @@ # Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. from datetime import datetime -from typing import Optional, Dict, TYPE_CHECKING, Callable +from typing import Any, Optional, Dict, TYPE_CHECKING, Callable from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot, pyqtProperty, QTimer, Q_ENUMS @@ -46,6 +46,9 @@ class Account(QObject): loginStateChanged = pyqtSignal(bool) """Signal emitted when user logged in or out""" + additionalRightsChanged = pyqtSignal("QVariantMap") + """Signal emitted when a users additional rights change""" + accessTokenChanged = pyqtSignal() syncRequested = pyqtSignal() """Sync services may connect to this signal to receive sync triggers. @@ -70,6 +73,7 @@ class Account(QObject): self._error_message = None # type: Optional[Message] self._logged_in = False + self._additional_rights: Dict[str, Any] = {} self._sync_state = SyncState.IDLE self._manual_sync_enabled = False self._update_packages_enabled = False @@ -301,3 +305,14 @@ class Account(QObject): return # Nothing to do, user isn't logged in. self._authorization_service.deleteAuthData() + + def updateAdditionalRight(self, **kwargs) -> None: + """Update the additional rights of the account. + The argument(s) are the rights that need to be set""" + self._additional_rights.update(kwargs) + self.additionalRightsChanged.emit(self._additional_rights) + + @pyqtProperty("QVariantMap", notify = additionalRightsChanged) + def additionalRights(self) -> Dict[str, Any]: + """A dictionary which can be queried for additional account rights.""" + return self._additional_rights diff --git a/cura/Machines/Models/ExtrudersModel.py b/cura/Machines/Models/ExtrudersModel.py index 1aba1d871a..5ae3c19874 100644 --- a/cura/Machines/Models/ExtrudersModel.py +++ b/cura/Machines/Models/ExtrudersModel.py @@ -59,6 +59,8 @@ class ExtrudersModel(ListModel): defaultColors = ["#ffc924", "#86ec21", "#22eeee", "#245bff", "#9124ff", "#ff24c8"] """List of colours to display if there is no material or the material has no known colour. """ + MaterialNameRole = Qt.UserRole + 13 + def __init__(self, parent = None): """Initialises the extruders model, defining the roles and listening for changes in the data. @@ -79,6 +81,7 @@ class ExtrudersModel(ListModel): self.addRoleName(self.MaterialBrandRole, "material_brand") self.addRoleName(self.ColorNameRole, "color_name") self.addRoleName(self.MaterialTypeRole, "material_type") + self.addRoleName(self.MaterialNameRole, "material_name") self._update_extruder_timer = QTimer() self._update_extruder_timer.setInterval(100) self._update_extruder_timer.setSingleShot(True) @@ -199,8 +202,8 @@ class ExtrudersModel(ListModel): "material_brand": material_brand, "color_name": color_name, "material_type": extruder.material.getMetaDataEntry("material") if extruder.material else "", + "material_name": extruder.material.getMetaDataEntry("name") if extruder.material else "", } - items.append(item) extruders_changed = True @@ -224,6 +227,7 @@ class ExtrudersModel(ListModel): "material_brand": "", "color_name": "", "material_type": "", + "material_label": "" } items.append(item) if self._items != items: diff --git a/cura/Machines/Models/MaterialManagementModel.py b/cura/Machines/Models/MaterialManagementModel.py index 3595d3025a..fd32f26089 100644 --- a/cura/Machines/Models/MaterialManagementModel.py +++ b/cura/Machines/Models/MaterialManagementModel.py @@ -29,9 +29,69 @@ class MaterialManagementModel(QObject): :param The base file of the material is provided as parameter when this emits """ +<<<<<<< HEAD def __init__(self, parent: QObject = None): super().__init__(parent) self._material_sync = CloudMaterialSync(parent = self) +======= + def __init__(self, parent: Optional[QObject] = None) -> None: + super().__init__(parent = parent) + self._checkIfNewMaterialsWereInstalled() + + def _checkIfNewMaterialsWereInstalled(self) -> None: + """ + Checks whether new material packages were installed in the latest startup. If there were, then it shows + a message prompting the user to sync the materials with their printers. + """ + application = cura.CuraApplication.CuraApplication.getInstance() + for package_id, package_data in application.getPackageManager().getPackagesInstalledOnStartup().items(): + if package_data["package_info"]["package_type"] == "material": + # At least one new material was installed + # TODO: This should be enabled again once CURA-8609 is merged + #self._showSyncNewMaterialsMessage() + break + + def _showSyncNewMaterialsMessage(self) -> None: + sync_materials_message = Message( + text = catalog.i18nc("@action:button", + "Please sync the material profiles with your printers before starting to print."), + title = catalog.i18nc("@action:button", "New materials installed"), + message_type = Message.MessageType.WARNING, + lifetime = 0 + ) + + sync_materials_message.addAction( + "sync", + name = catalog.i18nc("@action:button", "Sync materials with printers"), + icon = "", + description = "Sync your newly installed materials with your printers.", + button_align = Message.ActionButtonAlignment.ALIGN_RIGHT + ) + + sync_materials_message.addAction( + "learn_more", + name = catalog.i18nc("@action:button", "Learn more"), + icon = "", + description = "Learn more about syncing your newly installed materials with your printers.", + button_align = Message.ActionButtonAlignment.ALIGN_LEFT, + button_style = Message.ActionButtonStyle.LINK + ) + sync_materials_message.actionTriggered.connect(self._onSyncMaterialsMessageActionTriggered) + + # Show the message only if there are printers that support material export + container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry() + global_stacks = container_registry.findContainerStacks(type = "machine") + if any([stack.supportsMaterialExport for stack in global_stacks]): + sync_materials_message.show() + + def _onSyncMaterialsMessageActionTriggered(self, sync_message: Message, sync_message_action: str): + if sync_message_action == "sync": + QDesktopServices.openUrl(QUrl("https://example.com/openSyncAllWindow")) + # self.openSyncAllWindow() + sync_message.hide() + elif sync_message_action == "learn_more": + QDesktopServices.openUrl(QUrl("https://support.ultimaker.com/hc/en-us/articles/360013137919?utm_source=cura&utm_medium=software&utm_campaign=sync-material-printer-message")) +>>>>>>> master @pyqtSlot("QVariant", result = bool) def canMaterialBeRemoved(self, material_node: "MaterialNode") -> bool: |