Uranium
Application Framework
UM.PluginRegistry.PluginRegistry Class Reference

A central object to dynamically load modules as plugins. More...

Inherits QObject.

Public Member Functions

def __init__ (self, parent=None)
 
def addSupportedPluginExtension (self, extension, description)
 
def supportedPluginExtensions (self)
 
def isPluginFile (self, str plugin_path)
 
def installPlugin (self, str plugin_path)
 
bool checkRequiredPlugins (self, List[str] required_plugins)
 Check if all required plugins are loaded. More...
 
List[str] getActivePlugins (self)
 Get the list of active plugins.
 
bool isActivePlugin (self, str plugin_id)
 Ask whether plugin_name is an active plugin. More...
 
def removeActivePlugin (self, str plugin_id)
 Remove plugin from the list of active plugins. More...
 
def addActivePlugin (self, str plugin_id)
 Add a plugin to the list of active plugins. More...
 
def loadPlugin (self, str plugin_id)
 Load a single plugin by id. More...
 
def loadPlugins (self, Optional[dict] meta_data=None)
 Load all plugins matching a certain set of metadata. More...
 
PluginObject getPluginObject (self, str plugin_id)
 Get a plugin object. More...
 
Dict getMetaData (self, str plugin_id)
 Get the metadata for a certain plugin. More...
 
Optional[str] getPluginPath (self, str plugin_id)
 Get the path to a plugin. More...
 
List getAllMetaData (self, **kwargs)
 Get a list of all metadata matching a certain subset of metadata. More...
 
List getPluginLocations (self)
 Get the list of plugin locations. More...
 
def addPluginLocation (self, str location)
 Add a plugin location to the list of locations to search. More...
 
def setApplication (self, app)
 Set the central application object This is used by plugins as a central access point for other objects. More...
 
def addType (cls, str plugin_type, Callable[[Any], None] register_function)
 Add a new plugin type. More...
 
def removeType (cls, str plugin_type)
 Remove a plugin type. More...
 
"PluginRegistry" getInstance (cls)
 Get the singleton instance of this class. More...
 

Static Public Attributes

int APIVersion = 4
 
 supportedPluginExtensionsChanged = pyqtSignal()
 

Detailed Description

A central object to dynamically load modules as plugins.

The PluginRegistry class can load modules dynamically and use them as plugins. Each plugin module is expected to be a directory with and __init__ file defining a getMetaData and a register function.

For more details, see the plugins file.

Member Function Documentation

◆ addActivePlugin()

def UM.PluginRegistry.PluginRegistry.addActivePlugin (   self,
str  plugin_id 
)

Add a plugin to the list of active plugins.

Parameters
plugin_idstring The id of the plugin to add.

◆ addPluginLocation()

def UM.PluginRegistry.PluginRegistry.addPluginLocation (   self,
str  location 
)

Add a plugin location to the list of locations to search.

Parameters
locationstring The location to add to the list

◆ addType()

def UM.PluginRegistry.PluginRegistry.addType (   cls,
str  plugin_type,
Callable[[Any], None]  register_function 
)

Add a new plugin type.

This function is used to add new plugin types. Plugin types are simple string identifiers that match a certain plugin to a registration function.

The callable register_function is responsible for handling the object. Usually it will add the object to a list of objects in the relevant class. For example, the plugin type 'tool' has Controller::addTool as register function.

register_function will be called every time a plugin of type is loaded.

Parameters
typestring The name of the plugin type to add.
register_functioncallable A callable that takes an object as parameter.

◆ checkRequiredPlugins()

bool UM.PluginRegistry.PluginRegistry.checkRequiredPlugins (   self,
List[str]  required_plugins 
)

Check if all required plugins are loaded.

Parameters
required_pluginslist List of ids of plugins that ''must'' be activated.

◆ getAllMetaData()

List UM.PluginRegistry.PluginRegistry.getAllMetaData (   self,
**  kwargs 
)

Get a list of all metadata matching a certain subset of metadata.

Parameters
kwargsKeyword arguments. Possible keywords:
  • filter: dict The subset of metadata that should be matched.
  • active_only: Boolean, True when only active plugin metadata should be returned.
See also
getMetaData

◆ getInstance()

"PluginRegistry" UM.PluginRegistry.PluginRegistry.getInstance (   cls)

Get the singleton instance of this class.

Returns
instance PluginRegistry

◆ getMetaData()

Dict UM.PluginRegistry.PluginRegistry.getMetaData (   self,
str  plugin_id 
)

Get the metadata for a certain plugin.

Parameters
plugin_idstring The ID of the plugin
Returns
dict The metadata of the plugin. Can be an empty dict.
Exceptions
InvalidMetaDataErrorRaised when no metadata can be found or the metadata misses the right keys.

◆ getPluginLocations()

List UM.PluginRegistry.PluginRegistry.getPluginLocations (   self)

Get the list of plugin locations.

Returns
list The plugin locations

◆ getPluginObject()

PluginObject UM.PluginRegistry.PluginRegistry.getPluginObject (   self,
str  plugin_id 
)

Get a plugin object.

Parameters
plugin_idstring The ID of the plugin object to get.

◆ getPluginPath()

Optional[str] UM.PluginRegistry.PluginRegistry.getPluginPath (   self,
str  plugin_id 
)

Get the path to a plugin.

Parameters
plugin_idstring The ID of the plugin.
Returns
string The absolute path to the plugin or an empty string if the plugin could not be found.

◆ isActivePlugin()

bool UM.PluginRegistry.PluginRegistry.isActivePlugin (   self,
str  plugin_id 
)

Ask whether plugin_name is an active plugin.

Parameters
plugin_idstring The id of the plugin which might be active or not.

◆ loadPlugin()

def UM.PluginRegistry.PluginRegistry.loadPlugin (   self,
str  plugin_id 
)

Load a single plugin by id.

Parameters
plugin_idstring The ID of the plugin, i.e. its directory name.
Exceptions
PluginNotFoundErrorRaised when the plugin could not be found.

◆ loadPlugins()

def UM.PluginRegistry.PluginRegistry.loadPlugins (   self,
Optional[dict]   meta_data = None 
)

Load all plugins matching a certain set of metadata.

Parameters
meta_datadict The meta data that needs to be matched.
See also
loadPlugin

◆ removeActivePlugin()

def UM.PluginRegistry.PluginRegistry.removeActivePlugin (   self,
str  plugin_id 
)

Remove plugin from the list of active plugins.

Parameters
plugin_idstring The id of the plugin to remove.

◆ removeType()

def UM.PluginRegistry.PluginRegistry.removeType (   cls,
str  plugin_type 
)

Remove a plugin type.

Parameters
typestring The plugin type to remove.

◆ setApplication()

def UM.PluginRegistry.PluginRegistry.setApplication (   self,
  app 
)

Set the central application object This is used by plugins as a central access point for other objects.

Parameters
appApplication The application object to use

The documentation for this class was generated from the following file: