Welcome | Get started | Dive | Contribute | Topics | Reference | Changes | More
Introduction to plugins¶
What are plugins?¶
A plugin is a Python package that encapsulates a set of functionality designed to be used in more than one application. It can define database models, actors, actions, fixtures, template files, JavaScript snippets, dependencies, and configuration settings. None of these are mandatory.
A plugin in Lino corresponds to what Django calls an “application” (more about this controversial topic in What is an application?).
See Plugins reference for developers for a list of the plugins defined in Lino and the XL.
Usage overview¶
As an application developer you define which plugins to use by writing
a get_installed_plugins
method for your Site
.
The plugin developer defines a plugin in the __init__.py
file of the
package. Lino expects this file to define a class named Plugin
, which
inherits from the abstract base Plugin
class.
Your Plugin
class is the central description
of your plugin.
Here is a fictive example:
from lino.api import ad, _
class Plugin(ad.Plugin):
verbose_name = _("Better calendar")
extends = 'mylib.cal'
needs_plugins = ['lino_xl.lib.contacts']
def setup_main_menu(self, site, user_type, m):
m = m.add_menu(self.app_label, self.verbose_name)
m.add_action('cal.Teams')
m.add_action('cal.Agendas')
A plugin can depend on other plugins by specifying them in the
needs_plugins
attribute. This means that when you install this plugin, Lino will
automatically install these other plugins as well
A plugin can define a set of menu commands using methods like
setup_main_menu
. This is explained in
More about the application menu.
A plugin can extend another plugin by inheriting from its Plugin
class. This is explained in Plugin inheritance.
A plugin that extends another plugin can optionally extend one or multiple
database models defined by the parent plugin. If it does so, it must declare
their names in extends_models
.