Skip to content

Commit

Permalink
Ensure that a plugin can register multiple similar types
Browse files Browse the repository at this point in the history
So instead of giving a single metadata dict, you would need to provide a list
Note that this list must be in the same order as the objects!
  • Loading branch information
nallath committed Nov 1, 2019
1 parent 0b024d1 commit fb8bde4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions UM/PluginObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ class PluginObject:
def __init__(self) -> None:
self._plugin_id = None # type: Optional[str]
self._version = None # type: Optional[str]
self._metadata = {}

def setPluginId(self, plugin_id: str) -> None:
self._plugin_id = plugin_id

def setMetaData(self, metadata):
self._metadata = metadata

def getMetaData(self):
return self._metadata

def getPluginId(self) -> str:
if not self._plugin_id:
raise ValueError("The plugin ID needs to be set before the plugin can be used")
Expand Down
8 changes: 7 additions & 1 deletion UM/PluginRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,17 @@ def loadPlugin(self, plugin_id: str) -> None:
return
for plugin_type, plugin_object in to_register.items():
if type(plugin_object) == list:
for nested_plugin_object in plugin_object:
for metadata_index, nested_plugin_object in enumerate(plugin_object):
nested_plugin_object.setVersion(self._metadata[plugin_id].get("plugin", {}).get("version"))
all_metadata = self._metadata[plugin_id].get(plugin_type, [])
try:
nested_plugin_object.setMetaData(all_metadata[metadata_index])
except IndexError:
nested_plugin_object.setMetaData({})
self._addPluginObject(nested_plugin_object, plugin_id, plugin_type)
else:
plugin_object.setVersion(self._metadata[plugin_id].get("plugin", {}).get("version"))
plugin_object.setMetaData(self._metadata[plugin_id].get(plugin_type, {}))
self._addPluginObject(plugin_object, plugin_id, plugin_type)

self._plugins[plugin_id] = plugin
Expand Down
3 changes: 1 addition & 2 deletions UM/Qt/Bindings/ActiveToolProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ def valid(self):
def activeToolPanel(self):
if not self._active_tool:
return QUrl()

try:
panel_file = PluginRegistry.getInstance().getMetaData(self._active_tool.getPluginId())["tool"]["tool_panel"]
panel_file = self._active_tool.getMetaData()["tool_panel"]
except KeyError:
return QUrl()

Expand Down
5 changes: 3 additions & 2 deletions UM/Qt/Bindings/ToolModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def _onToolsChanged(self):

tools = self._controller.getAllTools()
for name in tools:
tool_meta_data = PluginRegistry.getInstance().getMetaData(name).get("tool", {})
location = PluginRegistry.getInstance().getMetaData(name).get("location", "")
plugin_id = tools[name].getPluginId()
tool_meta_data = tools[name].getMetaData()
location = PluginRegistry.getInstance().getMetaData(plugin_id).get("location", "")

# Skip tools that are marked as not visible
if "visible" in tool_meta_data and not tool_meta_data["visible"]:
Expand Down

0 comments on commit fb8bde4

Please sign in to comment.