add tuxbox starter plugin for enigma2
[tuxtxt.git] / plugin.py
1 from enigma import eConsoleAppContainer, iServiceInformation, fbClass, eRCInput, eDBoxLCD, getDesktop
2 from Screens.Screen import Screen
3 from Plugins.Plugin import PluginDescriptor
4 from os import symlink, mkdir, remove, rmdir, path
5
6 class ShellStarter(Screen):
7         skin = """
8                 <screen position="1,1" size="1,1" title="TuxTXT" >
9                 </screen>"""
10         faked_lcd = False
11
12         def __init__(self, session, args = None):
13                 self.skin = ShellStarter.skin
14                 Screen.__init__(self, session)
15                 self.container=eConsoleAppContainer()
16                 self.container.appClosed.append(self.finished)
17                 self.runapp()
18
19         def runapp(self):
20                 service = self.session.nav.getCurrentService()
21                 info = service and service.info()
22                 txtpid = info and "%d" %(info.getInfo(iServiceInformation.sTXTPID)) or ""
23
24                 stream = service and service.stream()
25                 demux = stream and stream.getStreamingData()
26                 demux = demux and demux.get("demux", -1)
27                 demux = demux > -1 and "%d" %(demux) or ""
28
29                 eDBoxLCD.getInstance().lock()
30                 eRCInput.getInstance().lock()
31                 fbClass.getInstance().lock()
32
33                 self.faked_lcd = not path.exists("/dev/dbox")
34                 if self.faked_lcd:
35                         mkdir("/dev/dbox")
36                         symlink("/dev/null", "/dev/dbox/lcd0")
37
38                 if self.container.execute("/usr/bin/tuxtxt " + demux + " " + txtpid):
39                         self.finished(-1)
40
41         def finished(self,retval):
42                 fbClass.getInstance().unlock()
43                 eRCInput.getInstance().unlock()
44                 eDBoxLCD.getInstance().unlock()
45
46                 if self.faked_lcd:
47                         remove("/dev/dbox/lcd0")
48                         rmdir("/dev/dbox")
49
50                 #force redraw
51                 dsk = getDesktop(0)
52                 dsk.resize(dsk.size())
53
54                 self.close()
55
56 def main(session, **kwargs):
57         session.open(ShellStarter)
58
59 def Plugins(**kwargs):
60         return PluginDescriptor(name="TuxTXT", description="Videotext", where = PluginDescriptor.WHERE_TELETEXT, fnc=main)