Transcript
The enigma2-plugin Tutorial
by emanuel@i-have-a-dreambox.com
english rel. 1* date: 14.02.2010
(sorry for my bad english)
This plugin tutorial is for advanced users. If vou've got problems with the following list below, take a look at our >> gp-wiki << .
If you haven't made a python tutorial yet, take a look at >>that<<.
What do you need:
1. Unix Editor (for exmpl. GNU notepad++.exe (Mswin)2. Ftp connetion to Dreambox3. a Terminal (telnet/ssh) to Dreambox4. Basic knowledge in Dreambox BusyBox5. Basic knowledge in Python (use your Dreambox to test)6. install Ihad plugin Tutorial, Tutorial stored at:
/usr/lib/enigma2/python/Plugins/IhadTutorial/7. usr/lib/enigma2/python/Plugins/IhadTutorial/doc/doc_enigma2 (read it also!)
(original ones from enigma2 CVS)8. have fun
Please no questions about basic python knowledge, this is an enigma2 plugin tutorial!
1
Table of contents:
"Our Small Test“ - pure print example without Gui (OSD) p. 3-5
lesson "01 Hallo World" – simple window (Screen) p. 6-7
lesson "02 Hallo World Message" – Screen with message p. 8-9
lesson "03 Call My Msg" - Screen with message Yes/No p. 10-11
lesson "04 My Menulist" – Screen with menulist p. 12-14
lesson "05 My Shell Prombt" – Screen with menulist and shell p. 15-17commands, outpute on Screen Console
lesson "06 Message Input" – Screens with character input, output p. 18-20
lesson "07 View a picture" - Screen with picture p. 21-23
lesson "08 Download a picture" - Download a picture p. 24-25and show on Screen
lesson "09 dynamic Text" - Change a textlabel of the Screens p. 26-27
lesson "10 Set Auto Sleep" – Screen to config of the dreambox's p. 28-30starting behavior
lesson "11 Start other plugin" – Screen to Start picture player p. 31-32
2
If you've made your basic python tutorial well, let's start...
Our Small Test
Ok, if you have installed the Tutorial plugin, start a telnet session to your dreambox and type in:
code:root@dm8000:~# init 4; sleep 4; enigma2
Enigma2 restarts and you can see the enigma2 messages in telnet.All print commands or error messages of your plugin will be shown there. (also during enigma2 startup)
Telnet is developers best friend!
Start the mini plugin from enigma2 cvs doc, for testing.(/usr/lib/enigma2/python/Plugins/IhadTutorial/OurSmallTest/..)
Open Plugin Browser and select:
3
Take a look at telnet:
Caution!
Press [Ctrl c] to stop enigma2.
code:...- (10) gRCwaiting for gRC thread shutdowngRC thread has finished- (9) gLCDDC- (9) GFBDC- (9) Font Render Class- (8) graphics acceleration manager- (1) Background File Eraserreached rl -1close frontend 0root@dm8000:~#
Please wait till the empty input appear in telnet, because enigma need to save configs!!
To start up enigma2 again:
code:
root@dm8000:~# init 4; sleep 4; init 3
4
code:
...hdd IDLE![IDLE] 251.999181986 120 Trueaction -> WizardActions ok
<<<<<<<<<< Hello world! >>>>>>>>>>
[EPGC] start cleanloop[EPGC] stop cleanloop...
The src to "Our smal Test":
Take a look at the module imports:
from Plugins.Plugin (file) /usr/lib/enigma2/python/Plugins/Plugin.py
the PluginDescriptor will be loaded. Take always a look at the module files you are importing, in order to know what you are loading, which parameters do you need. For beginner it is a little bit difficult, but that becomes better with time.
In our case it is the module, which promt our plugin in the Plugin Browser.
If you take a look at the file, you can see there are a lot of PluginDescriptors - more in lesson 10.
Info:
write and edit your enigma2 plugins direct on dreambox. To get your changes working restart enigma2 (see above)
Store you plugins at:
/usr/lib/enigma2/python/Plugins/Extensions/<your Pluginfolder> for example “MyPlugin“.
This Tutorial is only an Exception, for better overview, do not store plugins in other folders!
A plugin needs:
a file __init__.py (could be empty) and a file plugin.py (incl. src).
5
12345678910111213141516
# Ihad.tv enigma2-plugin tutorial 2010# "Our Small Test" - taken from enigma2/doc
from Plugins.Plugin import PluginDescriptor
def main(session, **kwargs):print "\n<<<<<<<<<< Hello world! >>>>>>>>>>\n"
def Plugins(**kwargs): return PluginDescriptor(
name="Our Small Test",description="plugin to test some capabilities",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
01 Hallo World
A simple window (screen) with textlable and exit command.
6
# Ihad.tv enigma2-plugin tutorial 2010# lesson 1# by emanuel###########################################################################
from Screens.Screen import Screenfrom Components.Label import Labelfrom Components.ActionMap import ActionMapfrom Plugins.Plugin import PluginDescriptor
###########################################################################
class HalloWorldScreen(Screen):skin = """
<screen position="130,150" size="460,150" title="Ihad.tv e2-tutorial lesson 1" >
<widget name="myLabel" position="10,60" size="200,40" font="Regular;20"/>
</screen>"""
def __init__(self, session, args = None):self.session = session
Screen.__init__(self, session)self["myLabel"] = Label("Hello World ;-)")self["myActionMap"] = ActionMap(["SetupActions"],{
"cancel": self.close # add the RC Command "cancel" to close your Screen
}, -1)
###########################################################################
def main(session, **kwargs):print "\n[Hallo World] start\n"
session.open(HalloWorldScreen)
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="01 Hallo World",description="lesson 1 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
123456789101112131415
16
17181920212223242526
2728293031323334353637383940414243444546
In lesson 01 you can see how to build a Screen class. What do you need?
1) imports line 6-9 (take a look at the files behind!!)(/usr/lib/enigma2/python/...)
2) Screen class HalloWorldScreen line 13-273) main function (starts the HalloWorldScreen) line 32-354) PluginDescriptor line 39-45
Explanation HalloWorldScreen class: Line 14-17 the skin is defined in xml format. 1 screen, 1 widget (Textlabel)Line19-27 initialisation of the class.
line 19: __init__ will be called at plugin start (note parameters).A Screen needs as his first parameter "self", as second a session.In our example the session parameter comes frome the main function.
line 20:The parameter session (provided by __init__) will be saved as class intern global variable self.session for further use.
line 22:Call initialisation function of the class including parameters self, self.session
line 23:widget "myLabel" (attributs set in line 16) becomes a static text.
line 24-27:The ActionMap will be definde. In our case the minimum is exit the Screen.See line 26 self.close becomes a RC command “cancel” from SetupActions.
note:ActionMap “SetupActions” is stored in:/usr/share/enigma2/keymap.xml
result:
7
02 Hallo World Message
a Screen with message
Bla
8
# Ihad.tv enigma2-plugin tutorial 2010# lesson 2# by emanuelfrom Screens.Screen import Screenfrom Components.Label import Labelfrom Components.ActionMap import ActionMapfrom Screens.MessageBox import MessageBoxfrom Plugins.Plugin import PluginDescriptor
###########################################################################
class HalloWorldMsg(Screen):skin = """
<screen position="130,150" size="460,150" title="Ihad.tv e2-tutorial lesson 2" >
<widget name="myLabel" position="10,60" size="200,40" font="Regular;20"/>
</screen>"""
def __init__(self, session, args = 0):self.session = sessionScreen.__init__(self, session)
self["myLabel"] = Label(_("please press OK"))self["myActionMap"] = ActionMap(["SetupActions"],{
"ok": self.myMsg,"cancel": self.cancel
}, -1)
def myMsg(self):print "\n[HalloWorldMsg] OK pressed \n"self.session.open(MessageBox,_("Hello World!"), MessageBox.TYPE_INFO)
def cancel(self):print "\n[HalloWorldMsg] cancel\n"self.close(False,self.session)
###########################################################################
def main(session, **kwargs):print "\n[HalloWorldMsg] start\n"session.open(HalloWorldMsg)
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="02 Hallo World Message",description="lesson 2 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
1234567891011121314
15
16171819202122232425262728293031323334353637383940414243444546474849505152
Explanation HalloWorldMsg Class:
As extension to lessen 01, take a look at line 7, 25-26 , 29-35
line 7:import of Screen class MessageBox(/usr/lib/enigma2/python/Screens/MessageBox.py)
line 25-26:Set class function to ActionMap line 29-35.
line 29-35:in “def myMsg” Screen MessageBox will be called.in “def cancel” normal self.close will be called with parameters(only for test example)
result:
9
03 Call My Msg
A Screen with message Yes/No
10
1234567891011121314
15
1617181920212223242526272829303132333435
36373839
4041424344
# Ihad.tv enigma2-plugin tutorial 2010# lesson 3# by emanuelfrom Screens.Screen import Screenfrom Components.Label import Labelfrom Components.ActionMap import ActionMapfrom Screens.MessageBox import MessageBoxfrom Plugins.Plugin import PluginDescriptor
###########################################################################
class CallMyMsg(Screen):skin = """
<screen position="130,150" size="460,150" title="Ihad.tv tutorial e2-tutorial lesson 3" >
<widget name="myLabel" position="10,60" size="400,120" font="Regular;20"/>
</screen>"""
def __init__(self, session, args = 0):self.session = sessionScreen.__init__(self, session)
self["myLabel"] = Label(_("please press OK to select"))self["myActionMap"] = ActionMap(["SetupActions"],{
"ok": self.myMsg,"cancel": self.cancel
}, -1)
def callMyMsg(self, result):print "\n[CallMyMsg] checking result\n"if result:
print "\n[CallMyMsg] cancel\n"self.close(None)
else:self.session.open(MessageBox,_("Ah, you like the Ihad
plugin!\n;-)"), MessageBox.TYPE_INFO)
def myMsg(self):print "\n[CallMyMsg] OK pressed \n"self.session.openWithCallback(self.callMyMsg, MessageBox, _("Do you
want to exit the plugin?"), MessageBox.TYPE_YESNO)
def cancel(self):print "\n[CallMyMsg] cancel\n"self.close(None)
continuation src: CallMyMsg
Explanation CallMyMsg class:
Als Ergänzungen gegenüber lessen 02 solltest du dir hier die line 29-39ansehen.
line 29-39:in “def callMyMsg” wird das result (result) des Aufrufes der “ openWithCallback” picture der session in line 39 ausgewertet. Sie diehnt als Schnittstelle zwischen den 2 Screens. Von der Ja/Nein Msg Screen wird 1 bzw 0 zurück gegeben.
result:
11
###########################################################################
def main(session, **kwargs):print "\n[CallMyMsg] start\n"session.open(CallMyMsg)
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="03 Call My Msg",description="lesson 3 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
45464748495051525354555657585960
04 My Menulist
Screen with menulist
12
1234567891011121314
15
16171819202122232425262728293031323334353637383940414243444546474849505152
# Ihad.tv enigma2-plugin tutorial 2010# lesson 4# by emanuelfrom Screens.Screen import Screenfrom Components.MenuList import MenuListfrom Components.ActionMap import ActionMapfrom Screens.MessageBox import MessageBoxfrom Plugins.Plugin import PluginDescriptor
###########################################################################
class MyMenu(Screen):skin = """
<screen position="100,150" size="460,400" title="Ihad.tv tutorial e2-tutorial lesson 4" >
<widget name="myMenu" position="10,10" size="420,380" scrollbarMode="showOnDemand" />
</screen>"""
def __init__(self, session, args = 0):self.session = session
list = []list.append((_("Entry 1"), "one"))list.append((_("Entry 2"), "two"))list.append((_("Entry 3"), "tree"))list.append((_("Exit"), "exit"))
Screen.__init__(self, session)self["myMenu"] = MenuList(list)self["myActionMap"] = ActionMap(["SetupActions"],{
"ok": self.go,"cancel": self.cancel
}, -1)
def go(self):returnValue = self["myMenu"].l.getCurrentSelection()[1]print "\n[MyMenu] returnValue: " + returnValue + "\n"
if returnValue is not None:if returnValue is "one":
self.myMsg("1")
elif returnValue is "two":self.myMsg("2")
elif returnValue is "tree":self.myMsg("3")
else:print "\n[MyMenu] cancel\n"self.close(None)
continuation src: MyMenu
Explanation MyMenu class:
line 5:import of the menulist. Take a look at Components.MenuList file!(/usr/lib/enigma2/python/Components/MenuList.py)
line 15:in Screen Skin is only one widget for Menulist defined.
line 21-25:the python list for Menulist will be build.
line 28:widget "myMenu" is the MenuList, the in line 21-25 made list is used as parameter.
line 31:RC Command "ok" is set to “self.go”.
line 35-51:self["myMenu"].l.getCurrentSelection()[1] provides the second listentry of the selected MenuList Entry, selected by RC Command “OK” list entry. example: (_("Entry 1"), "one") => “one”
13
535455565758596061626364656667686970717273747576
def myMsg(self, entry):self.session.open(MessageBox,_("You selected entry no. %s!")
% (entry), MessageBox.TYPE_INFO)
def cancel(self):print "\n[MyMenu] cancel\n"self.close(None)
###########################################################################
def main(session, **kwargs):print "\n[MyMenu] start\n"session.open(MyMenu)
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="04 My Menulist",description="lesson 4 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
result:
14
05 My Shell Prombt
Screen with menulist and shell commands , outpute on Screen Console
1415
# Ihad.tv enigma2-plugin tutorial 2010# lesson 5 - copyrights 2010 by emanueel@ihad.tv# by emanuelfrom Screens.Screen import Screenfrom Screens.Console import Consolefrom Components.MenuList import MenuListfrom Components.ActionMap import ActionMapfrom Plugins.Plugin import PluginDescriptor
###########################################################################
class MyShPrombt(Screen):skin = """
<screen position="100,150" size="460,400" title="Ihad.tv tutorial e2-tutorial lesson 5" >
<widget name="myMenu" position="10,10" size="420,380" scrollbarMode="showOnDemand" />
</screen>"""
def __init__(self, session, args = 0):self.session = session
list = []list.append(("netstat", "com_one"))list.append(("ls -ls /", "com_two"))list.append(("mount", "com_tree"))list.append((_("Exit"), "exit"))
Screen.__init__(self, session)self["myMenu"] = MenuList(list)self["myActionMap"] = ActionMap(["SetupActions"],{
"ok": self.go,"cancel": self.cancel
}, -1)
def go(self):returnValue = self["myMenu"].l.getCurrentSelection()[1]print "\n[MyShPrombt] returnValue: " + returnValue + "\n"
if returnValue is not None:if returnValue is "com_one":
self.prombt("/bin/netstat")
elif returnValue is "com_two":self.prombt("/bin/ls -ls /")
elif returnValue is "com_tree":self.prombt("/bin/mount")
else:print "\n[MyShPrombt] cancel\n"self.close(None)
1234567891011121314
15
16171819202122232425262728293031323334353637383940414243444546474849505152
continuation src: MyShPrombt
Explanation MyShPrombt class:
line 5:import of Console
line 71-72:“def prombt” starts a Screen Console. As parameter the shell commands are used. line: 41, 44, 47
16
def go(self):returnValue = self["myMenu"].l.getCurrentSelection()[1]print "\n[MyShPrombt] returnValue: " + returnValue + "\n"
if returnValue is not None:if returnValue is "com_one":
self.prombt("/bin/netstat")
elif returnValue is "com_two":self.prombt("/bin/ls -ls /")
elif returnValue is "com_tree":self.prombt("/bin/mount")
else:print "\n[MyShPrombt] cancel\n"self.close(None)
def prombt(self, com):self.session.open(Console,_("start shell com: %s") % (com), ["%s" %
com])
def cancel(self):print "\n[MyShPrombt] cancel\n"self.close(None)
###########################################################################
def main(session, **kwargs):print "\n[MyShPrombt] start\n"session.open(MyShPrombt)
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="05 My Shell Prombt",description="lesson 5 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
535455565758596061626364656667686970717273747576777879808182838485868788899091929394
result:
17
06 Message Input
Screens with character input, output
18
# Ihad.tv enigma2-plugin tutorial 2010# lesson 6# by emanuelfrom Screens.Screen import Screenfrom Components.Label import Labelfrom Components.ActionMap import ActionMapfrom Components.Input import Inputfrom Screens.InputBox import InputBoxfrom Screens.MessageBox import MessageBoxfrom Plugins.Plugin import PluginDescriptor
###########################################################################
class MsgInput(Screen):skin = """
<screen position="130,150" size="460,150" title="Ihad.tv e2-tutorial lesson 6" >
<widget name="myLabel" position="10,60" size="200,40" font="Regular;20"/>
</screen>"""
def __init__(self, session, args = 0):self.session = sessionScreen.__init__(self, session)
self["myLabel"] = Label(_("please press OK"))self["myActionMap"] = ActionMap(["SetupActions"],{
"ok": self.myInput,"cancel": self.cancel
}, -1)
def myInput(self):self.session.openWithCallback(self.askForWord, InputBox,
title=_("Please enter a name for prombt!"), text=" " * 55, maxSize=55, type=Input.TEXT)
def askForWord(self, word):if word is None:
passelse:
self.session.open(MessageBox,_(word), MessageBox.TYPE_INFO)
def cancel(self):print "\n[MsgInput] cancel\n"self.close(None)
12345678910111213141516
17
181920212223242526272829303132
3334353637383940414243
continuation src: MsgInput
Explanation MsgInput class:
The class MsgInput is a little bit like the lesson 03. Only the input does not provide 0 or 1 as result, in this case it is the input of the RC/Keyboard.
line 7,8:import from Input, InputBox
line 31-38:“def myInput” starts InputBox Screen. openWithCallback provides the result for “def askForWord” from InputBox.
19
###########################################################################
def main(session, **kwargs):print "\n[MsgInput] start\n"session.open(MsgInput)
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="06 Message Input",description="lesson 6 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
44454647484950515253545556575859
result:
20
07 View a picture
Screen with picture
21
1234567891011121314151617
18
1920212223242526272829303132333435363738394041
4243444546474849
# Ihad.tv enigma2-plugin tutorial 2010# lesson 7# by emanuelfrom Screens.Screen import Screenfrom Components.Label import Labelfrom Components.Pixmap import Pixmapfrom Components.AVSwitch import AVSwitchfrom Components.ActionMap import ActionMapfrom Plugins.Plugin import PluginDescriptorfrom enigma import ePicLoad
###########################################################################
class PictureScreen(Screen):
skin="""<screen name="PictureScreen" position="0,0" size="720,576"
title="Picture Screen" backgroundColor="#002C2C39"><widget name="myPic" position="0,0" size="720,576"
zPosition="1" alphatest="on" /></screen>"""
def __init__(self, session, picPath = None):Screen.__init__(self, session)print "[PictureScreen] __init__\n"self.picPath = picPathself.Scale = AVSwitch().getFramebufferScale()self.PicLoad = ePicLoad()self["myPic"] = Pixmap()self["myActionMap"] = ActionMap(["SetupActions"],{
"ok": self.cancel,"cancel": self.cancel
}, -1)
self.PicLoad.PictureData.get().append(self.DecodePicture)self.onLayoutFinish.append(self.ShowPicture)
def ShowPicture(self):if self.picPath is not None:
self.PicLoad.setPara([self["myPic"].instance.size().width(),
self["myPic"].instance.size().height(),
self.Scale[0],self.Scale[1],0,1,"#002C2C39"])
self.PicLoad.startDecode(self.picPath)
continuation src: PictureScreen
Explanation PictureScreen class:
The class PictureScreen is an example of how to show a picture in a Screen.
line 6,7,9:import of Pixmap, AVSwitch, ePicLoad (look at it!)
line 18:in Screen Skin widget “myPic” for the picture will be defined.
line 21:the Screen class PictureScreen takes from __init__ a extra Parameter “picPath” called from function “main” in line 64.
line 26:Memory for the picture
line 27:widget self["myPic"] becomes a Pixmap() without parameter!
22
def DecodePicture(self, PicInfo = ""):if self.picPath is not None:
ptr = self.PicLoad.getData()self["myPic"].instance.setPixmap(ptr)
def cancel(self):print "[PictureScreen] - cancel\n"self.close(None)
###########################################################################
def main(session, **kwargs):session.open(PictureScreen, picPath =
"/usr/share/enigma2/skin_default/icons/dish.png")
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="07 View a picture",description="lesson 7 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
5152535455565758596061626364
6566676869707172737475
line 34:loading und decoding of the picture, see line 51-54
line 35:the Screen picture “onLayoutFinish.append(self.ShowPicture)” loads the picture see line 37-48, parameter for the picture will be set.
result:
23
08 Download a picture
Download a picture and show on Screen from lesson 07
24
1234567891011121314151617181920
21222324
252627282930313233
3435363738394041424344
# Ihad.tv enigma2-plugin tutorial 2010# lesson 8# by emanuel###########################################################################
from twisted.web.client import downloadPagefrom Screens.MessageBox import MessageBoxfrom Plugins.IhadTutorial.lesson_07.plugin import PictureScreenfrom Plugins.Plugin import PluginDescriptor
###########################################################################
class getPicfromUrl(object):def __init__(self, session, url=None, path=None):
self.path = pathself.session = sessionself.download(url, path)
def download(self, url, path):downloadPage(url,
path).addCallback(self.downloadDone).addErrback(self.downloadError)
def downloadError(self, raw):print "[e2Fetcher.fetchPage]: download Error", rawself.session.open(MessageBox, text = _("Error downloading: ") +
self.path, type = MessageBox.TYPE_ERROR)
def downloadDone(self,raw):print "[e2Fetcher.fetchPage]: download done", rawself.session.open(PictureScreen, picPath = self.path)
###########################################################################
def main(session, **kwargs):getPicfromUrl(session,"http://www.i-have-a-dreambox.com/images/ihad.jpg",
"/tmp/myPic.tmp")
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="08 Download a picture",description="lesson 8 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
Explanation getPicfromUrl class:
The class getPicfromUrl imports the Screen from lesson 07 to show the dowloaded picture.
line 6,8:import of downloadPage, PictureScreen from lesson 07 (self made Screen)
line 13-28:class getPicfromUrl(object): is no Screen; but it uses a session to start PictureScreen or some MessageBox tht modules do need “session” as parameter! see line 14 __init__
result:
25
09 dynamic Text
Change a textlabel of Screen
26
# Ihad.tv enigma2-plugin tutorial 2010# lesson 9# by emanuel###########################################################################
from Screens.Screen import Screenfrom Components.Label import Labelfrom Components.ActionMap import ActionMapfrom Plugins.Plugin import PluginDescriptor
###########################################################################
class MyDynaTextScreen(Screen):skin = """
<screen position="130,150" size="460,150" title="Ihad.tv e2-tutorial lesson 9" >
<widget name="myText" position="10,50" size="400,40" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;22"/>
<widget name="myRedBtn" position="10,110" size="100,40" backgroundColor="red" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;20"/>
<widget name="myGreenBtn" position="120,110" size="100,40" backgroundColor="green" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;20"/>
</screen>"""
def __init__(self, session, args = 0):self.session = sessionScreen.__init__(self, session)
self.text="Press green or ok button to edit text!"self["myText"] = Label()self["myRedBtn"] = Label(_("Cancel"))self["myGreenBtn"] = Label(_("OK"))self["myActionsMap"] = ActionMap(["SetupActions", "ColorActions"],{
"ok": self.editMyText,"green": self.editMyText,"red": self.close,"cancel": self.close,
}, -1)self.onShown.append(self.setMyText)
def setMyText(self):self["myText"].setText(self.text)
def editMyText(self):self.text="I love Ihad.tv!\n:-)"self.setMyText()
###########################################################################
123456789101112131415
16
17
18
1920212223242526272829303132333435363738394041424344
continuation src: MyDynaTextScreen
Explanation MyDynaTextScreen class: Now this should be no problem for you.
line 26:self["myText"] = Label() with no parameter init! Note this is important for self["myText"].setText(self.text) in line 39!
line 36:self.onShown.append(self.setMyText) to get text at startup!
result:
27
###########################################################################
def main(session, **kwargs):session.open(MyDynaTextScreen)
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="09 dynamic Text",description="lesson 9 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
45464748495051525354555657585960
10 Set Auto Sleep
Screen to config of the dreambox starting behavior
28
12345678910111213141516171819202122232425
26
272829303132333435363738394041424344454647484950
# Ihad.tv enigma2-plugin tutorial 2010# lesson 10# by emanuel###########################################################################
from Screens.Screen import Screenfrom Screens.MessageBox import MessageBoxfrom Components.Label import Labelfrom Components.ActionMap import ActionMapfrom Components.config import config, ConfigSubsection, ConfigYesNofrom Plugins.Plugin import PluginDescriptorimport time
config.plugins.AutoSleep = ConfigSubsection()config.plugins.AutoSleep.enable = ConfigYesNo(default = False)
line = "-" * 66blank = "\n\n\n\n\n"tut_vers = "Ihad.tv e2-plugin tutorial v0.4 - lesson 10"
###########################################################################
class AutoSleepScreen(Screen):skin = """
<screen position="130,150" size="360,150" title="Ihad.tv e2-tutorial lesson 10" >
<widget name="myGreenBtn" position="120,50" size="120,60" backgroundColor="green" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;20"/>
</screen>"""
def __init__(self, session, args = 0):self.session = sessionScreen.__init__(self, session)self.changed = Falseself["myGreenBtn"] = Label()self["myActionsMap"] = ActionMap(["SetupActions", "ColorActions"],{
"green": self.setSleep,"ok": self.exit,"cancel": self.exit,
}, -1)self.onShown.append(self.updateSettings)
def updateSettings(self):GreenBtnCaption = "Auto Sleep: "if config.plugins.AutoSleep.enable.value:
GreenBtnCaption += _("on")self["myGreenBtn"].setText(GreenBtnCaption)
else:GreenBtnCaption += _("off")self["myGreenBtn"].setText(GreenBtnCaption)
continuation src: AutoSleepScreen
29
51525354565758596061626364656667686970717273747576
7778
7980818283848586878889909192939495969798
def setSleep(self):self.changed = Trueif config.plugins.AutoSleep.enable.value:
config.plugins.AutoSleep.enable.setValue(False)else:
config.plugins.AutoSleep.enable.setValue(True)self.updateSettings()
def exit(self):if self.changed:
config.plugins.AutoSleep.enable.save()self.close(None)
###########################################################################
def main(session, **kwargs):session.open(AutoSleepScreen)
############################################################################ start and stop enigma2 & and watch output in telnet
def autostart(reason, **kwargs):print blank, lineif reason == 0:
print "[AutoSleep] - autostart sleep enabled: ", config.plugins.AutoSleep.enable.getValue()
else:print "[AutoSleep] - autostop sleep enabled: ",
config.plugins.AutoSleep.enable.getValue()print tut_versprint line, blank
if config.plugins.AutoSleep.enable.value:time.sleep(10)
###########################################################################
def Plugins(**kwargs):return [
PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART,fnc = autostart),
PluginDescriptor(name = "10 Set Auto Sleep",description = "lesson 10 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon = "../ihad_tut.png",fnc = main)]
Explanation AutoSleepScreen class: Now this should be no problem for you. New: the Configs and the Autostart PluginDescriptor.
line 10:import of config, ConfigSubsection, ConfigYesNo
line 14:config.plugins.AutoSleep = ConfigSubsection() creating of Enigma sub configuratinos
line 15:config.plugins.AutoSleep.enable = ConfigYesNo(default = False)a variable that 0/1 stores.
line 73-83:The picture autostart is called by PluginDescriptor in line 91 and checks if config.plugins.AutoSleep.enable is set. If it is set, the enigma2 bootup will be stop for 10 sec. Watch this at startup/stop of your dreambox in telnet.
result:
30
"11 Start other plugin"Screen to start Pictureplayer
31
1234567891011121314151617
18
19
20
2122232425262728293031323334353637383940414243444546474849
# Ihad.tv enigma2-plugin tutorial 2010# lesson 11# by emanuel###########################################################################
from Screens.Screen import Screenfrom Screens.MessageBox import MessageBoxfrom Components.Label import Labelfrom Components.ActionMap import ActionMapfrom Plugins.Plugin import PluginDescriptorfrom Tools.Directories import fileExists
###########################################################################
class MyPluginStartScreen(Screen):skin = """
<screen position="130,150" size="460,150" title="Ihad.tv e2-tutorial lesson 11" >
<widget name="myText" position="10,20" size="400,50" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;22"/>
<widget name="myRedBtn" position="10,110" size="100,40" backgroundColor="red" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;20"/>
<widget name="myGreenBtn" position="120,110" size="100,40" backgroundColor="green" valign="center" halign="center" zPosition="2" foregroundColor="white" font="Regular;20"/>
</screen>"""
def __init__(self, session, args = 0):self.session = sessionScreen.__init__(self, session)
self["myText"] = Label("Press green or ok button to start\nPicture Player plugin!")
self["myRedBtn"] = Label(_("Cancel"))self["myGreenBtn"] = Label(_("OK"))self["myActionsMap"] = ActionMap(["SetupActions", "ColorActions"],{
"ok": self.startPicplayer,"green": self.startPicplayer,"red": self.close,"cancel": self.close,
}, -1)
def startPicplayer(self):if
fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.py"):from Plugins.Extensions.PicturePlayer.plugin import *self.session.open(picshow)
else:self.session.open(MessageBox,"No Picture Player found!",
MessageBox.TYPE_ERROR)
###########################################################################
def main(session, **kwargs):
continuation src: MyPluginStartScreen
Explanation MyPluginStartScreen class: Now this should be no problem for you. We imported Screens often in thie tutorial.
line 10/42:import of fileExists, and everything from PicturePlayerplug
result:
32
def main(session, **kwargs):session.open(MyPluginStartScreen)
###########################################################################
def Plugins(**kwargs):return PluginDescriptor(
name="11 Start other plugin",description="lesson 11 - Ihad.tv e2-tutorial",where = PluginDescriptor.WHERE_PLUGINMENU,icon="../ihad_tut.png",fnc=main)
50515253545556575859606162
top related