aboutsummaryrefslogtreecommitdiff
path: root/doc/PLUGINS
blob: c383997ea5e5601fd3df1e058347b340e2a75309 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
enigma2 plugins
===============

Enigma2 plugins are always written in python. If you really have to call
C/C++ functions from your code, you can supply a python module with it,
implementing your functions.

Let's write a plugin. We call it "OurSmallTest", and it should be a test
plugin. Thus we choose "DemoPlugins" as a category. The category is just to
organize plugins in the filesystem.

The simplest plugin looks like the following:

Plugins/DemoPlugins/OurSmallTest/plugin.py:

"from Plugins.Plugin import PluginDescriptor

def main(session, **kwargs):
	print "Hello world!"

def Plugins(**kwargs):
 	return PluginDescriptor(
		name="Our Small Test", 
		description="plugin to test some capabilities", 
		where = PluginDescriptor.WHERE_PLUGINMENU,
		fnc=main)"

Basically, you're writing a "python module", which is called
Plugins.ourSmallTest.plugin. This corresponds to the
Plugins/ourSmallTest/plugin.py file.

This module must define a single function called "Plugins". The functions is
called for every Plugin, and should return (a list of)
PluginDescriptor-Objects. A PluginDescriptor is a simple object, holding the
Plugin's name, description, picture etc., and an entry point.

In the first line, we import that class. It's contained in a module called
Plugins.Plugin.

At the end, we define the "Plugins"-Functions. As said, it returns a
constructed PluginDescriptor-object (in fact it can return either one or a
list of descriptors, here it returns exactly one). We use keyword arguments
to supply the Plugin's information, like the name, the descripttion etc.

We also supply an entry point, called "fnc". It's set to the "main"
function, which is defined before. Our entry point is called with a number
of arguments, depending on where the plugin was launched from. In this case,
it's a "session" argument. You need the session argument if you want to do
graphical output. A session basically connects to "user". There is always
one sessions which corresponds to the main screen output, but there can also
be other sessions, which yet have to be implemented. (A possible example is a
networked remote session.) If you don't need that argument, just ignore it.

A plugin can decide where it wants to be displayed. A possible example is
the plugin menu out of the main menu. In the "where" argument to the
descriptor, you can supply one (or a list of) "WHERE_"-identifiers. We use
WHERE_PLUGINMENU. There will be other ones, for example for the blue button,
or specific other menus.

Now, if you copy this plugin in-place, it should be listed in the plugin
browser in the main menu. You can press "ok" on the plugin, and the "main"
function, which was specified as the plugin's entry point, is executed.

If you want to open a graphical screen, you might want the entry point to
look like:

def main(session):
	session.open(MyScreen)

with MyScreen being a GUI screen.

About the **kwargs:
This somewhat special syntax (in fact the name 'kwargs' is arbitrary, but
stands for "keyword arguments") collects all addition keyword arguments
(i.e. named parameters). For example. the Plugins()-call gets a "path"
parameter, and probably more in the future. You must ignore all additional
keywords which you don't need!

autostarting plugins
====================

you can configure your plugin to automatically start on enigma startup, and
end on shutdown.

you just have to use "WHERE_AUTOSTART". your entry point must (fnc) look 
like:

def autostartEntry(raeson, **kwargs):
	if reason == 0: # startup
		print "startup"
	elif reason == 1:
		print "shutdown"

Categories
==========

Currently defined categories are:

* DemoPlugins: Plugins fore pure demonstration purposes
* Extensions: User interface extensions
* SystemPlugins: Hardware specific plugins