Peas.Engine¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
[ |
r/w |
The list of loaded plugins |
|
r/w/co |
Use non-global plugin loaders |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
The load-plugin signal is emitted when a plugin is being loaded. |
|
The unload-plugin signal is emitted when a plugin is being unloaded. |
Fields¶
- Inherited:
Class Details¶
- class Peas.Engine(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
The
Peas.Engine
is the object which manages the plugins.Its role is twofold:
it will fetch all the information about the available plugins from all the registered plugin directories;
it will provide you an API to load, control and unload your plugins and their extensions from within your application.
- classmethod get_default()¶
- Returns:
the existing instance of
Peas.Engine
.- Return type:
Return the existing instance of
Peas.Engine
or a subclass of it.If no
Peas.Engine
subclass has been instantiated yet, the first call of this function will return a new instance ofPeas.Engine
.Note: this function should never be used when multiple threads are using libpeas API as it is not thread-safe.
- classmethod new()¶
- Returns:
a new instance of
Peas.Engine
.- Return type:
Return a new instance of
Peas.Engine
.If no default
Peas.Engine
has been instantiated yet, the first call of this function will set the default engine as the new instance ofPeas.Engine
.
- classmethod new_with_nonglobal_loaders()¶
- Returns:
a new instance of
Peas.Engine
that uses non-global loaders.- Return type:
Return a new instance of
Peas.Engine
which will use non-global plugin loaders instead of the default global ones.This allows multiple threads to each have a
Peas.Engine
and be used without internal locking.Note: due to CPython’s GIL the python and python3 plugin loaders are always global.
- add_search_path(module_dir, data_dir)¶
- Parameters:
Appends a search path to the list of paths where to look for plugins.
A so-called “search path” actually consists of both a module directory (where the shared libraries or language modules lie) and a data directory (where the plugin data is).
The plugin will be able to use a correct data dir depending on where it is installed, hence allowing to keep the plugin agnostic when it comes to installation location: the same plugin can be installed either in the system path or in the user’s home directory, without taking other special care than using [method`PluginInfo`.get_data_dir] when looking for its data files.
If data_dir is
None
, then it is set to the same value as module_dir.
- create_extension(info, extension_type, prop_names, prop_values)¶
- Parameters:
info (
Peas.PluginInfo
) – A loadedPeas.PluginInfo
.extension_type (
GObject.GType
) – The implemented extensionGObject.GType
.prop_names ([
str
]) – an array of property names.prop_values ([
GObject.Value
]) – an array of property values.
- Returns:
a new instance of
GObject.Object
which meets the prerequisites of extension_type, orNone
.- Return type:
If the plugin identified by info implements the extension_type, then this function will return a new instance of this implementation.
See [method`Engine`.create_extension] for more information.
- dup_loaded_plugins()¶
-
Returns the list of the names of all the loaded plugins.
If there is no plugin currently loaded, it will return an array containing a single
None
element.Please note that the returned array is a newly allocated one: you will need to free it using [func`GLib`.strfreev].
- enable_loader(loader_name)¶
- Parameters:
loader_name (
str
) – The name of the loader to enable.
Enable a loader, enables a loader for plugins.
The C plugin loader is always enabled. The other plugin loaders are: gjs, lua5.1, python and python3.
For instance, the following code will enable Python 2 plugins to be loaded:
``c peas_engine_enable_loader (engine, “python”); ``
Note: plugin loaders used to be shared across ``PeasEngine``s so enabling a loader on one
Peas.Engine
would enable it on allPeas.Engines
. This behavior has been kept to avoid breaking applications, however a warning has been added to help applications transition.
- garbage_collect()¶
Triggers garbage collection on all the loaders currently owned by the
Peas.Engine
.This can be used to force the loaders to destroy managed objects that still hold references to objects that are about to disappear.
- get_plugin_info(plugin_name)¶
- Parameters:
plugin_name (
str
) – A plugin name.- Returns:
the
Peas.PluginInfo
corresponding with a given plugin module name.- Return type:
Gets the [class`PluginInfo`] corresponding with plugin_name, or
None
if plugin_name was not found.
- load_plugin(info)¶
- Parameters:
info (
Peas.PluginInfo
) – APeas.PluginInfo
.- Returns:
whether the plugin has been successfully loaded.
- Return type:
Loads the plugin corresponding to info if it’s not currently loaded.
Emits the [signal`Engine`:py:func:::load-plugin<Peas.Engine.signals.load_plugin>] signal; loading the plugin actually occurs in the default signal handler.
- provides_extension(info, extension_type)¶
- Parameters:
info (
Peas.PluginInfo
) – APeas.PluginInfo
.extension_type (
GObject.GType
) – The extensionGObject.GType
.
- Returns:
if info provides an extension for extension_type.
- Return type:
Returns if info provides an extension for extension_type.
If the info is not loaded than
False
will always be returned.
- rescan_plugins()¶
Rescan all the registered directories to find new or updated plugins.
Calling this function will make the newly installed plugin infos be loaded by the engine, so the new plugins can be used without restarting the application.
- set_loaded_plugins(plugin_names)¶
-
Sets the list of loaded plugins for self.
When this function is called, the
Peas.Engine
will load all the plugins whose names are in plugin_names, and ensures all other active plugins are unloaded.If plugin_names is
None
, all plugins will be unloaded.
- unload_plugin(info)¶
- Parameters:
info (
Peas.PluginInfo
) – APeas.PluginInfo
.- Returns:
whether the plugin has been successfully unloaded.
- Return type:
Unloads the plugin corresponding to info.
Emits the [signal`Engine`:py:func:::unload-plugin<Peas.Engine.signals.unload_plugin>] signal; unloading the plugin actually occurs in the default signal handler.
Signal Details¶
- Peas.Engine.signals.load_plugin(engine, info)¶
- Signal Name:
load-plugin
- Flags:
- Parameters:
engine (
Peas.Engine
) – The object which received the signalinfo (
Peas.PluginInfo
) – APeas.PluginInfo
.
The load-plugin signal is emitted when a plugin is being loaded.
The plugin is being loaded in the default handler. Hence, if you want to perform some action before the plugin is loaded, you should use [func`GObject`.signal_connect], but if you want to perform some action *after* the plugin is loaded (the most common case), you should use [func`GObject`.signal_connect_after].
- Peas.Engine.signals.unload_plugin(engine, info)¶
- Signal Name:
unload-plugin
- Flags:
- Parameters:
engine (
Peas.Engine
) – The object which received the signalinfo (
Peas.PluginInfo
) – APeas.PluginInfo
.
The unload-plugin signal is emitted when a plugin is being unloaded.
The plugin is being unloaded in the default handler. Hence, if you want to perform some action before the plugin is unloaded (the most common case), you should use [func`GObject`.signal_connect], but if you want to perform some action after the plugin is unloaded (the most common case), you should use [func`GObject`.signal_connect_after].
Property Details¶
- Peas.Engine.props.loaded_plugins¶
-
The list of loaded plugins.
This will be modified when [method`Engine`.load_plugin] or [method`Engine`.unload_plugin] is called.
This can be used with [class`Gio`.Settings] to save the loaded plugins by binding to this property after instantiating the engine by doing:
- ``c
- g_settings_bind (gsettings_object,
LOADED_PLUGINS_KEY, engine, “loaded-plugins”, G_SETTINGS_BIND_DEFAULT);
Note: notify will not be called when the engine is being destroyed.