My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Plugins  

Featured
Updated Apr 15, 2010 by diego.sarmentero

How To Create Plugins for PyTv



Extend PluginBase

In order to make a New Plugin, it is necessary to create a new class that extend from PluginBase and this class name has to be "Plugin" (but the file or module can has a different name). For example:

file: example_plugin.py

import pluginbase

class Plugin(pluginbase.PluginBase):



Configure Your Plugin

Now that you have your class created is time to configure it. PluginBase has some different attributes that allow you to configure the behaviour of your plugin:

  • name : Specifies the name of the Plugin.
  • description : A short text that describe the Plugin.
  • icon : Specifies the path of the icon for this Plugin (relative to the Plugin file).
  • toThread : Specifies if this Plugin has to be included in the main thread of PyTv, it is not neccesary for the Plugin to has its behaviour inside a "while".
  • toShow : Specifies if this Plugin has a GUI to interact with the user.
  • authors : Specifies the name of the author/s of this Plugin.

Example:

class Plugin(pluginbase.PluginBase):
    _name = 'Example Plugin'
    _description = 'This plugin is just for example purpose'
    _icon = 'example/Goomba.png'
    _toThread = True
    _toShow = True
    
    _authors = ['Diego Sarmentero <diego.sarmentero@gmail.com>']



Plugin Base Methods

Depending on the configuration that you set for your plugin you have to re-implement some of PluginBase methods.

configure(self, db=None, notif=None, dirPlugins=None)

This methods share with the Plugin the database of PyTv, its Notification system and the path of the folder where the plugins are stored if it is needed to store some data locally or anything else.

Example:

def configure(self, d, n, dire):
    self.db = d
    self.notif = n
    self.dir = dire



show(self)

This method return the widget to be displayed to allow user interaction with the plugin. For example, if you have a file named "main.py" inside a "example" folder in the plugins folder, you can do:

Example:

import pluginbase
import example

class Plugin(pluginbase.PluginBase):

    def show(self):
        ex = example.Main()
        return ex



threadMe(self)

This method contains the piece of code that is going to be executed inside the main thread of PyTv each time that PyTv run that cycle.

Example:

def threadMe(self):
    #Do Staff
    image = self.dir + Plugin._icon
    self.notif.show_message('Welcome!', 'Example Plugin', image)

In this case this example take the path of plugins folder and concatenate it with the path of the icon from this Plugin and then show a message using PyTv Notification System with that icon included.



Where to find PyTv Plugins

To add a New Plugin go to "Plugin Manager" in the PyTv Menu, and press the "add plugin" button to see the Plugins List.

All the PyTv Plugins are stored in .config/pytv/plugins



Download the Example

The Complete Source Code of this Example can be downloaded from: Download



Screenshot of this Plugin


















Sign in to add a comment
Powered by Google Project Hosting