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