From fd416bd5e7b0a44482090c37e9ce33ebc26eba4d Mon Sep 17 00:00:00 2001 From: sb02dev Date: Sun, 31 Aug 2025 22:16:59 +0200 Subject: [PATCH 1/2] custom plugin classes can be loaded and retreived --- PyFlow/Core/PackageBase.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/PyFlow/Core/PackageBase.py b/PyFlow/Core/PackageBase.py index 3e0f36c5..c2ec85b8 100644 --- a/PyFlow/Core/PackageBase.py +++ b/PyFlow/Core/PackageBase.py @@ -16,6 +16,7 @@ import os import importlib.util import inspect +from typing import Optional from PyFlow.Core import PinBase from PyFlow.Core import NodeBase @@ -41,12 +42,13 @@ def __init__(self): self._TOOLS = OrderedDict() self._PREFS_WIDGETS = OrderedDict() self._EXPORTERS = OrderedDict() + self._CUSTOM_PLUGIN_CLASSES = {} self._PinsInputWidgetFactory = None self._UINodesFactory = None self._UIPinsFactory = None - def analyzePackage(self, packagePath): + def analyzePackage(self, packagePath, custom_types: Optional[list[tuple[str, type]]] = None): def import_subclasses(directory, base_class): subclasses = [] for filename in os.listdir(directory): @@ -75,13 +77,21 @@ def loadPackageElements(packagePath, element, elementDict,classType): else: elementDict[subclass.__name__] = subclass + # initiate custom element store + if custom_types is None: + custom_types = [] + for typ in custom_types: + if typ[0] not in self._CUSTOM_PLUGIN_CLASSES: + self._CUSTOM_PLUGIN_CLASSES[typ[0]] = {} + custom_elements = [(typ[0], self._CUSTOM_PLUGIN_CLASSES[typ[0]], typ[1]) for typ in custom_types] # Load all elements from the package for element in [("FunctionLibraries", self._FOO_LIBS, FunctionLibraryBase), ("Nodes", self._NODES, NodeBase), ("Pins", self._PINS, PinBase), ("Tools", self._TOOLS, ToolBase), ("Exporters", self._EXPORTERS, IDataExporter), - ("PrefsWidgets", self._PREFS_WIDGETS, CategoryWidgetBase)]: + ("PrefsWidgets", self._PREFS_WIDGETS, CategoryWidgetBase)] + \ + custom_elements: loadPackageElements(packagePath, element[0], element[1], element[2]) if os.path.exists(os.path.join(packagePath, "Factories")): modPrefix = "PyFlow.Packages."+self.__class__.__name__+".Factories." @@ -164,3 +174,12 @@ def PinsInputWidgetFactory(self): :rtype: function """ return self._PinsInputWidgetFactory + + def GetCustomClasses(self, custom_type): + """Registered custom plugins by their type name. + + :rtype: dict[str, class] + """ + if custom_type not in self._CUSTOM_PLUGIN_CLASSES: + return None + return self._CUSTOM_PLUGIN_CLASSES[custom_type] \ No newline at end of file From 674713c0964ef988f1b1ef6278a9bc9268fab1ef Mon Sep 17 00:00:00 2001 From: sb02dev Date: Thu, 4 Sep 2025 22:08:29 +0200 Subject: [PATCH 2/2] get custom plugin classes: defaults to empty dict instead of None --- PyFlow/Core/PackageBase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyFlow/Core/PackageBase.py b/PyFlow/Core/PackageBase.py index c2ec85b8..9803356e 100644 --- a/PyFlow/Core/PackageBase.py +++ b/PyFlow/Core/PackageBase.py @@ -181,5 +181,5 @@ def GetCustomClasses(self, custom_type): :rtype: dict[str, class] """ if custom_type not in self._CUSTOM_PLUGIN_CLASSES: - return None + return {} return self._CUSTOM_PLUGIN_CLASSES[custom_type] \ No newline at end of file