Implement switching sidebar views

This commit is contained in:
ChrisTerBeke 2017-12-04 19:37:03 +01:00
parent 3c863fc388
commit caf56587fe
8 changed files with 121 additions and 72 deletions

View file

@ -1,6 +1,7 @@
# Copyright (c) 2017 Ultimaker B.V.
from PyQt5.QtCore import QUrl
import os.path
from UM.Application import Application
from UM.Logger import Logger
from UM.PluginObject import PluginObject
from UM.PluginRegistry import PluginRegistry
@ -14,11 +15,21 @@ class SidebarView(PluginObject):
super().__init__()
self._view = None
def getComponent(self):
if not self._view:
self.createView()
return self._view
def createView(self):
component_path = self.getComponentPath()
self._view = Application.getInstance().createQmlComponent(component_path, {"manager": self})
## Get the path to the component QML file as QUrl
def getComponentPath(self):
try:
plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
sidebar_component_file_path = PluginRegistry.getInstance().getMetaData(self.getPluginId())["sidebar_view"]["sidebar_component"]
return QUrl.fromLocalFile(sidebar_component_file_path)
return os.path.join(plugin_path, sidebar_component_file_path)
except KeyError:
Logger.log("w", "Could not find sidebar component QML file for %s", self.getPluginId())
return QUrl()
return ""