From cd8bc3b60d79125de0afc3592a2b5351bfc4ff59 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 30 Jun 2016 01:53:48 +0200 Subject: [PATCH] Introduce a ContainerManager class to handle container actions like duplicate Because MachineManager is getting rather large Contributes to CURA-342 --- cura/ContainerManager.py | 34 ++++++++++++++++++++++++++++++++++ cura/CuraApplication.py | 3 +++ 2 files changed, 37 insertions(+) create mode 100644 cura/ContainerManager.py diff --git a/cura/ContainerManager.py b/cura/ContainerManager.py new file mode 100644 index 0000000000..9639dd1064 --- /dev/null +++ b/cura/ContainerManager.py @@ -0,0 +1,34 @@ +# Copyright (c) 2016 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal + +import UM.Settings + +from UM.i18n import i18nCatalog +catalog = i18nCatalog("cura") + +class ContainerManager(QObject): + def __init__(self, parent = None): + super().__init__(parent) + + @pyqtSlot(str) + def duplicateContainer(self, container_id): + containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id) + if not containers: + return + + new_name = UM.Settings.ContainerRegistry.getInstance().uniqueName(containers[0].getName()) + new_material = containers[0].duplicate(new_name) + UM.Settings.ContainerRegistry.getInstance().addContainer(new_material) + + @pyqtSlot(str, str) + def renameContainer(self, container_id, new_name): + pass + + @pyqtSlot(str) + def removeContainer(self, container_id): + pass + +def createContainerManager(engine, js_engine): + return ContainerManager() diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 9970f0efce..420ae276e9 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -45,6 +45,7 @@ from . import CuraSplashScreen from . import MachineManagerModel from . import ContainerSettingsModel from . import MachineActionManager +from . import ContainerManager import cura.Settings @@ -428,6 +429,8 @@ class CuraApplication(QtApplication): qmlRegisterType(ContainerSettingsModel.ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel") qmlRegisterType(cura.Settings.MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler") + qmlRegisterSingletonType(ContainerManager.ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager) + qmlRegisterSingletonType(QUrl.fromLocalFile(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")), "Cura", 1, 0, "Actions") engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.ExtruderManager.getInstance())