Classes:Plugin

From OpenLP

Jump to: navigation, search
  1. # -*- coding: utf-8 -*-
  2. # vim: autoindent shiftwidth=4 expandtab textwidth=80
  3. """
  4. OpenLP - Open Source Lyrics Projection
  5. Copyright (c) 2008 Raoul Snyman
  6. Portions copyright (c) 2008 Martin Thompson, Tim Bentley,
  7.  
  8. This program is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free Software
  10. Foundation; version 2 of the License.
  11.  
  12. This program is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  14. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License along with
  17. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  18. Place, Suite 330, Boston, MA 02111-1307 USA
  19. """
  20.  
  21. import logging
  22.  
  23. from openlp.core.lib import PluginConfig
  24.  
  25. class Plugin(object):
  26.     """
  27.     Base class for openlp plugins to inherit from.
  28.  
  29.     Basic attributes are:
  30.     * name
  31.         The name that should appear in the plugins list.
  32.     * version
  33.         The version number of this iteration of the plugin.
  34.     * icon
  35.         An instance of QIcon, which holds an icon for this plugin.
  36.     * config
  37.         An instance of PluginConfig, which allows plugins to read and write to
  38.         openlp.org's configuration. This is pre-instantiated.
  39.     * log
  40.         A log object used to log debugging messages. This is pre-instantiated.
  41.  
  42.     Hook functions:
  43.     * check_pre_conditions()
  44.         Provides the Plugin with a handle to check if it can be loaded.
  45.     * get_media_manager_item()
  46.         Returns an instance of MediaManagerItem to be used in the Media Manager.
  47.     * add_import_menu_item(import_menu)
  48.         Returns an item for the Import menu.
  49.     * add_export_menu_item(export_menu)
  50.         Returns an item for the Export menu.
  51.     * get_settings_tab()
  52.         Returns an instance of SettingsTab to be used in the Settings dialog.
  53.     * add_to_menu(menubar)
  54.         A method to add a menu item to anywhere in the menu, given the menu bar.
  55.     * handle_event(event)
  56.         A method use to handle events, given an Event object.
  57.     * about()
  58.         Used in the plugin manager, when a person clicks on the 'About' button.
  59.     * save(data)
  60.         A method to convert the plugin's data to a string to be stored in the
  61.         Service file.
  62.     * load(string)
  63.         A method to convert the string from a Service file into the plugin's
  64.         own data format.
  65.     * render(theme, screen_number)
  66.         A method used to render something to the screen, given the current theme
  67.         and screen number.
  68.     """
  69.  
  70.     def __init__(self, name=None, version=None):
  71.         """
  72.         This is the constructor for the plugin object. This provides an easy
  73.         way for descendent plugins to populate common data. This method *must*
  74.         be overridden, like so:
  75.         class MyPlugin(Plugin):
  76.             def __init__(self):
  77.                 Plugin.__init(self, 'MyPlugin', '0.1')
  78.                 ...
  79.         """
  80.         if name is not None:
  81.             self.name = name
  82.         else:
  83.             self.name = 'Plugin'
  84.         if version is not None:
  85.             self.version = version
  86.         self.icon = None
  87.         self.config = PluginConfig(self.name)
  88.         self.weight = 0
  89.         # Set up logging
  90.         self.log = logging.getLogger(self.name)
  91.  
  92.     def check_pre_conditions(self):
  93.         """
  94.         Provides the Plugin with a handle to check if it can be loaded.
  95.         Returns True or False.
  96.         """
  97.         return True
  98.  
  99.     def get_media_manager_item(self):
  100.         """
  101.         Construct a MediaManagerItem object with all the buttons and things you
  102.         need, and return it for integration into openlp.org.
  103.         """
  104.         pass
  105.  
  106.     def add_import_menu_item(self, import_menu):
  107.         """
  108.         Create a menu item and add it to the "Import" menu.
  109.         """
  110.         pass
  111.  
  112.     def add_export_menu_item(self, export_menu):
  113.         """
  114.         Create a menu item and add it to the "Export" menu.
  115.         """
  116.         pass
  117.  
  118.     def get_settings_tab(self):
  119.         """
  120.         Create a menu item and add it to the "Import" menu.
  121.         """
  122.         pass
  123.  
  124.     def add_to_menu(self, menubar):
  125.         """
  126.         Add menu items to the menu, given the menubar.
  127.         """
  128.         pass
  129.  
  130.     def handle_event(self, event):
  131.         """
  132.         Handle the event contained in the event object.
  133.         """
  134.         pass
  135.  
  136.     def about(self):
  137.         """
  138.         Show a dialog when the user clicks on the 'About' button in the plugin
  139.         manager.
  140.         """
  141.         pass
  142.  
  143.     def save(self, data):
  144.         """
  145.         Service item data is passed to this function, which should return a
  146.         string which can be written to the service file.
  147.         """
  148.         pass
  149.  
  150.     def load(self, string):
  151.         """
  152.         A string from the service file is passed in. This function parses and
  153.         sets up the internals of the plugin.
  154.         """
  155.         pass
  156.  
  157.     def render(self, theme, screen=None):
  158.         """
  159.         Render the screenth screenful of data using theme settings in theme.
  160.         """
  161.         pass
  162.  
  163.     def initalise(self):
  164.         """
  165.         Called by the plugin Manager to initialise anything it needs.
  166.         """
  167.         pass
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox