now is possible to browse also SAT1 teletext
[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 from Components.config import config, ConfigSubsection, ConfigText, ConfigInteger
37
38
39
40 config.plugins.ORFteletext = ConfigSubsection()
41 config.plugins.ORFteletext.startHZ = ConfigInteger(default=100)
42 config.plugins.ORFteletext.startNZ = ConfigInteger(default=1)
43 config.plugins.ORFteletext.adr = ConfigText(default="ORF")
44
45
46
47 def Plugins(**kwargs):
48         return [PluginDescriptor(name="ORF-Teletext", description=_("ORF-Teletext"), where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=main),]
49
50
51
52 def main(session, **kwargs):
53         session.open(ORFteletextScreen)
54
55
56
57 class ORFteletextScreen(Screen):
58         if (getDesktop(0).size().width()) == 1280:
59                 skin="""
60                         <screen flags="wfNoBorder" position="0,0" size="1280,720" title="ORF-Teletext" backgroundColor="#00121214">
61                                 <widget backgroundColor="#ffffffff" position="30,163" render="Pig" size="700,394" source="session.VideoPicture" zPosition="1"/>
62                                 <widget name="Picture" position="740,192" size="480,336" zPosition="1"/>
63                                 <widget name="seite" position="770,93" size="200,24" font="Regular;22" transparent="1"/>
64                                 <widget name="wohin" position="770,123" size="200,24" font="Regular;22" foregroundColor="#ff4a3c" transparent="1"/>
65                                 <eLabel font="Regular;20" foregroundColor="#00ff4A3C" position="320,620" size="120,26" transparent="1" text="NEWS"/>
66                                 <eLabel font="Regular;20" foregroundColor="#0056C856" position="320,650" size="120,26" transparent="1" text="WEATHER"/>
67                                 <eLabel font="Regular;20" foregroundColor="#00ffc000" position="760,620" size="120,26" transparent="1" text="SPORT"/>
68                                 <eLabel font="Regular;20" foregroundColor="#00879ce1" position="760,650" size="120,26" transparent="1" text="INDEX"/>
69                         </screen>"""
70         elif (getDesktop(0).size().width()) == 1024:
71                 skin="""
72                         <screen flags="wfNoBorder" position="0,0" size="1024,576" title="ORF-Teletext" backgroundColor="#00121214">
73                                 <widget backgroundColor="#ffffffff" position="30,156" render="Pig" size="470,264" source="session.VideoPicture" zPosition="1"/>
74                                 <widget name="Picture" position="504,120" size="480,336" zPosition="1"/>
75                                 <widget name="seite" position="504,50" size="200,24" font="Regular;22" transparent="1"/>
76                                 <widget name="wohin" position="504,75" size="200,24" font="Regular;22" foregroundColor="#ff4a3c" transparent="1"/>
77                                 <eLabel font="Regular;20" foregroundColor="#00ff4A3C" position="220,480" size="120,26" transparent="1" text="NEWS"/>
78                                 <eLabel font="Regular;20" foregroundColor="#0056C856" position="220,510" size="120,26" transparent="1" text="WEATHER"/>
79                                 <eLabel font="Regular;20" foregroundColor="#00ffc000" position="504,480" size="120,26" transparent="1" text="SPORT"/>
80                                 <eLabel font="Regular;20" foregroundColor="#00879ce1" position="504,510" size="120,26" transparent="1" text="INDEX"/>
81                         </screen>"""
82         else:
83                 skin="""
84                         <screen flags="wfNoBorder" position="0,0" size="720,576" title="ORF-Teletext" backgroundColor="#00121214">
85                                 <widget name="seite" position="250,50" size="200,24" font="Regular;22" transparent="1"/>
86                                 <widget name="wohin" position="250,75" size="200,24" font="Regular;22" foregroundColor="#ff4a3c" transparent="1"/>
87                                 <widget backgroundColor="#ffffffff" position="60,156" render="Pig" size="160,120" source="session.VideoPicture" zPosition="1"/>
88                                 <widget name="Picture" position="250,120" size="480,336" zPosition="1"/>
89                                 <eLabel font="Regular;20" foregroundColor="#00ff4A3C" position="120,480" size="120,26" transparent="1" text="NEWS"/>
90                                 <eLabel font="Regular;20" foregroundColor="#0056C856" position="120,510" size="120,26" transparent="1" text="WEATHER"/>
91                                 <eLabel font="Regular;20" foregroundColor="#00ffc000" position="504,480" size="120,26" transparent="1" text="SPORT"/>
92                                 <eLabel font="Regular;20" foregroundColor="#00879ce1" position="504,510" size="120,26" transparent="1" text="INDEX"/>
93                         </screen>"""
94         def __init__(self, session):
95                 Screen.__init__(self, session)
96                 self["seite"] = Label("100")
97                 self["wohin"] = Label("")
98                 self.seite = config.plugins.ORFteletext.startHZ.value
99                 self.strseite = ""
100                 self.subseite = config.plugins.ORFteletext.startNZ.value
101                 self.EXscale = (AVSwitch().getFramebufferScale())
102                 self.EXpicload = ePicLoad()
103                 self["Picture"] = Pixmap()
104                 self["actions"] = NumberActionMap(["DirectionActions", "ColorActions", "OkCancelActions", "NumberActions", "EPGSelectActions"],
105                 {
106                         "ok": self.showMe,
107                         "cancel": self.raus,
108                         "left": self.seiteMinus,
109                         "right": self.seitePlus,
110                         "up": self.vor,
111                         "down": self.zurueck,
112                         "1": self.keyNumberGlobal,
113                         "2": self.keyNumberGlobal,
114                         "3": self.keyNumberGlobal,
115                         "4": self.keyNumberGlobal,
116                         "5": self.keyNumberGlobal,
117                         "6": self.keyNumberGlobal,
118                         "7": self.keyNumberGlobal,
119                         "8": self.keyNumberGlobal,
120                         "9": self.keyNumberGlobal,
121                         "0": self.keyNumberGlobal,
122                         "red": self.rot,
123                         "green": self.gruen,
124                         "yellow": self.gelb,
125                         "blue": self.blau,
126                         "info": self.Info
127                 }, -1)
128                 if fileExists("/tmp/bild"):
129                         self.whatPic = "/tmp/bild"
130                 else:
131                         self.whatPic = "/usr/lib/enigma2/python/Plugins/Extensions/ORFteletext/nodata.png"
132                 self.EXpicload.PictureData.get().append(self.DecodeAction)
133                 self.onLayoutFinish.append(self.firstStart)
134
135         def firstStart(self):
136                 self.lade2(self.seite,self.subseite)
137
138         def Show_Picture(self):
139                 if self.whatPic is not None:
140                         self.EXpicload.setPara([self["Picture"].instance.size().width(), self["Picture"].instance.size().height(), self.EXscale[0], self.EXscale[1], 0, 1, "#121214"])
141                         self.EXpicload.startDecode(self.whatPic)
142
143         def DecodeAction(self, pictureInfo=" "):
144                 if self.whatPic is not None:
145                         ptr = self.EXpicload.getData()
146                         self["Picture"].instance.setPixmap(ptr)
147
148         def raus(self):
149                 os_system("rm -f /tmp/bild")
150                 config.plugins.ORFteletext.startHZ.value = self.seite
151                 config.plugins.ORFteletext.startNZ.value = self.subseite
152                 config.plugins.ORFteletext.adr.save()
153                 config.plugins.ORFteletext.startHZ.save()
154                 config.plugins.ORFteletext.startNZ.save()
155                 self.close()
156
157         def lade2(self, hs, ns):
158                 os_system("rm -f /tmp/bild")
159                 hz = str(hs)
160                 lz = hz[0]
161                 nz = str(ns)
162                 if config.plugins.ORFteletext.adr.value == "ORF":
163                         adr = "http://teletext.orf.at/" + lz + "00/" + hz + "_000" + nz + ".png"
164                 elif config.plugins.ORFteletext.adr.value == "SAT1":
165                         adr = "http://www.sat1.at/service/teletext/cache_de/" + hz + "_0" + nz + ".png" 
166                 neu = "wget -O /tmp/bild " + adr
167                 self["seite"].setText(hz+"-"+nz+" at "+config.plugins.ORFteletext.adr.value)
168                 os_system(neu)
169                 if fileExists("/tmp/bild"):
170                         self.whatPic = "/tmp/bild"
171                 else:
172                         self.whatPic = "/usr/lib/enigma2/python/Plugins/Extensions/ORFteletext/nodata.png"
173                 self.Show_Picture()
174
175         def showMe(self):
176                 self.lade2(self.seite,self.subseite)
177
178         def seitePlus(self):
179                 if self.subseite < 9:
180                         self.subseite = self.subseite + 1
181                 else:
182                         self.subseite = 1
183                 self.lade2(self.seite,self.subseite)
184
185         def seiteMinus(self):
186                 if self.subseite > 1:
187                         self.subseite = self.subseite - 1
188                 else:
189                         self.subseite = 1
190                 self.lade2(self.seite,self.subseite)
191
192         def keyNumberGlobal(self,number):
193                 if len(self.strseite) < 3:
194                         self.strseite = self.strseite + str(number)
195                         self["wohin"].setText(self.strseite)
196                 if len(self.strseite) == 3:
197                         self.seite = int(self.strseite)
198                         self.subseite = 1
199                         self.lade2(self.seite,self.subseite)
200                         self.strseite = ""
201                         self["wohin"].setText(self.strseite)
202                 if len(self.strseite) > 3:
203                         self.strseite = ""
204                         self["wohin"].setText(self.strseite)
205
206         def vor(self):
207                 if self.seite < 900:
208                         self.seite = self.seite + 1
209                 else:
210                         self.seite = 100
211                 self.subseite = 1
212                 self.lade2(self.seite,self.subseite)
213
214         def zurueck(self):
215                 if self.seite > 100:
216                         self.seite = self.seite - 1
217                 else:
218                         self.seite = 100
219                 self.subseite = 1
220                 self.lade2(self.seite,self.subseite)    
221
222         def rot(self):
223                 self.seite = 111
224                 self.subseite = 1
225                 self.lade2(self.seite,self.subseite)
226
227         def gruen(self):
228                 if config.plugins.ORFteletext.adr.value == "ORF":
229                         self.seite = 600
230                 elif config.plugins.ORFteletext.adr.value == "SAT1":
231                         self.seite = 150
232                 self.subseite = 1
233                 self.lade2(self.seite,self.subseite)
234         def gelb(self):
235                 self.seite = 200
236                 self.subseite = 1
237                 self.lade2(self.seite,self.subseite)
238
239         def blau(self):
240                 if config.plugins.ORFteletext.adr.value == "ORF":
241                         self.seite = 890
242                 elif config.plugins.ORFteletext.adr.value == "SAT1":
243                         self.seite = 104
244                 self.subseite = 1
245                 self.lade2(self.seite,self.subseite)
246                         
247
248         def Info(self):
249                 if config.plugins.ORFteletext.adr.value == "ORF":
250                         config.plugins.ORFteletext.adr.value = "SAT1"
251                         config.plugins.ORFteletext.adr.save()
252                 else:
253                         config.plugins.ORFteletext.adr.value = "ORF"
254                         config.plugins.ORFteletext.adr.save()
255                 self.seite = 100
256                 self.subseite = 1
257                 self.showMe()
258
259
260
261