diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 6d22320882..01b0e457ae 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -78,6 +78,7 @@ from cura.Machines.Models.GenericMaterialsModel import GenericMaterialsModel from cura.Machines.Models.MaterialBrandsModel import MaterialBrandsModel from cura.Machines.Models.QualityManagementModel import QualityManagementModel from cura.Machines.Models.QualitySettingsModel import QualitySettingsModel +from cura.Machines.Models.FirstStartMachineActionsModel import FirstStartMachineActionsModel from cura.Machines.Models.SettingVisibilityPresetsModel import SettingVisibilityPresetsModel @@ -215,6 +216,7 @@ class CuraApplication(QtApplication): self._machine_settings_manager = MachineSettingsManager(self) self._discovered_printer_model = DiscoveredPrintersModel(self) + self._first_start_machine_actions_model = FirstStartMachineActionsModel(self) self._welcome_pages_model = WelcomePagesModel(self) self._quality_profile_drop_down_menu_model = None @@ -751,6 +753,8 @@ class CuraApplication(QtApplication): # Initialize setting visibility presets model. self._setting_visibility_presets_model = SettingVisibilityPresetsModel(self.getPreferences(), parent = self) + self._first_start_machine_actions_model.initialize() + # Initialize Cura API self._cura_API.initialize() @@ -855,6 +859,10 @@ class CuraApplication(QtApplication): def getDiscoveredPrintersModel(self, *args) -> "DiscoveredPrintersModel": return self._discovered_printer_model + @pyqtSlot(result = QObject) + def getFirstStartMachineActionsModel(self, *args) -> "FirstStartMachineActionsModel": + return self._first_start_machine_actions_model + @pyqtSlot(result = QObject) def getSettingVisibilityPresetsModel(self, *args) -> SettingVisibilityPresetsModel: return self._setting_visibility_presets_model @@ -1026,6 +1034,7 @@ class CuraApplication(QtApplication): qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler") qmlRegisterType(SettingVisibilityPresetsModel, "Cura", 1, 0, "SettingVisibilityPresetsModel") qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel") + qmlRegisterType(FirstStartMachineActionsModel, "Cura", 1, 0, "FirstStartMachineActionsModel") qmlRegisterType(MachineNameValidator, "Cura", 1, 0, "MachineNameValidator") qmlRegisterType(UserChangesModel, "Cura", 1, 0, "UserChangesModel") qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.getInstance) diff --git a/cura/MachineActionManager.py b/cura/MachineActionManager.py index db0f7bfbff..8cfde654fb 100644 --- a/cura/MachineActionManager.py +++ b/cura/MachineActionManager.py @@ -136,7 +136,7 @@ class MachineActionManager(QObject): # action multiple times). # \param definition_id The ID of the definition that you want to get the "on added" actions for. # \returns List of actions. - @pyqtSlot(str, result="QVariantList") + @pyqtSlot(str, result = "QVariantList") def getFirstStartActions(self, definition_id: str) -> List["MachineAction"]: if definition_id in self._first_start_actions: return self._first_start_actions[definition_id] diff --git a/cura/Machines/Models/FirstStartMachineActionsModel.py b/cura/Machines/Models/FirstStartMachineActionsModel.py new file mode 100644 index 0000000000..8c2673c3a3 --- /dev/null +++ b/cura/Machines/Models/FirstStartMachineActionsModel.py @@ -0,0 +1,52 @@ +# Copyright (c) 2019 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from typing import Optional + +from PyQt5.QtCore import QObject, Qt + +from UM.Qt.ListModel import ListModel + + +# +# This model holds all first-start machine actions for the currently active machine. It has 2 roles: +# - title : the title/name of the action +# - content : the QObject of the QML content of the action +# +class FirstStartMachineActionsModel(ListModel): + + TitleRole = Qt.UserRole + 1 + ContentRole = Qt.UserRole + 2 + + def __init__(self, parent: Optional[QObject] = None) -> None: + super().__init__(parent) + + self.addRoleName(self.TitleRole, "title") + self.addRoleName(self.ContentRole, "content") + + from cura.CuraApplication import CuraApplication + self._application = CuraApplication.getInstance() + + def initialize(self) -> None: + self._application.getMachineManager().globalContainerChanged.connect(self._update) + self._update() + + def _update(self) -> None: + global_stack = self._application.getMachineManager().activeMachine + if global_stack is None: + self.setItems([]) + return + + definition_id = global_stack.definition.getId() + first_start_actions = self._application.getMachineActionManager().getFirstStartActions(definition_id) + + item_list = [] + for item in first_start_actions: + item_list.append({"title": item.label, + "content": item.displayItem, + }) + + self.setItems(item_list) + + +__all__ = ["FirstStartMachineActionsModel"]