|
Plugins
How To Create Plugins for PyTv
Extend PluginBaseIn 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 PluginNow 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:
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 MethodsDepending 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 PluginsTo 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 ExampleThe Complete Source Code of this Example can be downloaded from: Download
Screenshot of this Plugin
|