From 81602e9ccd71117652dcb1ff6dc8be3103144914 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 21 Jun 2016 12:47:34 +0200 Subject: [PATCH] Machine action can now create displayItems CURA-1385 --- cura/MachineAction.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cura/MachineAction.py b/cura/MachineAction.py index 67c4566f53..3958d62a70 100644 --- a/cura/MachineAction.py +++ b/cura/MachineAction.py @@ -1,8 +1,15 @@ # 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 +from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal, QUrl +from PyQt5.QtQml import QQmlComponent, QQmlContext + from UM.PluginObject import PluginObject +from UM.PluginRegistry import PluginRegistry + +from UM.Application import Application + +import os class MachineAction(QObject, PluginObject): @@ -10,6 +17,11 @@ class MachineAction(QObject, PluginObject): super().__init__() self._key = key self._label = label + self._qml_url = "" + + self._component = None + self._context = None + self._view = None labelChanged = pyqtSignal() @@ -30,4 +42,19 @@ class MachineAction(QObject, PluginObject): self._execute() def _execute(self): - raise NotImplementedError("Execute() must be implemented") \ No newline at end of file + raise NotImplementedError("Execute() must be implemented") + + def _createViewFromQML(self): + path = QUrl.fromLocalFile( + os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), self._qml_url)) + self._component = QQmlComponent(Application.getInstance()._engine, path) + self._context = QQmlContext(Application.getInstance()._engine.rootContext()) + self._context.setContextProperty("manager", self) + self._view = self._component.create(self._context) + + @pyqtProperty(QObject, constant = True) + def displayItem(self): + if not self._component: + self._createViewFromQML() + + return self._view \ No newline at end of file