From 669dcc62ddc9a091a426d2b3d90c410b56798c90 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 9 Jun 2020 15:20:15 +0200 Subject: [PATCH 01/10] Add extra "AddPrinterPagesModel" without the cancel button This commit adds an additional AddPrinterPagesModel in Cura that does not have the "Cancel" button in the "Add Printer" page. To achieve that, the AddPrinterPagesModel is modified so that its initialize function decides whether or not it will add the cancel button. If Cura ends up in a state without an active machine, the AddPrinters dialog will open up using the showAddPrintersUncancellableDialog signal and display the new "Uncancellable" (is this a word?) AddPrinterPagesModel, so that the dialog cannot be dismissed. If Cura is closed at that point, the next time it is initiated, if the user is logged in and there is no ActiveMachine, then instead of displaying the entire WelcomePages wizard, it will show the uncancellable AddPrinterPagesModel, forcing the user to add a printer. CURA-7454 --- cura/CuraApplication.py | 14 +++++++++++++- cura/UI/AddPrinterPagesModel.py | 6 ++++-- resources/qml/Cura.qml | 24 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index a4d7bc303e..510b2b2053 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -207,6 +207,7 @@ class CuraApplication(QtApplication): self._first_start_machine_actions_model = None self._welcome_pages_model = WelcomePagesModel(self, parent = self) self._add_printer_pages_model = AddPrinterPagesModel(self, parent = self) + self._add_printer_pages_model_without_cancel = AddPrinterPagesModel(self, parent = self) self._whats_new_pages_model = WhatsNewPagesModel(self, parent = self) self._text_manager = TextManager(parent = self) @@ -647,7 +648,7 @@ class CuraApplication(QtApplication): return self._global_container_stack @override(Application) - def setGlobalContainerStack(self, stack: "GlobalStack") -> None: + def setGlobalContainerStack(self, stack: Optional[GlobalStack]) -> None: self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Initializing Active Machine...")) super().setGlobalContainerStack(stack) @@ -812,6 +813,7 @@ class CuraApplication(QtApplication): self._output_device_manager.start() self._welcome_pages_model.initialize() self._add_printer_pages_model.initialize() + self._add_printer_pages_model_without_cancel.initialize(cancellable = False) self._whats_new_pages_model.initialize() # Detect in which mode to run and execute that mode @@ -849,6 +851,7 @@ class CuraApplication(QtApplication): self.callLater(self._openFile, file_name) initializationFinished = pyqtSignal() + showAddPrintersUncancellableDialog = pyqtSignal() # Used to show the add printers dialog with a greyed background def runWithoutGUI(self): """Run Cura without GUI elements and interaction (server mode).""" @@ -939,6 +942,10 @@ class CuraApplication(QtApplication): def getAddPrinterPagesModel(self, *args) -> "AddPrinterPagesModel": return self._add_printer_pages_model + @pyqtSlot(result = QObject) + def getAddPrinterPagesModelWithoutCancel(self, *args) -> "AddPrinterPagesModel": + return self._add_printer_pages_model_without_cancel + @pyqtSlot(result = QObject) def getWhatsNewPagesModel(self, *args) -> "WhatsNewPagesModel": return self._whats_new_pages_model @@ -1940,6 +1947,11 @@ class CuraApplication(QtApplication): # Only show the complete flow if there is no printer yet. return self._machine_manager.activeMachine is None + @pyqtSlot(result = bool) + def shouldShowAddPrintersUncancellableDialog(self) -> bool: + # If there is no printer and the user is logged in, show only the add printers flow in the welcome dialog. + return self._machine_manager.activeMachine is None and self.getCuraAPI().account.isLoggedIn + @pyqtSlot(result = bool) def shouldShowWhatsNewDialog(self) -> bool: has_active_machine = self._machine_manager.activeMachine is not None diff --git a/cura/UI/AddPrinterPagesModel.py b/cura/UI/AddPrinterPagesModel.py index b06f220374..9b35dbcacc 100644 --- a/cura/UI/AddPrinterPagesModel.py +++ b/cura/UI/AddPrinterPagesModel.py @@ -10,12 +10,11 @@ from .WelcomePagesModel import WelcomePagesModel # class AddPrinterPagesModel(WelcomePagesModel): - def initialize(self) -> None: + def initialize(self, cancellable: bool = True) -> None: self._pages.append({"id": "add_network_or_local_printer", "page_url": self._getBuiltinWelcomePagePath("AddNetworkOrLocalPrinterContent.qml"), "next_page_id": "machine_actions", "next_page_button_text": self._catalog.i18nc("@action:button", "Add"), - "previous_page_button_text": self._catalog.i18nc("@action:button", "Cancel"), }) self._pages.append({"id": "add_printer_by_ip", "page_url": self._getBuiltinWelcomePagePath("AddPrinterByIpContent.qml"), @@ -30,6 +29,9 @@ class AddPrinterPagesModel(WelcomePagesModel): "page_url": self._getBuiltinWelcomePagePath("FirstStartMachineActionsContent.qml"), "should_show_function": self.shouldShowMachineActions, }) + if cancellable: + self._pages[0]["previous_page_button_text"] = self._catalog.i18nc("@action:button", "Cancel") + self.setItems(self._pages) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index ed2c6dc5fe..da195720f7 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -84,6 +84,21 @@ UM.MainWindow CuraApplication.purgeWindows() } + Connections + { + // This connection is used when there is no ActiveMachine and the user is logged in + target: CuraApplication + onShowAddPrintersUncancellableDialog: + { + Cura.Actions.parent = backgroundItem + + // Reuse the welcome dialog item to show "Add a printer" only. + welcomeDialogItem.model = CuraApplication.getAddPrinterPagesModelWithoutCancel() + welcomeDialogItem.progressBarVisible = false + welcomeDialogItem.visible = true + } + } + Connections { target: CuraApplication @@ -117,6 +132,15 @@ UM.MainWindow welcomeDialogItem.progressBarVisible = false welcomeDialogItem.visible = true } + + // Reuse the welcome dialog item to show the "Add printers" dialog. Triggered when there is no active + // machine and the user is logged in. + if (CuraApplication.shouldShowAddPrintersUncancellableDialog()) + { + welcomeDialogItem.model = CuraApplication.getAddPrinterPagesModelWithoutCancel() + welcomeDialogItem.progressBarVisible = false + welcomeDialogItem.visible = true + } } } From 5c898b8c579c3de4a9f93230be9fc2f536246ce1 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 9 Jun 2020 15:33:22 +0200 Subject: [PATCH 02/10] Allow the machine manager to set an empty active machine Gracefully handle the case where the machine manager is requested to delete the last machine in Cura. In this case, instead of deleting everything of this machine and still keep it as an active machine, the machine manager will set the active machine to None. The QML files which depend on the active machine were changed to properly handle themselves when there is no active machine. CURA-7454 --- cura/Machines/Models/BaseMaterialsModel.py | 2 +- cura/Settings/MachineManager.py | 10 +++++++++- resources/qml/Dialogs/WorkspaceSummaryDialog.qml | 2 +- .../qml/Menus/ConfigurationMenu/ConfigurationMenu.qml | 6 +++--- .../Menus/ConfigurationMenu/CustomConfiguration.qml | 4 ++-- .../Recommended/RecommendedSupportSelector.qml | 6 +++++- resources/qml/PrinterSelector/MachineSelectorList.qml | 4 ++-- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/cura/Machines/Models/BaseMaterialsModel.py b/cura/Machines/Models/BaseMaterialsModel.py index aa8552bebb..776d540867 100644 --- a/cura/Machines/Models/BaseMaterialsModel.py +++ b/cura/Machines/Models/BaseMaterialsModel.py @@ -154,7 +154,7 @@ class BaseMaterialsModel(ListModel): # Update the available materials (ContainerNode) for the current active machine and extruder setup. global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack() - if not global_stack.hasMaterials: + if not global_stack or not global_stack.hasMaterials: return # There are no materials for this machine, so nothing to do. extruder_list = global_stack.extruderList if self._extruder_position > len(extruder_list): diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index e5eec988e7..516579ede2 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -290,9 +290,15 @@ class MachineManager(QObject): self.activeStackValueChanged.emit() @pyqtSlot(str) - def setActiveMachine(self, stack_id: str) -> None: + def setActiveMachine(self, stack_id: Optional[str]) -> None: self.blurSettings.emit() # Ensure no-one has focus. + if not stack_id: + self._application.setGlobalContainerStack(None) + self.globalContainerChanged.emit() + self._application.showAddPrintersUncancellableDialog.emit() + return + container_registry = CuraContainerRegistry.getInstance() containers = container_registry.findContainerStacks(id = stack_id) if not containers: @@ -717,6 +723,8 @@ class MachineManager(QObject): other_machine_stacks = [s for s in machine_stacks if s["id"] != machine_id] if other_machine_stacks: self.setActiveMachine(other_machine_stacks[0]["id"]) + else: + self.setActiveMachine(None) metadatas = CuraContainerRegistry.getInstance().findContainerStacksMetadata(id = machine_id) if not metadatas: diff --git a/resources/qml/Dialogs/WorkspaceSummaryDialog.qml b/resources/qml/Dialogs/WorkspaceSummaryDialog.qml index 6fe9607274..670766204f 100644 --- a/resources/qml/Dialogs/WorkspaceSummaryDialog.qml +++ b/resources/qml/Dialogs/WorkspaceSummaryDialog.qml @@ -143,7 +143,7 @@ UM.Dialog { width: parent.width height: childrenRect.height - model: Cura.MachineManager.activeMachine.extruderList + model: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.extruderList : null delegate: Column { height: childrenRect.height diff --git a/resources/qml/Menus/ConfigurationMenu/ConfigurationMenu.qml b/resources/qml/Menus/ConfigurationMenu/ConfigurationMenu.qml index 9891fc1d69..0d7a5886d2 100644 --- a/resources/qml/Menus/ConfigurationMenu/ConfigurationMenu.qml +++ b/resources/qml/Menus/ConfigurationMenu/ConfigurationMenu.qml @@ -33,7 +33,7 @@ Cura.ExpandablePopup } contentPadding: UM.Theme.getSize("default_lining").width - enabled: Cura.MachineManager.activeMachine.hasMaterials || Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates; //Only let it drop down if there is any configuration that you could change. + enabled: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasMaterials || Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates : false; //Only let it drop down if there is any configuration that you could change. headerItem: Item { @@ -84,7 +84,7 @@ Cura.ExpandablePopup { id: variantLabel - visible: Cura.MachineManager.activeMachine.hasVariants + visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasVariants : false text: model.variant elide: Text.ElideRight @@ -114,7 +114,7 @@ Cura.ExpandablePopup color: UM.Theme.getColor("text") renderType: Text.NativeRendering - visible: !Cura.MachineManager.activeMachine.hasMaterials && (Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates) + visible: Cura.MachineManager.activeMachine ? !Cura.MachineManager.activeMachine.hasMaterials && (Cura.MachineManager.activeMachine.hasVariants || Cura.MachineManager.activeMachine.hasVariantBuildplates) : false anchors { diff --git a/resources/qml/Menus/ConfigurationMenu/CustomConfiguration.qml b/resources/qml/Menus/ConfigurationMenu/CustomConfiguration.qml index 65f5bcce8c..010e2e77b0 100644 --- a/resources/qml/Menus/ConfigurationMenu/CustomConfiguration.qml +++ b/resources/qml/Menus/ConfigurationMenu/CustomConfiguration.qml @@ -244,7 +244,7 @@ Item Row { height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0 - visible: Cura.MachineManager.activeMachine.hasMaterials + visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasMaterials : false Label { @@ -305,7 +305,7 @@ Item Row { height: visible ? UM.Theme.getSize("print_setup_big_item").height : 0 - visible: Cura.MachineManager.activeMachine.hasVariants + visible: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.hasVariants : false Label { diff --git a/resources/qml/PrintSetupSelector/Recommended/RecommendedSupportSelector.qml b/resources/qml/PrintSetupSelector/Recommended/RecommendedSupportSelector.qml index f227dddaf9..92f0024b23 100644 --- a/resources/qml/PrintSetupSelector/Recommended/RecommendedSupportSelector.qml +++ b/resources/qml/PrintSetupSelector/Recommended/RecommendedSupportSelector.qml @@ -130,7 +130,11 @@ Item target: extruderModel onModelChanged: { - supportExtruderCombobox.color = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color + var maybeColor = supportExtruderCombobox.model.getItem(supportExtruderCombobox.currentIndex).color + if (maybeColor) + { + supportExtruderCombobox.color = maybeColor + } } } onCurrentIndexChanged: diff --git a/resources/qml/PrinterSelector/MachineSelectorList.qml b/resources/qml/PrinterSelector/MachineSelectorList.qml index a7c041630f..18b1a68b20 100644 --- a/resources/qml/PrinterSelector/MachineSelectorList.qml +++ b/resources/qml/PrinterSelector/MachineSelectorList.qml @@ -28,11 +28,11 @@ ListView delegate: MachineSelectorButton { - text: model.name + text: model.name ? model.name : "" width: listView.width outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null - checked: Cura.MachineManager.activeMachine.id == model.id + checked: Cura.MachineManager.activeMachine ? Cura.MachineManager.activeMachine.id == model.id : false onClicked: { From 567f6dabdc792ebb9ffc3dd6e62cbe24a8a47e27 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 9 Jun 2020 15:40:30 +0200 Subject: [PATCH 03/10] Add option to remove all printers not linked to the account When the "Printers removed from account" message pops up, it will give the option to the user to remove all the printers that are not linked to his/her account from Cura. Since this action removes all configurations, it first pops a confirmation question box, and if the user insists, these printers are purged from Cura. Note: In order to properly delete all the files, the printers have to be activated first before they are removed, or else some extruder files in %appdata%/cura//user and %appdata%/cura// extruders remain. CURA-7454 --- .../src/Cloud/CloudOutputDeviceManager.py | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index c4ffe44fb1..a537f5aa24 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -4,6 +4,7 @@ import os from typing import Dict, List, Optional, Set from PyQt5.QtNetwork import QNetworkReply +from PyQt5.QtWidgets import QMessageBox from UM import i18nCatalog from UM.Logger import Logger # To log errors talking to the API. @@ -293,6 +294,12 @@ class CloudOutputDeviceManager: icon = "", description = "Keep the configuration of the cloud printer(s) synced with Cura which are not linked to your account.", button_align = Message.ActionButtonAlignment.ALIGN_RIGHT) + removed_printers_message.addAction("remove_printers_action", + name = self.I18N_CATALOG.i18nc("@action:button", "Remove printers"), + icon = "", + description = "Remove the cloud printer(s) which are not linked to your account.", + button_style = Message.ActionButtonStyle.SECONDARY, + button_align = Message.ActionButtonAlignment.ALIGN_LEFT) removed_printers_message.actionTriggered.connect(self._onRemovedPrintersMessageActionTriggered) output_device_manager = CuraApplication.getInstance().getOutputDeviceManager() @@ -397,7 +404,23 @@ class CloudOutputDeviceManager: if container_cluster_id in self._remote_clusters.keys(): del self._remote_clusters[container_cluster_id] - @staticmethod - def _onRemovedPrintersMessageActionTriggered(removed_printers_message: Message, action: str) -> None: + def _onRemovedPrintersMessageActionTriggered(self, removed_printers_message: Message, action: str) -> None: if action == "keep_printer_configurations_action": removed_printers_message.hide() + elif action == "remove_printers_action": + machine_manager = CuraApplication.getInstance().getMachineManager() + remove_printers_ids = {self._um_cloud_printers[i].getId() for i in self.reported_device_ids} + all_ids = {m.getId() for m in CuraApplication.getInstance().getContainerRegistry().findContainerStacks(type = "machine")} + + question_title = self.I18N_CATALOG.i18nc("@title:window", "Remove printers?") + question_content = self.I18N_CATALOG.i18nc("@label", "You are about to remove {} printer(s) from Cura. This action cannot be undone. \nAre you sure you want to continue?".format(len(remove_printers_ids))) + if remove_printers_ids == all_ids: + question_content = self.I18N_CATALOG.i18nc("@label", "You are about to remove all printers from Cura. This action cannot be undone. \nAre you sure you want to continue?") + result = QMessageBox.question(None, question_title, question_content) + if result == QMessageBox.No: + return + + for machine_cloud_id in self.reported_device_ids: + machine_manager.setActiveMachine(self._um_cloud_printers[machine_cloud_id].getId()) + machine_manager.removeMachine(self._um_cloud_printers[machine_cloud_id].getId()) + removed_printers_message.hide() From f26445a914fcecc01dbf3d9b39aa3a3b6fcdd9ad Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 9 Jun 2020 16:01:38 +0200 Subject: [PATCH 04/10] Fix mypy complaint CURA-7454 --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 510b2b2053..c806da6151 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -648,7 +648,7 @@ class CuraApplication(QtApplication): return self._global_container_stack @override(Application) - def setGlobalContainerStack(self, stack: Optional[GlobalStack]) -> None: + def setGlobalContainerStack(self, stack: Optional["GlobalStack"]) -> None: self._setLoadingHint(self._i18n_catalog.i18nc("@info:progress", "Initializing Active Machine...")) super().setGlobalContainerStack(stack) From 1c9ce25614a3b9c90b5d160f67ce4fec0b3ba824 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 9 Jun 2020 17:24:36 +0200 Subject: [PATCH 05/10] Change lifetime of the removed_printers_message to 30 seconds After 30 seconds a new sync will be initiated, which will alter the conents of self.reported_device_ids, thus making the current message deprecated. Therefore, it is best to have a maximum lifetime of 30 seconds. CURA-7454 --- .../UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index a537f5aa24..35865c11ad 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -273,7 +273,7 @@ class CloudOutputDeviceManager: "Cloud connection is not available for some printers", len(self.reported_device_ids) ), - lifetime = 0 + lifetime = 30 ) device_names = "\n".join(["
  • {} ({})
  • ".format(self._um_cloud_printers[device].name, self._um_cloud_printers[device].definition.name) for device in self.reported_device_ids]) message_text = self.I18N_CATALOG.i18ncp( From 2442371c2f6b755505accee5f542faeacb0bb453 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 9 Jun 2020 17:42:53 +0200 Subject: [PATCH 06/10] Hide the message if a manual check is initiated This has to be done in order to avoid weird actions taking place, such as the user pressing to remove the printers while another sync is happening. CURA-7454 --- .../src/Cloud/CloudOutputDeviceManager.py | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 35865c11ad..b45ebe6b74 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -51,6 +51,7 @@ class CloudOutputDeviceManager: self._account = CuraApplication.getInstance().getCuraAPI().account # type: Account self._api = CloudApiClient(CuraApplication.getInstance(), on_error = lambda error: Logger.log("e", str(error))) self._account.loginStateChanged.connect(self._onLoginStateChanged) + self.removed_printers_message = None # type: Optional[Message] # Ensure we don't start twice. self._running = False @@ -121,6 +122,11 @@ class CloudOutputDeviceManager: self._um_cloud_printers[device_id].setMetaDataEntry(META_UM_LINKED_TO_ACCOUNT, True) self._onDevicesDiscovered(new_clusters) + # Hide the current removed_printers_message, if there is any + if self.removed_printers_message: + self.removed_printers_message.actionTriggered.disconnect(self._onRemovedPrintersMessageActionTriggered) + self.removed_printers_message.hide() + # Remove the CloudOutput device for offline printers offline_device_keys = set(self._remote_clusters.keys()) - set(online_clusters.keys()) for device_id in offline_device_keys: @@ -266,7 +272,7 @@ class CloudOutputDeviceManager: return # Generate message - removed_printers_message = Message( + self.removed_printers_message = Message( title = self.I18N_CATALOG.i18ncp( "info:status", "Cloud connection is not available for a printer", @@ -288,19 +294,19 @@ class CloudOutputDeviceManager: "Ultimaker Digital Factory.", device_names ) - removed_printers_message.setText(message_text) - removed_printers_message.addAction("keep_printer_configurations_action", + self.removed_printers_message.setText(message_text) + self.removed_printers_message.addAction("keep_printer_configurations_action", name = self.I18N_CATALOG.i18nc("@action:button", "Keep printer configurations"), icon = "", description = "Keep the configuration of the cloud printer(s) synced with Cura which are not linked to your account.", button_align = Message.ActionButtonAlignment.ALIGN_RIGHT) - removed_printers_message.addAction("remove_printers_action", + self.removed_printers_message.addAction("remove_printers_action", name = self.I18N_CATALOG.i18nc("@action:button", "Remove printers"), icon = "", description = "Remove the cloud printer(s) which are not linked to your account.", button_style = Message.ActionButtonStyle.SECONDARY, button_align = Message.ActionButtonAlignment.ALIGN_LEFT) - removed_printers_message.actionTriggered.connect(self._onRemovedPrintersMessageActionTriggered) + self.removed_printers_message.actionTriggered.connect(self._onRemovedPrintersMessageActionTriggered) output_device_manager = CuraApplication.getInstance().getOutputDeviceManager() @@ -317,7 +323,7 @@ class CloudOutputDeviceManager: # Update the printer's metadata to mark it as not linked to the account device.setMetaDataEntry(META_UM_LINKED_TO_ACCOUNT, False) - removed_printers_message.show() + self.removed_printers_message.show() def _onDiscoveredDeviceRemoved(self, device_id: str) -> None: device = self._remote_clusters.pop(device_id, None) # type: Optional[CloudOutputDevice] @@ -406,7 +412,7 @@ class CloudOutputDeviceManager: def _onRemovedPrintersMessageActionTriggered(self, removed_printers_message: Message, action: str) -> None: if action == "keep_printer_configurations_action": - removed_printers_message.hide() + self.removed_printers_message.hide() elif action == "remove_printers_action": machine_manager = CuraApplication.getInstance().getMachineManager() remove_printers_ids = {self._um_cloud_printers[i].getId() for i in self.reported_device_ids} @@ -423,4 +429,4 @@ class CloudOutputDeviceManager: for machine_cloud_id in self.reported_device_ids: machine_manager.setActiveMachine(self._um_cloud_printers[machine_cloud_id].getId()) machine_manager.removeMachine(self._um_cloud_printers[machine_cloud_id].getId()) - removed_printers_message.hide() + self.removed_printers_message.hide() From b9956f2ae2b92324414493afe8822411bf26337b Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Tue, 9 Jun 2020 17:51:06 +0200 Subject: [PATCH 07/10] Fix failing tests CURA-7454 --- .../UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index b45ebe6b74..c6aa5ef3f7 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -412,7 +412,7 @@ class CloudOutputDeviceManager: def _onRemovedPrintersMessageActionTriggered(self, removed_printers_message: Message, action: str) -> None: if action == "keep_printer_configurations_action": - self.removed_printers_message.hide() + removed_printers_message.hide() elif action == "remove_printers_action": machine_manager = CuraApplication.getInstance().getMachineManager() remove_printers_ids = {self._um_cloud_printers[i].getId() for i in self.reported_device_ids} @@ -429,4 +429,4 @@ class CloudOutputDeviceManager: for machine_cloud_id in self.reported_device_ids: machine_manager.setActiveMachine(self._um_cloud_printers[machine_cloud_id].getId()) machine_manager.removeMachine(self._um_cloud_printers[machine_cloud_id].getId()) - self.removed_printers_message.hide() + removed_printers_message.hide() From 20c9be285f4a89c2cb81efb9fe285718e055e1e6 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Wed, 10 Jun 2020 12:50:03 +0200 Subject: [PATCH 08/10] Remove unnecessary variable from CuraApplication In response to feedback comment https://github.com/Ultimaker/Cura/pull/7904#discussion_r438022415 CURA-7454 --- cura/CuraApplication.py | 5 ----- resources/qml/Cura.qml | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index c806da6151..19f8174a95 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -1947,11 +1947,6 @@ class CuraApplication(QtApplication): # Only show the complete flow if there is no printer yet. return self._machine_manager.activeMachine is None - @pyqtSlot(result = bool) - def shouldShowAddPrintersUncancellableDialog(self) -> bool: - # If there is no printer and the user is logged in, show only the add printers flow in the welcome dialog. - return self._machine_manager.activeMachine is None and self.getCuraAPI().account.isLoggedIn - @pyqtSlot(result = bool) def shouldShowWhatsNewDialog(self) -> bool: has_active_machine = self._machine_manager.activeMachine is not None diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index da195720f7..8ba651a5b0 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -135,7 +135,7 @@ UM.MainWindow // Reuse the welcome dialog item to show the "Add printers" dialog. Triggered when there is no active // machine and the user is logged in. - if (CuraApplication.shouldShowAddPrintersUncancellableDialog()) + if (!Cura.MachineManager.activeMachine && Cura.API.account.isLoggedIn) { welcomeDialogItem.model = CuraApplication.getAddPrinterPagesModelWithoutCancel() welcomeDialogItem.progressBarVisible = false From ad36903cbbe05207822c7492dfcf93a13864a0ab Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Wed, 10 Jun 2020 12:59:39 +0200 Subject: [PATCH 09/10] Convert removed_printers_message into private In response to feedback comment https://github.com/Ultimaker/Cura/pull/7904#discussion_r438023220 CURA-7454 --- .../src/Cloud/CloudOutputDeviceManager.py | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index d2968acb2c..8c81ce39a8 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -51,7 +51,7 @@ class CloudOutputDeviceManager: self._account = CuraApplication.getInstance().getCuraAPI().account # type: Account self._api = CloudApiClient(CuraApplication.getInstance(), on_error = lambda error: Logger.log("e", str(error))) self._account.loginStateChanged.connect(self._onLoginStateChanged) - self.removed_printers_message = None # type: Optional[Message] + self._removed_printers_message = None # type: Optional[Message] # Ensure we don't start twice. self._running = False @@ -123,9 +123,9 @@ class CloudOutputDeviceManager: self._onDevicesDiscovered(new_clusters) # Hide the current removed_printers_message, if there is any - if self.removed_printers_message: - self.removed_printers_message.actionTriggered.disconnect(self._onRemovedPrintersMessageActionTriggered) - self.removed_printers_message.hide() + if self._removed_printers_message: + self._removed_printers_message.actionTriggered.disconnect(self._onRemovedPrintersMessageActionTriggered) + self._removed_printers_message.hide() # Remove the CloudOutput device for offline printers offline_device_keys = set(self._remote_clusters.keys()) - set(online_clusters.keys()) @@ -276,7 +276,7 @@ class CloudOutputDeviceManager: return # Generate message - self.removed_printers_message = Message( + self._removed_printers_message = Message( title = self.I18N_CATALOG.i18ncp( "info:status", "Cloud connection is not available for a printer", @@ -298,19 +298,19 @@ class CloudOutputDeviceManager: "Ultimaker Digital Factory.", device_names ) - self.removed_printers_message.setText(message_text) - self.removed_printers_message.addAction("keep_printer_configurations_action", - name = self.I18N_CATALOG.i18nc("@action:button", "Keep printer configurations"), - icon = "", - description = "Keep the configuration of the cloud printer(s) synced with Cura which are not linked to your account.", - button_align = Message.ActionButtonAlignment.ALIGN_RIGHT) - self.removed_printers_message.addAction("remove_printers_action", - name = self.I18N_CATALOG.i18nc("@action:button", "Remove printers"), - icon = "", - description = "Remove the cloud printer(s) which are not linked to your account.", - button_style = Message.ActionButtonStyle.SECONDARY, - button_align = Message.ActionButtonAlignment.ALIGN_LEFT) - self.removed_printers_message.actionTriggered.connect(self._onRemovedPrintersMessageActionTriggered) + self._removed_printers_message.setText(message_text) + self._removed_printers_message.addAction("keep_printer_configurations_action", + name = self.I18N_CATALOG.i18nc("@action:button", "Keep printer configurations"), + icon = "", + description = "Keep the configuration of the cloud printer(s) synced with Cura which are not linked to your account.", + button_align = Message.ActionButtonAlignment.ALIGN_RIGHT) + self._removed_printers_message.addAction("remove_printers_action", + name = self.I18N_CATALOG.i18nc("@action:button", "Remove printers"), + icon = "", + description = "Remove the cloud printer(s) which are not linked to your account.", + button_style = Message.ActionButtonStyle.SECONDARY, + button_align = Message.ActionButtonAlignment.ALIGN_LEFT) + self._removed_printers_message.actionTriggered.connect(self._onRemovedPrintersMessageActionTriggered) output_device_manager = CuraApplication.getInstance().getOutputDeviceManager() @@ -327,7 +327,7 @@ class CloudOutputDeviceManager: # Update the printer's metadata to mark it as not linked to the account device.setMetaDataEntry(META_UM_LINKED_TO_ACCOUNT, False) - self.removed_printers_message.show() + self._removed_printers_message.show() def _onDiscoveredDeviceRemoved(self, device_id: str) -> None: device = self._remote_clusters.pop(device_id, None) # type: Optional[CloudOutputDevice] From defa3fd94081deccec79f337b91dbac5294d25ba Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Wed, 10 Jun 2020 13:00:55 +0200 Subject: [PATCH 10/10] Remove lifetime of message, since it is the same as the default In response to feedback comment https://github.com/Ultimaker/Cura/pull/7904#discussion_r438023812 CURA-7454 --- .../UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index 8c81ce39a8..33c9caba05 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -282,8 +282,7 @@ class CloudOutputDeviceManager: "Cloud connection is not available for a printer", "Cloud connection is not available for some printers", len(self.reported_device_ids) - ), - lifetime = 30 + ) ) device_names = "\n".join(["
  • {} ({})
  • ".format(self._um_cloud_printers[device].name, self._um_cloud_printers[device].definition.name) for device in self.reported_device_ids]) message_text = self.I18N_CATALOG.i18ncp(