From ac012e8f0992c35691b18b013cb902b71dbc46de Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Wed, 27 Feb 2019 11:51:28 +0100 Subject: [PATCH] WIP: Add Welcome Page and use CTRL+Alt+D to trigger --- cura/CuraApplication.py | 12 ++++++++++ cura/UI/WelcomePagesModel.py | 45 ++++++++++++++++++++++++++++++++++++ cura/UI/__init__.py | 0 resources/qml/Actions.qml | 9 ++++++++ resources/qml/Cura.qml | 25 ++++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 cura/UI/WelcomePagesModel.py create mode 100644 cura/UI/__init__.py diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 4d3d2434ff..5d85763fea 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -59,6 +59,8 @@ from cura.Scene.CuraSceneNode import CuraSceneNode from cura.Scene.CuraSceneController import CuraSceneController +from cura.UI.WelcomePagesModel import WelcomePagesModel + from UM.Settings.SettingDefinition import SettingDefinition, DefinitionPropertyType from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.SettingFunction import SettingFunction @@ -208,6 +210,8 @@ class CuraApplication(QtApplication): self._cura_scene_controller = None self._machine_error_checker = None + self._welcome_pages_model = WelcomePagesModel(self) + self._quality_profile_drop_down_menu_model = None self._custom_quality_profile_drop_down_menu_model = None self._cura_API = CuraAPI(self) @@ -745,6 +749,8 @@ class CuraApplication(QtApplication): # Initialize Cura API self._cura_API.initialize() + self._welcome_pages_model.initialize() + # Detect in which mode to run and execute that mode if self._is_headless: self.runWithoutGUI() @@ -843,6 +849,10 @@ class CuraApplication(QtApplication): def getSettingVisibilityPresetsModel(self, *args) -> SettingVisibilityPresetsModel: return self._setting_visibility_presets_model + @pyqtSlot(result = QObject) + def getWelcomePagesModel(self, *args) -> "WelcomePagesModel": + return self._welcome_pages_model + def getCuraFormulaFunctions(self, *args) -> "CuraFormulaFunctions": if self._cura_formula_functions is None: self._cura_formula_functions = CuraFormulaFunctions(self) @@ -975,6 +985,8 @@ class CuraApplication(QtApplication): qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 0, "SimpleModeSettingsManager", self.getSimpleModeSettingsManager) qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager) + qmlRegisterType(WelcomePagesModel, "Cura", 1, 0, "WelcomePageModel") + qmlRegisterType(NetworkMJPGImage, "Cura", 1, 0, "NetworkMJPGImage") qmlRegisterSingletonType(ObjectsModel, "Cura", 1, 0, "ObjectsModel", self.getObjectsModel) diff --git a/cura/UI/WelcomePagesModel.py b/cura/UI/WelcomePagesModel.py new file mode 100644 index 0000000000..6365ed1c0b --- /dev/null +++ b/cura/UI/WelcomePagesModel.py @@ -0,0 +1,45 @@ + + +import os +from typing import TYPE_CHECKING, Optional + +from PyQt5.QtCore import QUrl, Qt + +from UM.Qt.ListModel import ListModel +from UM.Resources import Resources + +if TYPE_CHECKING: + from PyQt5.QtCore import QObject + + +class WelcomePagesModel(ListModel): + + IdRole = Qt.UserRole + 1 # Page ID + PageUrlRole = Qt.UserRole + 2 # URL to the page's QML file + NextPageIdRole = Qt.UserRole + 3 # The next page ID it should go to + + def __init__(self, parent: Optional["QObject"] = None) -> None: + super().__init__(parent) + + self.addRoleName(self.IdRole, "id") + self.addRoleName(self.PageUrlRole, "page_url") + self.addRoleName(self.NextPageIdRole, "next_page_id") + + self._pages = [] + + def initialize(self) -> None: + from cura.CuraApplication import CuraApplication + # Add default welcome pages + self._pages.append({"id": "welcome", + "page_url": QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, + os.path.join("WelcomePages", "WelcomeContent.qml"))), + } + ) + + self.setItems(self._pages) + + def addPage(self): + pass + + +__all__ = ["WelcomePagesModel"] diff --git a/cura/UI/__init__.py b/cura/UI/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/resources/qml/Actions.qml b/resources/qml/Actions.qml index 368f1aa0cf..206f99af00 100644 --- a/resources/qml/Actions.qml +++ b/resources/qml/Actions.qml @@ -69,10 +69,19 @@ Item property alias browsePackages: browsePackagesAction + property alias showOnBoarding: showOnBoarding + UM.I18nCatalog{id: catalog; name: "cura"} Controls2.Action + { + id: showOnBoarding + text: catalog.i18nc("@action:inmenu", "Show On boarding") + shortcut: "Ctrl+Alt+D" + } + + Action { id: showTroubleShootingAction onTriggered: Qt.openUrlExternally("https://ultimaker.com/en/troubleshooting") diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index 44ff31ef31..25678a34ab 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -14,6 +14,7 @@ import Cura 1.1 as Cura import "Dialogs" import "Menus" import "MainWindow" +import "WelcomePages" UM.MainWindow { @@ -41,6 +42,30 @@ UM.MainWindow tooltip.hide(); } + WelcomeDialog + { + id: welcomeDialog + visible: false + } + + Rectangle + { + id: greyOutBackground + anchors.fill: parent + visible: welcomeDialog.visible + color: "black" + opacity: 0.7 + z: stageMenu.z + 1 + } + + Connections + { + target: Cura.Actions.showOnBoarding + onTriggered: + { + welcomeDialog.show() + } + } Component.onCompleted: {