ORFteletext first check into CVS
[enigma2-plugins.git] / orfteletext / src / plugin.py
1 #######################################################################
2 #
3 #    ORFteletext for Dreambox-Enigma2
4 #    Coded by Vali (c)2010
5 #    Support: www.dreambox-tools.info
6 #
7 #  This plugin is licensed under the Creative Commons 
8 #  Attribution-NonCommercial-ShareAlike 3.0 Unported License.
9 #  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
10 #  or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
11 #
12 #  Alternatively, this plugin may be distributed and executed on hardware which
13 #  is licensed by Dream Multimedia GmbH.
14 #
15 #
16 #  This plugin is NOT free software. It is open source, you are allowed to
17 #  modify it (if you keep the license), but it may not be commercially 
18 #  distributed other than under the conditions noted above.
19 #
20 #
21 #######################################################################
22
23
24
25 from Screens.Screen import Screen
26 from Screens.MessageBox import MessageBox
27 from Plugins.Plugin import PluginDescriptor
28 from Components.ActionMap import NumberActionMap
29 from Components.AVSwitch import AVSwitch
30 from Components.Pixmap import Pixmap
31 from Components.MenuList import MenuList
32 from Components.Label import Label
33 from Tools.Directories import fileExists
34 from enigma import ePicLoad, getDesktop
35 from os import system as os_system
36
37
38
39 def Plugins(**kwargs):
40         return [PluginDescriptor(name="ORF-Teletext", description=_("ORF-Teletext"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=main),]
41
42
43
44 def main(session, **kwargs):
45         session.open(ORFteletextScreen)
46
47
48
49 class ORFteletextScreen(Screen):
50         if (getDesktop(0).size().width()) == 1280:
51                 skin="""
52                         <screen flags="wfNoBorder" position="0,0" size="1280,720" title="ORF-Teletext" backgroundColor="#00121214">
53                                 <widget backgroundColor="#ffffffff" position="30,163" render="Pig" size="700,394" source="session.VideoPicture" zPosition="1"/>
54                                 <widget name="Picture" position="740,192" size="480,336" zPosition="1"/>
55                                 <widget name="seite" position="770,93" size="200,24" font="Regular;22" transparent="1"/>
56                                 <widget name="wohin" position="770,123" size="200,24" font="Regular;22" foregroundColor="#ff4a3c" transparent="1"/>
57                                 <eLabel font="Regular;20" foregroundColor="#00ff4A3C" position="320,620" size="120,26" transparent="1" text="NEWS"/>
58                                 <eLabel font="Regular;20" foregroundColor="#0056C856" position="320,650" size="120,26" transparent="1" text="WEATHER"/>
59                                 <eLabel font="Regular;20" foregroundColor="#00ffc000" position="760,620" size="120,26" transparent="1" text="SPORT"/>
60                                 <eLabel font="Regular;20" foregroundColor="#00879ce1" position="760,650" size="120,26" transparent="1" text="INDEX"/>
61                         </screen>"""
62         elif (getDesktop(0).size().width()) == 1024:
63                 skin="""
64                         <screen flags="wfNoBorder" position="0,0" size="1024,576" title="ORF-Teletext" backgroundColor="#00121214">
65                                 <widget backgroundColor="#ffffffff" position="30,156" render="Pig" size="470,264" source="session.VideoPicture" zPosition="1"/>
66                                 <widget name="Picture" position="504,120" size="480,336" zPosition="1"/>
67                                 <widget name="seite" position="504,50" size="200,24" font="Regular;22" transparent="1"/>
68                                 <widget name="wohin" position="504,75" size="200,24" font="Regular;22" foregroundColor="#ff4a3c" transparent="1"/>
69                                 <eLabel font="Regular;20" foregroundColor="#00ff4A3C" position="220,480" size="120,26" transparent="1" text="NEWS"/>
70                                 <eLabel font="Regular;20" foregroundColor="#0056C856" position="220,510" size="120,26" transparent="1" text="WEATHER"/>
71                                 <eLabel font="Regular;20" foregroundColor="#00ffc000" position="504,480" size="120,26" transparent="1" text="SPORT"/>
72                                 <eLabel font="Regular;20" foregroundColor="#00879ce1" position="504,510" size="120,26" transparent="1" text="INDEX"/>
73                         </screen>"""
74         else:
75                 skin="""
76                         <screen flags="wfNoBorder" position="0,0" size="720,576" title="ORF-Teletext" backgroundColor="#00121214">
77                                 <widget name="seite" position="250,50" size="200,24" font="Regular;22" transparent="1"/>
78                                 <widget name="wohin" position="250,75" size="200,24" font="Regular;22" foregroundColor="#ff4a3c" transparent="1"/>
79                                 <widget backgroundColor="#ffffffff" position="60,156" render="Pig" size="160,120" source="session.VideoPicture" zPosition="1"/>
80                                 <widget name="Picture" position="250,120" size="480,336" zPosition="1"/>
81                                 <eLabel font="Regular;20" foregroundColor="#00ff4A3C" position="120,480" size="120,26" transparent="1" text="NEWS"/>
82                                 <eLabel font="Regular;20" foregroundColor="#0056C856" position="120,510" size="120,26" transparent="1" text="WEATHER"/>
83                                 <eLabel font="Regular;20" foregroundColor="#00ffc000" position="504,480" size="120,26" transparent="1" text="SPORT"/>
84                                 <eLabel font="Regular;20" foregroundColor="#00879ce1" position="504,510" size="120,26" transparent="1" text="INDEX"/>
85                         </screen>"""
86         def __init__(self, session):
87                 Screen.__init__(self, session)
88                 self["seite"] = Label("100")
89                 self["wohin"] = Label("")
90                 self.seite = 100
91                 self.strseite = ""
92                 self.subseite = 1
93                 self.EXscale = (AVSwitch().getFramebufferScale())
94                 self.EXpicload = ePicLoad()
95                 self["Picture"] = Pixmap()
96                 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions"],
97                 {
98                         "ok": self.showMe,
99                         "cancel": self.raus,
100                         "left": self.seiteMinus,
101                         "right": self.seitePlus,
102                         "up": self.vor,
103                         "down": self.zurueck,
104                         "1": self.keyNumberGlobal,
105                         "2": self.keyNumberGlobal,
106                         "3": self.keyNumberGlobal,
107                         "4": self.keyNumberGlobal,
108                         "5": self.keyNumberGlobal,
109                         "6": self.keyNumberGlobal,
110                         "7": self.keyNumberGlobal,
111                         "8": self.keyNumberGlobal,
112                         "9": self.keyNumberGlobal,
113                         "0": self.keyNumberGlobal,
114                         "red": self.rot,
115                         "green": self.gruen,
116                         "yellow": self.gelb,
117                         "blue": self.blau
118                 }, -1)
119                 if fileExists("/tmp/bild"):
120                         self.whatPic = "/tmp/bild"
121                 else:
122                         self.whatPic = "/usr/lib/enigma2/python/Plugins/Extensions/ORFteletext/nodata.png"
123                 self.EXpicload.PictureData.get().append(self.DecodeAction)
124                 self.onLayoutFinish.append(self.firstStart)
125
126         def firstStart(self):
127                 self.lade2(self.seite,self.subseite)
128
129         def Show_Picture(self):
130                 if self.whatPic is not None:
131                         self.EXpicload.setPara([self["Picture"].instance.size().width(), self["Picture"].instance.size().height(), self.EXscale[0], self.EXscale[1], 0, 1, "#121214"])
132                         self.EXpicload.startDecode(self.whatPic)
133
134         def DecodeAction(self, pictureInfo=" "):
135                 if self.whatPic is not None:
136                         ptr = self.EXpicload.getData()
137                         self["Picture"].instance.setPixmap(ptr)
138
139         def raus(self):
140                 os_system("rm -f /tmp/bild")
141                 self.close()
142
143         def lade2(self, hs, ns):
144                 os_system("rm -f /tmp/bild")
145                 hz = str(hs)
146                 lz = hz[0]
147                 nz = str(ns)
148                 adr = "http://teletext.orf.at/" + lz + "00/" + hz + "_000" + nz + ".png"
149                 neu = "wget -O /tmp/bild " + adr
150                 self["seite"].setText(hz+"-"+nz)
151                 os_system(neu)
152                 if fileExists("/tmp/bild"):
153                         self.whatPic = "/tmp/bild"
154                 else:
155                         self.whatPic = "/usr/lib/enigma2/python/Plugins/Extensions/ORFteletext/nodata.png"
156                 self.Show_Picture()
157
158         def showMe(self):
159                 self.lade2(self.seite,self.subseite)
160
161         def seitePlus(self):
162                 if self.subseite < 9:
163                         self.subseite = self.subseite + 1
164                 else:
165                         self.subseite = 1
166                 self.lade2(self.seite,self.subseite)
167
168         def seiteMinus(self):
169                 if self.subseite > 1:
170                         self.subseite = self.subseite - 1
171                 else:
172                         self.subseite = 1
173                 self.lade2(self.seite,self.subseite)
174
175         def keyNumberGlobal(self,number):
176                 if len(self.strseite) < 3:
177                         self.strseite = self.strseite + str(number)
178                         self["wohin"].setText(self.strseite)
179                 if len(self.strseite) == 3:
180                         self.seite = int(self.strseite)
181                         self.subseite = 1
182                         self.lade2(self.seite,self.subseite)
183                         self.strseite = ""
184                         self["wohin"].setText(self.strseite)
185                 if len(self.strseite) > 3:
186                         self.strseite = ""
187                         self["wohin"].setText(self.strseite)
188
189         def vor(self):
190                 if self.seite < 900:
191                         self.seite = self.seite + 1
192                 else:
193                         self.seite = 100
194                 self.subseite = 1
195                 self.lade2(self.seite,self.subseite)
196
197         def zurueck(self):
198                 if self.seite > 100:
199                         self.seite = self.seite - 1
200                 else:
201                         self.seite = 100
202                 self.subseite = 1
203                 self.lade2(self.seite,self.subseite)    
204
205         def rot(self):
206                 self.seite = 111
207                 self.subseite = 1
208                 self.lade2(self.seite,self.subseite)
209
210         def gruen(self):
211                 self.seite = 600
212                 self.subseite = 1
213                 self.lade2(self.seite,self.subseite)
214
215         def gelb(self):
216                 self.seite = 200
217                 self.subseite = 1
218                 self.lade2(self.seite,self.subseite)
219
220         def blau(self):
221                 self.seite = 890
222                 self.subseite = 1
223                 self.lade2(self.seite,self.subseite)
224         
225
226
227
228
229
230
231
232
233