From f2b4cbe182fe01fdd974958f28e35f37952a1b28 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Mon, 4 Dec 2017 11:37:49 +0100 Subject: [PATCH] Register sidebar controller in application, start with default sidebar view --- cura/CuraApplication.py | 19 +++++++++++++++++++ cura/Settings/SettingsSidebarView.py | 10 ++++++++++ cura/Sidebar/SidebarViewModel.py | 16 ++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 cura/Settings/SettingsSidebarView.py create mode 100644 cura/Sidebar/SidebarViewModel.py diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 9427e15552..7f8fef05ad 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -33,9 +33,11 @@ from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation from UM.Operations.GroupedOperation import GroupedOperation from UM.Operations.SetTransformOperation import SetTransformOperation from cura.Arrange import Arrange +from cura.Settings.SettingsSidebarView import SettingsSidebarView from cura.ShapeArray import ShapeArray from cura.ConvexHullDecorator import ConvexHullDecorator from cura.SetParentOperation import SetParentOperation +from cura.Sidebar.SidebarController import SidebarController from cura.SliceableObjectDecorator import SliceableObjectDecorator from cura.BlockSlicingDecorator import BlockSlicingDecorator @@ -204,6 +206,14 @@ class CuraApplication(QtApplication): self._setting_inheritance_manager = None self._simple_mode_settings_manager = None + ## As of Cura 3.2, the sidebar is controlled by a controller. + # This functionality was added to allow plugins registering custom sidebar views. + self._sidebar_controller = SidebarController(self) + + ## Register the default settings sidebar manually + settings_sidebar_view = SettingsSidebarView() + self._sidebar_controller.addSidebarView(settings_sidebar_view) + self._additional_components = {} # Components to add to certain areas in the interface super().__init__(name = "cura", version = CuraVersion, buildtype = CuraBuildType, @@ -775,6 +785,14 @@ class CuraApplication(QtApplication): def getPrintInformation(self): return self._print_information + ## Get the SidebarController of this application. + # A sidebar controller is created if it wasn't yet. + # \returns SidebarControllers \type{SidebarController} + def getSidebarController(self) -> SidebarController: + if self._sidebar_controller is None: + self._sidebar_controller = SidebarController(self) + return self._sidebar_controller + ## Registers objects for the QML engine to use. # # \param engine The QML engine. @@ -800,6 +818,7 @@ class CuraApplication(QtApplication): qmlRegisterType(MachineNameValidator, "Cura", 1, 0, "MachineNameValidator") qmlRegisterType(UserChangesModel, "Cura", 1, 1, "UserChangesModel") qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager) + qmlRegisterSingletonType(SidebarController, "Cura", 1, 0, "SidebarController", self.getSidebarController) # As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work. actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml"))) diff --git a/cura/Settings/SettingsSidebarView.py b/cura/Settings/SettingsSidebarView.py new file mode 100644 index 0000000000..813f3fef2f --- /dev/null +++ b/cura/Settings/SettingsSidebarView.py @@ -0,0 +1,10 @@ +# Copyright (c) 2017 Ultimaker B.V. + +from PyQt5.QtCore import QObject + +from cura.Sidebar.SidebarView import SidebarView + +class SettingsSidebarView(QObject, SidebarView): + + def __init__(self): + super().__init__() diff --git a/cura/Sidebar/SidebarViewModel.py b/cura/Sidebar/SidebarViewModel.py new file mode 100644 index 0000000000..49e64060bc --- /dev/null +++ b/cura/Sidebar/SidebarViewModel.py @@ -0,0 +1,16 @@ +# Copyright (c) 2017 Ultimaker B.V. +from PyQt5.QtCore import Qt +from UM.Qt.ListModel import ListModel +from UM.Application import Application +from UM.PluginRegistry import PluginRegistry + +## The SidebarViewModel is the default sidebar view in Cura with all the print settings and print button. +class SidebarViewModel(ListModel): + IdRole = Qt.UserRole + 1 + NameRole = Qt.UserRole + 2 + ActiveRole = Qt.UserRole + 3 + + def __init__(self, parent = None): + super().__init__(parent) + + \ No newline at end of file