diff --git a/cura/Machines/Models/MaterialManagementModel.py b/cura/Machines/Models/MaterialManagementModel.py index c75e16cd63..31f9bfbc92 100644 --- a/cura/Machines/Models/MaterialManagementModel.py +++ b/cura/Machines/Models/MaterialManagementModel.py @@ -10,6 +10,7 @@ import zipfile # To export all materials in a .zip archive. from UM.i18n import i18nCatalog from UM.Logger import Logger from UM.Message import Message +from UM.Resources import Resources # To find QML files. from UM.Signal import postponeSignals, CompressTechnique import cura.CuraApplication # Imported like this to prevent circular imports. @@ -28,6 +29,10 @@ class MaterialManagementModel(QObject): :param The base file of the material is provided as parameter when this emits """ + def __init__(self, parent: QObject = None): + super().__init__(parent) + self._sync_all_dialog = None # type: Optional[QObject] + @pyqtSlot("QVariant", result = bool) def canMaterialBeRemoved(self, material_node: "MaterialNode") -> bool: """Can a certain material be deleted, or is it still in use in one of the container stacks anywhere? @@ -262,6 +267,18 @@ class MaterialManagementModel(QObject): except ValueError: # Material was not in the favorites list. Logger.log("w", "Material {material_base_file} was already not a favorite material.".format(material_base_file = material_base_file)) + @pyqtSlot() + def openSyncAllWindow(self) -> None: + """ + Opens the window to sync all materials. + """ + if self._sync_all_dialog is None: + qml_path = Resources.getPath(cura.CuraApplication.CuraApplication.ResourceTypes.QmlFiles, "Preferences", "Materials", "MaterialsSyncDialog.qml") + self._sync_all_dialog = cura.CuraApplication.CuraApplication.getInstance().createQmlComponent(qml_path, {}) + if self._sync_all_dialog is None: # Failed to load QML file. + return + self._sync_all_dialog.show() + @pyqtSlot(result = QUrl) def getPreferredExportAllPath(self) -> QUrl: """ diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index 8f15838e0d..1d3519624d 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -201,7 +201,7 @@ Item onClicked: { forceActiveFocus(); - materialsSyncDialog.show(); + base.materialManagementModel.openSyncAllWindow(); } visible: Cura.MachineManager.activeMachine.supportsMaterialExport } @@ -399,9 +399,4 @@ Item { id: messageDialog } - - MaterialsSyncDialog - { - id: materialsSyncDialog - } } diff --git a/resources/qml/Preferences/Materials/MaterialsSyncDialog.qml b/resources/qml/Preferences/Materials/MaterialsSyncDialog.qml index 55a44f3ad5..d7d92e1d5e 100644 --- a/resources/qml/Preferences/Materials/MaterialsSyncDialog.qml +++ b/resources/qml/Preferences/Materials/MaterialsSyncDialog.qml @@ -9,6 +9,8 @@ import UM 1.2 as UM Window { id: materialsSyncDialog + property variant catalog: UM.I18nCatalog { name: "cura" } + title: catalog.i18nc("@title:window", "Sync materials with printers") minimumWidth: UM.Theme.getSize("modal_window_minimum").width minimumHeight: UM.Theme.getSize("modal_window_minimum").height