pycrossword  0.3
Pure-Python implementation of a crossword puzzle generator and editor
Public Member Functions | Public Attributes | Private Member Functions | List of all members
pycross.utils.pluginmanager.PxPluginManager Class Reference

Reimplemented PluginManager class to enable plugins' access to the main window. More...

Inheritance diagram for pycross.utils.pluginmanager.PxPluginManager:

Public Member Functions

def __init__ (self, mainwindow, categories_filter=None, directories_list=None, plugin_info_ext=None, plugin_locator=None)
 Adds 'mainwindow' to the PluginManager default constructor. More...
 
def instanciateElementWithImportInfo (self, element, element_name, plugin_module_name, candidate_filepath)
 Reimplemented method that creates plugin objects passing 'self' in constructor. More...
 
def call_plugin_method (self, plugin_name, plugin_category, method_name, *args, **kwargs)
 Calls a given method from a given plugin by its name. More...
 
def plugin_from_settings (self, settings, plugin_name, plugin_category)
 Returns the plugin object corresponding to a plugin info record in the global settings. More...
 
def set_plugin_active (self, plugin_name, plugin_category, active=True)
 Sets a plugin's active state to True or False. More...
 
def update_global_settings (self, forced_update=False)
 Updates the custom plugin settings in guisettings::CWSettings::settings. More...
 
def get_plugins_of_category (self, category, active_only=True)
 Gets the list of plugins for a given category respecting their order. More...
 
def get_plugin_methods (self, category, method_name)
 Returns the list of methods with a given name from all active plugins. More...
 
def configure_plugins (self)
 Activates or deactivates loaded plugins according to the global settings. More...
 

Public Attributes

 mainwin
 PxAPI wrapper instance for app main window self.__mainwindow = mainwindow More...
 

Private Member Functions

def _plugin_info_to_dic (self, plugin)
 Makes a dictionary of plugin info given a plugin object. More...
 

Detailed Description

Reimplemented PluginManager class to enable plugins' access to the main window.

Constructor & Destructor Documentation

◆ __init__()

def pycross.utils.pluginmanager.PxPluginManager.__init__ (   self,
  mainwindow,
  categories_filter = None,
  directories_list = None,
  plugin_info_ext = None,
  plugin_locator = None 
)

Adds 'mainwindow' to the PluginManager default constructor.

Parameters
mainwindowpycross.gui.MainWindow pointer to the app main window
categories_filterdict categories of plugins to be looked for as well as the way to recognise them
directories_listiterable list of search directories for plugins (relative or absolute paths)
plugin_info_extstr extension of plugin info files (without dot)
plugin_locatoryapsy::IPluginLocator::IPluginLocator plugin locator instance

Member Function Documentation

◆ _plugin_info_to_dic()

def pycross.utils.pluginmanager.PxPluginManager._plugin_info_to_dic (   self,
  plugin 
)
private

Makes a dictionary of plugin info given a plugin object.

The resulting dict is formatted in the same way as in the global settings, corresponding to a custom plugin record in a given category.

Parameters
pluginyapsy::PluginInfo::PluginInfo the plugin object
Returns
dict plugin info record

◆ call_plugin_method()

def pycross.utils.pluginmanager.PxPluginManager.call_plugin_method (   self,
  plugin_name,
  plugin_category,
  method_name,
args,
**  kwargs 
)

Calls a given method from a given plugin by its name.

Parameters
plugin_namestr name of plugin
plugin_categorystr name of plugin category
method_namestr name of method to call
*argspositional args positional args passed to the method
*kwargskeyword args keyword args passed to the method
Returns
whatever the called method returns
Exceptions
<tt>Exception</tt>failure to locate plugin or plugin inactive or failure to locate method

◆ configure_plugins()

def pycross.utils.pluginmanager.PxPluginManager.configure_plugins (   self)

Activates or deactivates loaded plugins according to the global settings.

◆ get_plugin_methods()

def pycross.utils.pluginmanager.PxPluginManager.get_plugin_methods (   self,
  category,
  method_name 
)

Returns the list of methods with a given name from all active plugins.

The methods are returned from all active plugins in a given category, while respecting the plugin order in the global settings. That is, the resulting list of methods will be ordered by the plugin order in the settings.

Parameters
categorystr plugin category name
method_namestr method name to look for
Returns
list list of methods, each being a callable bound object

◆ get_plugins_of_category()

def pycross.utils.pluginmanager.PxPluginManager.get_plugins_of_category (   self,
  category,
  active_only = True 
)

Gets the list of plugins for a given category respecting their order.

This method is added since the inherited getPluginsOfCategory method of PluginManager does not respect the order of the plugins (it knows nothing about the order). The plugin order is taken from the global settings (guisettings::CWSettings::settings).

Parameters
categorystr plugin category name
active_onlybool only list active plugins (default)
Returns
list list of plugins of type yapsy::PluginInfo::PluginInfo

◆ instanciateElementWithImportInfo()

def pycross.utils.pluginmanager.PxPluginManager.instanciateElementWithImportInfo (   self,
  element,
  element_name,
  plugin_module_name,
  candidate_filepath 
)

Reimplemented method that creates plugin objects passing 'self' in constructor.

See params in yapsy docs.

◆ plugin_from_settings()

def pycross.utils.pluginmanager.PxPluginManager.plugin_from_settings (   self,
  settings,
  plugin_name,
  plugin_category 
)

Returns the plugin object corresponding to a plugin info record in the global settings.

Parameters
settingsdict pointer to global settings ['plugins']['custom']
plugin_namestr name of plugin
plugin_categorystr name of plugin category
Returns
yapsy::PluginInfo::PluginInfo plugin object or None on failure

◆ set_plugin_active()

def pycross.utils.pluginmanager.PxPluginManager.set_plugin_active (   self,
  plugin_name,
  plugin_category,
  active = True 
)

Sets a plugin's active state to True or False.

Parameters
plugin_namestr name of plugin
plugin_categorystr name of plugin category
activebool active state to set

◆ update_global_settings()

def pycross.utils.pluginmanager.PxPluginManager.update_global_settings (   self,
  forced_update = False 
)

Updates the custom plugin settings in guisettings::CWSettings::settings.

The function will first look for plugins contained in the current settings and update their data from the existing plugins collected by the plugin manager. Plugins that are found in settings but not in the plugin manager will be removed from settings. Then finally plugins collected by the manager but not contained in the settings will be appended to the settings, in their respective categories.

Parameters
forced_updatebool if True, all current plugin settings will be cleared and plugins will be added anew from the plugin manager (default = False)

Member Data Documentation

◆ mainwin

pycross.utils.pluginmanager.PxPluginManager.mainwin

PxAPI wrapper instance for app main window self.__mainwindow = mainwindow


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