edit timer posibility by pressing pvr/vodeo button
[enigma2-plugins.git] / merlinepg / src / plugin.py
1 #######################################################################
2 #
3 #    Merlin Programm Guide for Dreambox-Enigma2
4 #    Coded by Vali (c)2010
5 #    Support: www.dreambox-tools.info
6 #
7 #
8 #  This plugin is licensed under the Creative Commons 
9 #  Attribution-NonCommercial-ShareAlike 3.0 Unported License.
10 #  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
11 #  or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12 #
13 #  Alternatively, this plugin may be distributed and executed on hardware which
14 #  is licensed by Dream Multimedia GmbH.
15 #
16 #
17 #  This plugin is NOT free software. It is open source, you are allowed to
18 #  modify it (if you keep the license), but it may not be commercially 
19 #  distributed other than under the conditions noted above.
20 #
21 #
22 #######################################################################
23
24
25
26 from Plugins.Plugin import PluginDescriptor
27 from Screens.Screen import Screen
28 from Screens.EventView import EventViewSimple
29 from Screens.MessageBox import MessageBox
30 from Screens.ChoiceBox import ChoiceBox
31 from Screens.TimerEntry import TimerEntry
32 from Screens.TimerEdit import TimerSanityConflict
33 from Components.ConfigList import ConfigListScreen
34 from Components.ActionMap import ActionMap
35 from Components.MenuList import MenuList
36 from Components.Label import Label
37 from Components.EpgList import EPGList, EPG_TYPE_SINGLE, Rect
38 from Components.config import config, ConfigSubsection, ConfigYesNo, ConfigInteger, getConfigListEntry
39 from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN, fileExists
40 from Tools.LoadPixmap import LoadPixmap
41 from enigma import eServiceReference, eServiceCenter, getDesktop, eTimer, gFont, eListboxPythonMultiContent, RT_HALIGN_LEFT, RT_WRAP
42 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
43 from ServiceReference import ServiceReference
44 from ShowMe import ShowMe
45 from time import localtime
46 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/AutoTimer/AutoTimerEditor.pyo") or fileExists("/usr/lib/enigma2/python/Plugins/Extensions/AutoTimer/AutoTimerEditor.pyc"):
47         from Plugins.Extensions.AutoTimer.AutoTimerEditor import addAutotimerFromEvent
48         from Plugins.Extensions.AutoTimer.plugin import main as AutoTimerView
49         AutoTimerPresent=True
50 else:
51         AutoTimerPresent=False
52 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/IMDb/plugin.pyo") or fileExists("/usr/lib/enigma2/python/Plugins/Extensions/IMDb/plugin.pyc"):
53         from Plugins.Extensions.IMDb.plugin import IMDB
54         IMDbPresent=True
55 else:
56         IMDbPresent=False
57
58
59 config.plugins.MerlinEPG = ConfigSubsection()
60 config.plugins.MerlinEPG.Columns = ConfigYesNo(default=True)
61 config.plugins.MerlinEPG.StartFirst = ConfigYesNo(default=False)
62 config.plugins.MerlinEPG.Primetime  = ConfigInteger(default=20, limits=(0, 23))
63 config.plugins.MerlinEPG.PTlow  = ConfigInteger(default=10, limits=(0, 59))
64 config.plugins.MerlinEPG.PThi  = ConfigInteger(default=20, limits=(0, 59))
65 config.plugins.MerlinEPG.AutoPT  = ConfigYesNo(default=False)
66 config.plugins.MerlinEPG.ZapOnOK  = ConfigYesNo(default=False)
67 config.plugins.MerlinEPG.PageUDonBouquets  = ConfigYesNo(default=True)
68
69
70
71 def Plugins(**kwargs):
72         list = [(PluginDescriptor(name="Merlin Programm Guide", description="Merlin Programm Guide", where = PluginDescriptor.WHERE_EVENTINFO, fnc=startMerlinPG))]
73         list.append(PluginDescriptor(name="Merlin Programm Guide", where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=startMerlinPGnew))
74         return list
75
76
77
78 def startMerlinPG(session, servicelist, **kwargs):
79         if config.plugins.MerlinEPG.Columns.value:
80                 session.open(Merlin_PGII, servicelist)
81         else:
82                 session.open(Merlin_PGd, servicelist)
83
84
85
86 def startMerlinPGnew(session, **kwargs):
87         if "servicelist" in kwargs:
88                 if config.plugins.MerlinEPG.Columns.value:
89                         session.open(Merlin_PGII, kwargs["servicelist"])
90                 else:
91                         session.open(Merlin_PGd, kwargs["servicelist"])
92         else:
93                 if config.plugins.MerlinEPG.Columns.value:
94                         session.open(Merlin_PGII)
95                 else:
96                         session.open(Merlin_PGd)
97
98
99
100 class MerlinPGsetup(ConfigListScreen, Screen):
101         skin = """
102                 <screen position="center,center" size="600,300" title="Merlin Programm Guide">
103                         <widget name="config" position="10,10" size="580,280" scrollbarMode="showOnDemand" />
104                 </screen>"""
105
106         def __init__(self, session):
107                 Screen.__init__(self, session)
108                 clist = []
109                 clist.append(getConfigListEntry(_("Show EPG in columns:"), config.plugins.MerlinEPG.Columns))
110                 clist.append(getConfigListEntry(_("Start allways on channel 1:"), config.plugins.MerlinEPG.StartFirst))
111                 clist.append(getConfigListEntry(_("Primetime (h):"), config.plugins.MerlinEPG.Primetime))
112                 clist.append(getConfigListEntry(_("Primetime from (m):"), config.plugins.MerlinEPG.PTlow))
113                 clist.append(getConfigListEntry(_("Primetime to (m):"), config.plugins.MerlinEPG.PThi))
114                 clist.append(getConfigListEntry(_("Auto-Primetime:"), config.plugins.MerlinEPG.AutoPT))
115                 clist.append(getConfigListEntry(_("Zap with OK button (false=EventInfo):"), config.plugins.MerlinEPG.ZapOnOK))
116                 clist.append(getConfigListEntry(_("Page-up/down with bouquet+/- :"), config.plugins.MerlinEPG.PageUDonBouquets))
117                 ConfigListScreen.__init__(self, clist)
118                 self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.set, "cancel": self.exit}, -2)
119
120         def set(self):
121                 if not config.plugins.MerlinEPG.PThi.value > config.plugins.MerlinEPG.PTlow.value:
122                         return
123                 for x in self["config"].list:
124                         x[1].save()
125                 self.close()
126
127         def exit(self):
128                 for x in self["config"].list:
129                         x[1].cancel()
130                 self.close()
131
132
133
134 class MerlinEPGList(EPGList):
135         def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None):
136                 EPGList.__init__(self, type, selChangedCB, timer)
137                 self.l.setFont(0, gFont("Regular", 18))
138                 self.PTpicture = LoadPixmap(cached=True, path="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/primetime.png")
139                 self.evCnt = 0
140
141         def recalcEntrySize(self):
142                 esize = self.l.getItemSize()
143                 width = esize.width()
144                 height = esize.height()
145                 self.weekday_rect = Rect(120, -10, 200, 20)
146                 self.datetime_rect = Rect(0, 0, 120, 20)
147                 self.descr_rect = Rect(0, 22, width, height-23)
148                 self.evCnt = 0
149
150         def buildSingleEntry(self, service, eventId, beginTime, duration, EventName):
151                 (clock_pic, rec) = self.getPixmapForEntry(service, eventId, beginTime, duration)
152                 r1=self.weekday_rect
153                 r2=self.datetime_rect
154                 r3=self.descr_rect
155                 t = localtime(beginTime)
156                 self.evCnt = self.evCnt + 1
157                 if (t[3]==config.plugins.MerlinEPG.Primetime.value) and (t[4]>=config.plugins.MerlinEPG.PTlow.value) and (t[4]<config.plugins.MerlinEPG.PThi.value):
158                         res = [
159                                 None,
160                                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, "  _________________"),
161                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 100, 1, 21, 21, self.PTpicture),
162                                 (eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_LEFT, (("%02d:%02d"%(t[3],t[4]))+" - "+self.days[t[6]]))
163                         ]
164                 else:
165                         res = [
166                                 None,
167                                 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, "___________________"),
168                                 (eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_LEFT, (("%02d:%02d"%(t[3],t[4]))+" - "+self.days[t[6]]))
169                         ]
170                 if rec:
171                         res.extend((
172                                 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
173                                 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT|RT_WRAP, EventName)
174                         ))
175                 else:
176                         res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT|RT_WRAP, EventName))
177                 return res
178
179         def getBgTime(self):
180                 tmp = self.l.getCurrentSelection()
181                 if tmp is None:
182                         return ( None )
183                 bt = localtime(tmp[2])
184                 return ( bt[3], bt[4] )
185
186         def foudPrimetime(self):
187                 for OneLine in range(0,self.evCnt):
188                         evBgTime, evBgMin = self.getBgTime()
189                         if evBgTime is not None:
190                                 if (evBgTime==config.plugins.MerlinEPG.Primetime.value) and (evBgMin>=config.plugins.MerlinEPG.PTlow.value) and (evBgMin<config.plugins.MerlinEPG.PThi.value):
191                                         break
192                                 self.moveDown()
193                         else:
194                                 break
195
196
197
198 class Merlin_PGII(Screen):
199         sz_w = getDesktop(0).size().width()
200         if sz_w == 1280:
201                 skin = """
202                 <screen flags="wfNoBorder" name="Merlin_PG" position="0,0" size="1280,720" title="Merlin Program Guide">
203                 <!-- DO NOT CHANGE THIS LINE !!!!!!!!!!!!!!! --><widget enableWrapAround="0" itemHeight="25" name="prg_list" position="-200,-200" size="50,125"/>
204                         <widget font="Regular;18" halign="center" valign="center" name="currCh1" position="60,40" size="231,24" transparent="1" zPosition="2"/>
205                         <widget font="Regular;18" halign="center" valign="center" name="currCh2" position="291,40" size="231,24" transparent="1" zPosition="2"/>
206                         <widget font="Regular;18" halign="center" valign="center" name="currCh3" position="522,40" size="231,24" transparent="1" zPosition="2"/>
207                         <widget font="Regular;18" halign="center" valign="center" name="currCh4" position="753,40" size="231,24" transparent="1" zPosition="2"/>
208                         <widget font="Regular;18" halign="center" valign="center" name="currCh5" position="984,40" size="231,24" transparent="1" zPosition="2"/>
209                         <widget backgroundColor="#10444649" name="Active1" position="60,80" size="225,560" transparent="0" zPosition="3"/>
210                         <widget backgroundColor="#10444649" name="Active2" position="291,80" size="225,560" transparent="0" zPosition="3"/>
211                         <widget backgroundColor="#10444649" name="Active3" position="522,80" size="225,560" transparent="0" zPosition="3"/>
212                         <widget backgroundColor="#10444649" name="Active4" position="753,80" size="225,560" transparent="0" zPosition="3"/>
213                         <widget backgroundColor="#10444649" name="Active5" position="984,80" size="225,560" transparent="0" zPosition="3"/>
214                         <widget itemHeight="70" name="epg_list1" position="60,80" scrollbarMode="showOnDemand" size="225,560" transparent="1" zPosition="4"/>
215                         <widget itemHeight="70" name="epg_list2" position="291,80" scrollbarMode="showOnDemand" size="225,560" transparent="1" zPosition="4"/>
216                         <widget itemHeight="70" name="epg_list3" position="522,80" scrollbarMode="showOnDemand" size="225,560" transparent="1" zPosition="4"/>
217                         <widget itemHeight="70" name="epg_list4" position="753,80" scrollbarMode="showOnDemand" size="225,560" transparent="1" zPosition="4"/>
218                         <widget itemHeight="70" name="epg_list5" position="984,80" scrollbarMode="showOnDemand" size="225,560" transparent="1" zPosition="4"/>
219                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/buttons.png" position="60,655" size="430,24"/>
220                         <widget backgroundColor="background" font="Regular;18" foregroundColor="#ffc000" position="500,655" render="Label" size="200,24" source="global.CurrentTime" transparent="1" valign="center" zPosition="3">     
221                                 <convert type="ClockToText">Format:%H:%M  %a %d. %b</convert>
222                         </widget>
223                 </screen>"""
224         elif sz_w == 1024:
225                 skin = """
226                 <screen flags="wfNoBorder" name="Merlin_PG" position="0,0" size="1024,576" title="Merlin Program Guide">
227                 <!-- DO NOT CHANGE THIS LINE !!!!!!!!!!!!!!! --><widget enableWrapAround="0" itemHeight="25" name="prg_list" position="-200,-200" size="50,100"/>
228                         <widget font="Regular;18" halign="center" valign="center" name="currCh1" position="50,40" size="231,24" transparent="1" zPosition="2"/>
229                         <widget font="Regular;18" halign="center" valign="center" name="currCh2" position="281,40" size="231,24" transparent="1" zPosition="2"/>
230                         <widget font="Regular;18" halign="center" valign="center" name="currCh3" position="512,40" size="231,24" transparent="1" zPosition="2"/>
231                         <widget font="Regular;18" halign="center" valign="center" name="currCh4" position="743,40" size="231,24" transparent="1" zPosition="2"/>
232                         <widget backgroundColor="#10444649" name="Active1" position="50,80" size="225,420" transparent="0" zPosition="3"/>
233                         <widget backgroundColor="#10444649" name="Active2" position="281,80" size="225,420" transparent="0" zPosition="3"/>
234                         <widget backgroundColor="#10444649" name="Active3" position="512,80" size="225,420" transparent="0" zPosition="3"/>
235                         <widget backgroundColor="#10444649" name="Active4" position="743,80" size="225,420" transparent="0" zPosition="3"/>
236                         <widget itemHeight="70" name="epg_list1" position="50,80" scrollbarMode="showOnDemand" size="225,420" transparent="1" zPosition="4"/>
237                         <widget itemHeight="70" name="epg_list2" position="281,80" scrollbarMode="showOnDemand" size="225,420" transparent="1" zPosition="4"/>
238                         <widget itemHeight="70" name="epg_list3" position="512,80" scrollbarMode="showOnDemand" size="225,420" transparent="1" zPosition="4"/>
239                         <widget itemHeight="70" name="epg_list4" position="743,80" scrollbarMode="showOnDemand" size="225,420" transparent="1" zPosition="4"/>
240                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/buttons.png" position="50,518" size="430,24"/>
241                         <widget backgroundColor="background" font="Regular;18" foregroundColor="#ffc000" position="490,518" render="Label" size="200,24" source="global.CurrentTime" transparent="1" valign="center" zPosition="3">     
242                                 <convert type="ClockToText">Format:%H:%M  %a %d. %b</convert>
243                         </widget>
244                         <!-- <widget font="Regular;18" name="fullEventInfo" position="300,200" size="300,200" transparent="0" zPosition="12"/> -->
245                 </screen>"""
246         else:
247                 skin = """
248                 <screen flags="wfNoBorder" name="Merlin_PG" position="0,0" size="720,576" title="Merlin Program Guide">
249                 <!-- DO NOT CHANGE THIS LINE !!!!!!!!!!!!!!! --><widget enableWrapAround="0" itemHeight="25" name="prg_list" position="-200,-200" size="50,100"/>
250                         <widget font="Regular;18" halign="center" valign="center" name="currCh1" position="50,35" size="155,36" transparent="1" zPosition="2"/>
251                         <widget font="Regular;18" halign="center" valign="center" name="currCh2" position="205,35" size="155,36" transparent="1" zPosition="2"/>
252                         <widget font="Regular;18" halign="center" valign="center" name="currCh3" position="360,35" size="155,36" transparent="1" zPosition="2"/>
253                         <widget font="Regular;18" halign="center" valign="center" name="currCh4" position="515,35" size="155,36" transparent="1" zPosition="2"/>
254                         <widget backgroundColor="#10444649" name="Active1" position="50,90" size="155,420" transparent="0" zPosition="3"/>
255                         <widget backgroundColor="#10444649" name="Active2" position="205,90" size="155,420" transparent="0" zPosition="3"/>
256                         <widget backgroundColor="#10444649" name="Active3" position="360,90" size="155,420" transparent="0" zPosition="3"/>
257                         <widget backgroundColor="#10444649" name="Active4" position="515,90" size="155,420" transparent="0" zPosition="3"/>
258                         <widget itemHeight="70" name="epg_list1" position="50,90" scrollbarMode="showOnDemand" size="155,420" transparent="1" zPosition="4"/>
259                         <widget itemHeight="70" name="epg_list2" position="205,90" scrollbarMode="showOnDemand" size="155,420" transparent="1" zPosition="4"/>
260                         <widget itemHeight="70" name="epg_list3" position="360,90" scrollbarMode="showOnDemand" size="155,420" transparent="1" zPosition="4"/>
261                         <widget itemHeight="70" name="epg_list4" position="515,90" scrollbarMode="showOnDemand" size="155,420" transparent="1" zPosition="4"/>
262                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/buttons.png" position="50,518" size="430,24"/>
263                         <widget backgroundColor="background" font="Regular;18" foregroundColor="#ffc000" position="490,518" render="Label" size="200,24" source="global.CurrentTime" transparent="1" valign="center" zPosition="3">     
264                                 <convert type="ClockToText">Format:%H:%M  %a %d. %b</convert>
265                         </widget>
266                 </screen>"""
267
268         def __init__(self, session, servicelist=None):
269                 Screen.__init__(self, session)
270                 self.session = session
271                 self.srvList = servicelist
272                 self.myServices = []
273                 self.myBqts = []
274                 self.list = []
275                 self.chCount = 0
276                 self.ActiveEPG = 1
277                 if getDesktop(0).size().width() == 1280:
278                         self.Fields = 6
279                         self["currCh5"] = Label(" ")
280                         self["Active5"] = Label(" ")
281                         self["epg_list5"] = MerlinEPGList(type = EPG_TYPE_SINGLE, selChangedCB = self.onSelectionChanged, timer = session.nav.RecordTimer)
282                 else:
283                         self.Fields = 5
284                 self.CheckForEPG = eTimer()
285                 self.CheckForEPG.callback.append(self.CheckItNow)
286                 self.AutoPrime = eTimer()
287                 self.AutoPrime.callback.append(self.go2Primetime)
288                 self["prg_list"] = MenuList(self.getChannels())
289                 self["fullEventInfo"] = Label(" ")
290                 self["currCh1"] = Label(" ")
291                 self["currCh2"] = Label(" ")
292                 self["currCh3"] = Label(" ")
293                 self["currCh4"] = Label(" ")
294                 self["Active1"] = Label(" ")
295                 self["Active2"] = Label(" ")
296                 self["Active3"] = Label(" ")
297                 self["Active4"] = Label(" ")
298                 self["epg_list1"] = MerlinEPGList(type = EPG_TYPE_SINGLE, selChangedCB = self.onSelectionChanged, timer = session.nav.RecordTimer)
299                 self["epg_list2"] = MerlinEPGList(type = EPG_TYPE_SINGLE, selChangedCB = self.onSelectionChanged, timer = session.nav.RecordTimer)
300                 self["epg_list3"] = MerlinEPGList(type = EPG_TYPE_SINGLE, selChangedCB = self.onSelectionChanged, timer = session.nav.RecordTimer)
301                 self["epg_list4"] = MerlinEPGList(type = EPG_TYPE_SINGLE, selChangedCB = self.onSelectionChanged, timer = session.nav.RecordTimer)
302                 self["actions"] = ActionMap(["OkCancelActions", "EPGSelectActions", "DirectionActions", "ColorActions", "MenuActions", "NumberActions", "HelpActions", "InfobarActions"], {
303                                                 "ok": self.UserOK, 
304                                                 "cancel": self.close,
305                                                 "nextBouquet": self.AllUp,
306                                                 "prevBouquet": self.AllDown,
307                                                 "nextService": self.NextPage,
308                                                 "prevService": self.PrevPage,
309                                                 "right": self.right,
310                                                 "rightRepeated": self.right,
311                                                 "left": self.left,
312                                                 "leftRepeated": self.left,
313                                                 "up": self.up,
314                                                 "upRepeated": self.up,
315                                                 "down": self.down,
316                                                 "downRepeated": self.down,
317                                                 "info": self.showEventInfo,
318                                                 "red": self.ZapTo,
319                                                 "green": self.timerAdd,
320                                                 "blue": self.ZapForRefresh,
321                                                 "yellow": self.go2Primetime,
322                                                 "menu": self.menuClicked,
323                                                 "displayHelp": self.myhelp,
324                                                 "0": self.go2now,
325                                                 "1": self.go2first,
326                                                 "7": self.findPrvBqt,
327                                                 "9": self.findNextBqt,
328                                                 "showMovies": self.editCurTimer
329                                                 },-2)
330                 self.onLayoutFinish.append(self.onLayoutReady)
331
332         def getChannels(self):
333                 indx = 0
334                 serviceHandler = eServiceCenter.getInstance()
335                 services = serviceHandler.list(eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25) FROM BOUQUET "bouquets.tv" ORDER BY bouquet'))
336                 bouquets = services and services.getContent("SN", True)
337                 for bouquet in bouquets:
338                         services = serviceHandler.list(eServiceReference(bouquet[0]))
339                         channels = services and services.getContent("SN", True)
340                         for channel in channels:
341                                 if not channel[0].startswith("1:64:"):
342                                         indx = indx + 1
343                                         self.list.append(str(indx) + ". " + channel[1].replace('\xc2\x86', '').replace('\xc2\x87', ''))
344                                         self.myServices.append(channel)
345                                         self.myBqts.append(bouquet)
346                 self.chCount = indx - 1
347                 return self.list
348
349         def onLayoutReady(self):
350                 service = self.session.nav.getCurrentService()
351                 info = service and service.info()
352                 if (info is not None) and not(config.plugins.MerlinEPG.StartFirst.value):
353                         nameROH = info.getName().replace('\xc2\x86', '').replace('\xc2\x87', '')
354                         for idx in range(1, len(self.list)):
355                                 name = str(idx) + ". " + nameROH
356                                 if name == self.list[idx-1]:
357                                         break
358                         self["prg_list"].moveToIndex(idx-1)
359                 else:
360                         self["prg_list"].moveToIndex(0)
361                 self.updateInfos()
362
363         def updateInfos(self):
364                 if self.AutoPrime.isActive():
365                         self.AutoPrime.stop()
366                 self.displayActiveEPG()
367                 prgIndex = self["prg_list"].getSelectionIndex()
368                 CurrentPrg = self.myServices[prgIndex]
369                 self["currCh1"].setText(str(CurrentPrg[1]))
370                 l = self["epg_list1"]
371                 l.recalcEntrySize()
372                 myService = ServiceReference(CurrentPrg[0])
373                 l.fillSingleEPG(myService)
374                 prgIndex = prgIndex + 1
375                 if prgIndex < (self.chCount+1):
376                         self["epg_list2"].show()
377                         CurrentPrg = self.myServices[prgIndex]
378                         self["currCh2"].setText(str(CurrentPrg[1]))
379                         l = self["epg_list2"]
380                         l.recalcEntrySize()
381                         myService = ServiceReference(CurrentPrg[0])
382                         l.fillSingleEPG(myService)
383                 else:
384                         self["currCh2"].setText(str(" "))
385                         self["epg_list2"].hide()
386                 prgIndex = prgIndex + 1
387                 if prgIndex < (self.chCount+1):
388                         self["epg_list3"].show()
389                         CurrentPrg = self.myServices[prgIndex]
390                         self["currCh3"].setText(str(CurrentPrg[1]))
391                         l = self["epg_list3"]
392                         l.recalcEntrySize()
393                         myService = ServiceReference(CurrentPrg[0])
394                         l.fillSingleEPG(myService)
395                 else:
396                         self["currCh3"].setText(str(" "))
397                         self["epg_list3"].hide()
398                 prgIndex = prgIndex + 1
399                 if prgIndex < (self.chCount+1):
400                         self["epg_list4"].show()
401                         CurrentPrg = self.myServices[prgIndex]
402                         self["currCh4"].setText(str(CurrentPrg[1]))
403                         CurrentPrg = self.myServices[prgIndex]
404                         self["currCh4"].setText(str(CurrentPrg[1]))
405                         l = self["epg_list4"]
406                         l.recalcEntrySize()
407                         myService = ServiceReference(CurrentPrg[0])
408                         l.fillSingleEPG(myService)
409                 else:
410                         self["currCh4"].setText(str(" "))
411                         self["epg_list4"].hide()
412                 if self.Fields == 6:
413                         prgIndex = prgIndex + 1
414                         if prgIndex < (self.chCount+1):
415                                 self["epg_list5"].show()
416                                 CurrentPrg = self.myServices[prgIndex]
417                                 self["currCh5"].setText(str(CurrentPrg[1]))
418                                 l = self["epg_list5"]
419                                 l.recalcEntrySize()
420                                 myService = ServiceReference(CurrentPrg[0])
421                                 l.fillSingleEPG(myService)
422                         else:
423                                 self["currCh5"].setText(str(" "))
424                                 self["epg_list5"].hide()
425                 if config.plugins.MerlinEPG.AutoPT.value:
426                          self.AutoPrime.start(500)
427
428         def onSelectionChanged(self):           
429                 curEV = self["epg_list"+str(self.ActiveEPG)].getCurrent()
430                 event = curEV[0]
431                 ext = event and event.getExtendedDescription() or ""
432                 self["fullEventInfo"].setText(str(ext))
433
434         def NextPage(self):
435                 self["prg_list"].pageDown()
436                 self.ActiveEPG = 1
437                 self.updateInfos()
438
439         def PrevPage(self):
440                 self["prg_list"].pageUp()
441                 self.ActiveEPG = 1
442                 self.updateInfos()
443
444         def displayActiveEPG(self):
445                 for xA in range(1,self.Fields):
446                         if xA == self.ActiveEPG:
447                                 self["Active"+str(xA)].show()
448                         else:
449                                 self["Active"+str(xA)].hide()
450
451         def getActivePrg(self):
452                 return self["prg_list"].getSelectionIndex()+(self.ActiveEPG-1)
453
454         def ZapTo(self):
455                 if (self.getActivePrg() > self.chCount) or (self.srvList==None):
456                         return
457                 CurrentPrg = self.myServices[self.getActivePrg()]
458                 CurrentBqt = self.myBqts[self.getActivePrg()]
459                 myService = ServiceReference(CurrentPrg[0])
460                 myB = ServiceReference(CurrentBqt[0])
461                 self.srvList.clearPath()
462                 if self.srvList.bouquet_root != myB.ref:
463                         self.srvList.enterPath(self.srvList.bouquet_root)
464                 self.srvList.enterPath(myB.ref)
465                 self.srvList.setCurrentSelection(myService.ref)
466                 self.srvList.zap()
467                 self.close()
468
469         def ZapForRefresh(self):
470                 if (self.getActivePrg() > self.chCount) or (self.srvList==None):
471                         return
472                 CurrentPrg = self.myServices[self.getActivePrg()]
473                 myService = ServiceReference(CurrentPrg[0])
474                 self.session.nav.playService(myService.ref)
475                 self.CheckForEPG.start(4000, True)
476
477         def CheckItNow(self):
478                 self.CheckForEPG.stop()
479                 CurrentPrg = self.myServices[self.getActivePrg()]
480                 l = self["epg_list"+str(self.ActiveEPG)]
481                 l.recalcEntrySize()
482                 myService = ServiceReference(CurrentPrg[0])
483                 l.fillSingleEPG(myService)
484
485         def up(self):
486                 self["epg_list"+str(self.ActiveEPG)].moveUp()
487
488         def down(self):
489                 self["epg_list"+str(self.ActiveEPG)].moveDown()
490
491         def AllUp(self):
492                 if config.plugins.MerlinEPG.PageUDonBouquets.value:
493                         for xU in range(1,self.Fields):
494                                 self["epg_list"+str(xU)].instance.moveSelection(self["epg_list"+str(xU)].instance.pageUp)
495                 else:
496                         for xU in range(1,self.Fields):
497                                 self["epg_list"+str(xU)].moveUp()
498
499         def AllDown(self):
500                 if config.plugins.MerlinEPG.PageUDonBouquets.value:
501                         for xU in range(1,self.Fields):
502                                 self["epg_list"+str(xU)].instance.moveSelection(self["epg_list"+str(xU)].instance.pageDown)
503                 else:
504                         for xD in range(1,self.Fields):
505                                 self["epg_list"+str(xD)].moveDown()
506
507         def go2now(self):
508                 for xD in range(1,self.Fields):
509                         self["epg_list"+str(xD)].instance.moveSelection(self["epg_list"+str(xD)].instance.moveTop)
510
511         def go2first(self):
512                 self["prg_list"].moveToIndex(0)
513                 self.ActiveEPG = 1
514                 self.updateInfos()
515
516         def left(self):
517                 if self.ActiveEPG > 1:
518                         self.ActiveEPG = self.ActiveEPG - 1
519                         self.displayActiveEPG()
520                 else:
521                         self["prg_list"].pageUp()
522                         self.ActiveEPG = (self.Fields-1)
523                         self.updateInfos()
524                 self.onSelectionChanged()
525
526         def right(self):
527                 if self.ActiveEPG < (self.Fields-1):
528                         self.ActiveEPG = self.ActiveEPG + 1
529                         self.displayActiveEPG()
530                 else:
531                         self.NextPage()
532                 self.onSelectionChanged()
533                 
534         def showEventInfo(self):
535                 if not IMDbPresent:
536                         self.showConfirmedInfo([None,"Ei"])
537                 else:
538                         self.session.openWithCallback(self.showConfirmedInfo, ChoiceBox, title=_("Select Info type..."), list=[(_("Standard EPG info"), "Ei"),(_("IMBd info"), "Ii")])
539
540         def showConfirmedInfo(self,answer):
541                 curEV = self["epg_list"+str(self.ActiveEPG)].getCurrent()
542                 event = curEV[0]
543                 service = curEV[1]
544                 answer = answer and answer[1]
545                 if answer == "Ei":
546                         if event is not None:
547                                 self.session.open(EventViewSimple, event, service)
548                 if answer == "Ii":
549                         if event is not None:
550                                 IeventName=event.getEventName()
551                                 self.session.open(IMDB, IeventName)
552
553         def timerAdd(self):
554                 if not AutoTimerPresent:
555                         self.AddConfirmedTimer([None,"NT"])
556                 else:
557                         self.session.openWithCallback(self.AddConfirmedTimer, ChoiceBox, title=_("Select timer type..."), list=[(_("Standard timer"), "NT"),(_("AutoTimer"), "AT"),(_("View AutoTimers"), "ATV")])
558
559         def AddConfirmedTimer(self, answer):
560                 cur = self["epg_list"+str(self.ActiveEPG)].getCurrent()
561                 event = cur[0]
562                 serviceref = cur[1]
563                 if event is None:
564                         return
565                 eventid = event.getEventId()
566                 refstr = serviceref.ref.toString()
567                 answer = answer and answer[1]
568                 if answer == "AT":
569                         addAutotimerFromEvent(self.session,evt=event,service=serviceref)
570                 elif answer == "NT":
571                         for timer in self.session.nav.RecordTimer.timer_list:
572                                 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
573                                         cb_func = lambda ret : not ret or self.removeTimer(timer)
574                                         self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
575                                         break
576                         else:
577                                 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
578                                 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
579                 elif answer == "ATV":
580                         AutoTimerView(self.session)
581
582         def removeTimer(self, timer):
583                 timer.afterEvent = AFTEREVENT.NONE
584                 self.session.nav.RecordTimer.removeEntry(timer)
585
586         def finishedAdd(self, answer):
587                 if answer[0]:
588                         entry = answer[1]
589                         simulTimerList = self.session.nav.RecordTimer.record(entry)
590                         if simulTimerList is not None:
591                                 for x in simulTimerList:
592                                         if x.setAutoincreaseEnd(entry):
593                                                 self.session.nav.RecordTimer.timeChanged(x)
594                                 simulTimerList = self.session.nav.RecordTimer.record(entry)
595                                 if simulTimerList is not None:
596                                         self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
597         
598         def finishSanityCorrection(self, answer):
599                 self.finishedAdd(answer)
600
601         def menuClicked(self):
602                 self.session.open(MerlinPGsetup)
603
604         def findNextBqt(self):
605                 CurrIdx = 0
606                 CurrBqt = self.myBqts[self.getActivePrg()]
607                 for CurrIdx in range(self.getActivePrg(),self.chCount):
608                         NewBqt = self.myBqts[CurrIdx]
609                         if NewBqt != CurrBqt:
610                                 break
611                 self["prg_list"].moveToIndex(CurrIdx)
612                 self.updateInfos()
613
614         def findPrvBqt(self):
615                 CurrIdx = 0
616                 CurrBqt = self.myBqts[self.getActivePrg()]
617                 for CurrIdx in range(self.getActivePrg(),-1,-1):
618                         NewBqt = self.myBqts[CurrIdx]
619                         if NewBqt != CurrBqt:
620                                 break
621                 self["prg_list"].moveToIndex(CurrIdx)
622                 self.updateInfos()
623
624         def go2Primetime(self):
625                 if self.AutoPrime.isActive():
626                         self.AutoPrime.stop()
627                 for xFL in range(1, self.Fields):
628                         self["epg_list"+str(xFL)].instance.moveSelection(self["epg_list"+str(xFL)].instance.moveTop)
629                         for i in range(0,(self.Fields*3)):
630                                 self["epg_list"+str(xFL)].foudPrimetime()
631
632         def myhelp(self):
633                 self.session.open(ShowMe, "/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/help.jpg")
634
635         def UserOK(self):
636                 if config.plugins.MerlinEPG.ZapOnOK.value:
637                         self.ZapTo()
638                 else:
639                         self.showConfirmedInfo([None,"Ei"])
640
641         def editCurTimer(self):
642                 cur = self["epg_list"+str(self.ActiveEPG)].getCurrent()
643                 event = cur[0]
644                 serviceref = cur[1]
645                 if event is None:
646                         return
647                 eventid = event.getEventId()
648                 refstr = serviceref.ref.toString()
649                 for timer in self.session.nav.RecordTimer.timer_list:
650                         if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
651                                 self.session.open(TimerEntry, timer)
652
653
654
655 class Merlin_PGd(Screen):
656         try:
657                 sz_w = getDesktop(0).size().width()
658         except:
659                 sz_w = 720
660         if sz_w == 1280:
661                 skin = """
662                 <screen backgroundColor="#ffffffff" flags="wfNoBorder" name="Merlin_PG" position="0,0" size="1280,720" title="Merlin Program Guide">
663                         <widget backgroundColor="#ffffffff" position="0,0" render="Pig" size="520,292" source="session.VideoPicture" zPosition="-1"/>
664                         <eLabel backgroundColor="#00111112" position="0,292" size="520,450" zPosition="1"/>
665                         <eLabel backgroundColor="#00111112" position="520,0" size="760,720" zPosition="1"/>
666                         <ePixmap alphatest="on" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/epg.png" position="1136,105" size="85,77" zPosition="5"/>
667                         <ePixmap alphatest="on" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/channels.png" position="395,306" size="80,80" zPosition="5"/>
668                         <ePixmap alphatest="on" name="red" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/red.png" position="70,635" size="35,25" zPosition="2"/>
669                         <ePixmap alphatest="on" name="green" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/green.png" position="275,635" size="35,25" zPosition="2"/>
670                         <eLabel backgroundColor="#00111112" font="Regular;18" position="110,635" size="131,24" text="ZAP" transparent="1" zPosition="2"/>
671                         <eLabel backgroundColor="#00111112" font="Regular;18" position="315,635" size="191,24" text="TIMERS" transparent="1" zPosition="2"/>
672                         <widget itemHeight="25" name="prg_list" position="75,306" scrollbarMode="showNever" size="400,300" transparent="1" zPosition="4"/>
673                         <widget itemHeight="27" name="epg_list" position="570,105" scrollbarMode="showNever" size="651,540" transparent="1" zPosition="4"/>
674                         <widget backgroundColor="#00111112" font="Regular;22" foregroundColor="#fcc000" halign="center" name="currCh" position="555,55" size="651,24" transparent="1" valign="center" zPosition="2"/>
675                 </screen>"""
676         elif sz_w == 1024:
677                 skin = """
678                 <screen backgroundColor="#ffffffff" flags="wfNoBorder" name="Merlin_PG" position="0,0" size="1024,576" title="Merlin Program Guide">
679                         <widget backgroundColor="#ffffffff" position="0,0" render="Pig" size="384,216" source="session.VideoPicture" zPosition="-1"/>
680                         <eLabel backgroundColor="#00111112" position="0,216" size="384,366" zPosition="1"/>
681                         <eLabel backgroundColor="#00111112" position="384,0" size="720,576" zPosition="1"/>
682                         <ePixmap alphatest="on" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/epg.png" position="900,80" size="85,77" zPosition="5"/>
683                         <ePixmap alphatest="on" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/channels.png" position="292,228" size="80,80" zPosition="5"/>
684                         <ePixmap alphatest="on" name="red" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/red.png" position="40,520" size="35,25" zPosition="3"/>
685                         <ePixmap alphatest="on" name="green" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/green.png" position="185,520" size="35,25" zPosition="3"/>
686                         <eLabel backgroundColor="#00111112" font="Regular;18" position="80,520" size="92,24" text="ZAP" transparent="1" zPosition="2"/>
687                         <eLabel backgroundColor="#00111112" font="Regular;18" position="230,520" size="141,24" text="TIMERS" transparent="1" zPosition="2"/>
688                         <widget itemHeight="25" name="prg_list" position="40,228" scrollbarMode="showNever" size="332,275" transparent="1" zPosition="4"/>
689                         <widget itemHeight="28" name="epg_list" position="395,80" scrollbarMode="showNever" size="590,448" transparent="1" zPosition="4"/>
690                         <widget backgroundColor="#00111112" font="Regular;21" foregroundColor="#fcc000" halign="center" name="currCh" position="395,40" size="590,24" transparent="1" valign="center" zPosition="4"/>
691                 </screen>"""
692         else:
693                 skin = """
694                 <screen flags="wfNoBorder" name="Merlin_PG" position="0,0" size="720,576" title="Merlin Program Guide">
695                         <ePixmap alphatest="on" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/mpgbgSD-fs8.png" position="0,0" size="720,576" zPosition="1"/>
696                         <ePixmap alphatest="on" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/red.png" position="165,90" size="35,25" zPosition="2"/>
697                         <ePixmap alphatest="on" pixmap="/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/green.png" position="165,110" size="35,25" zPosition="2"/>
698                         <eLabel backgroundColor="#1f1f1f" font="Regular;15" foregroundColor="#f0f0f0" position="205,93" size="70,20" text="ZAP" transparent="1" zPosition="2"/>
699                         <eLabel backgroundColor="#1f1f1f" font="Regular;15" foregroundColor="#f0f0f0" position="205,113" size="70,20" text="TIMERS" transparent="1" zPosition="2"/>
700                         <widget name="prg_list" position="342,63" scrollbarMode="showOnDemand" size="327,150" zPosition="2" itemHeight="25"/>
701                         <widget name="epg_list" position="57,238" scrollbarMode="showOnDemand" size="612,270" zPosition="2" itemHeight="27"/>
702                         <widget font="Regular;22" foregroundColor="#ffc000" halign="center" name="currCh" position="57,133" size="252,66" transparent="1" valign="center" zPosition="2"/>
703                         <widget font="LCD;28" halign="left" position="60,95" render="Label" size="91,32" source="global.CurrentTime" transparent="1" zPosition="3">
704                                 <convert type="ClockToText">Default</convert>
705                         </widget>       
706                         <widget font="Regular;16" position="60,65" render="Label" size="276,26" source="global.CurrentTime" transparent="1" zPosition="3">
707                                 <convert type="ClockToText">Date</convert>
708                         </widget>
709                 </screen>"""
710
711         def __init__(self, session, servicelist=None):
712                 Screen.__init__(self, session)
713                 self.session = session
714                 self.myServices = []
715                 self.myBqts = []
716                 self.list = []
717                 self.srvList = servicelist
718                 self.CheckForEPG = eTimer()
719                 self.CheckForEPG.callback.append(self.CheckItNow)
720                 self["currCh"] = Label(_("Channel"))
721                 self["fullEventInfo"] = Label(" ")
722                 self["prg_list"] = MenuList(self.getChannels())
723                 self["epg_list"] = EPGList(type = EPG_TYPE_SINGLE, selChangedCB = self.onSelectionChanged, timer = session.nav.RecordTimer)
724                 self["actions"] = ActionMap(["OkCancelActions", "EPGSelectActions", "ColorActions", "DirectionActions", "MenuActions", "HelpActions", "InfobarActions"], {
725                                                                         "ok": self.ok, 
726                                                                         "cancel": self.close,
727                                                                         "nextBouquet": self.prgDown,
728                                                                         "prevBouquet": self.prgUp,
729                                                                         "nextService": self.prgPlus,
730                                                                         "prevService": self.prgMinus,
731                                                                         "red": self.ZapTo,
732                                                                         "green": self.timerAdd,
733                                                                         "blue": self.ZapForRefresh,
734                                                                         "yellow": self.go2now,
735                                                                         "info": self.ok,
736                                                                         "menu": self.menuClicked,
737                                                                         "displayHelp": self.myhelp,
738                                                                         "right": self.right,
739                                                                         "rightRepeated": self.right,
740                                                                         "left": self.left,
741                                                                         "leftRepeated": self.left,
742                                                                         "up": self.up,
743                                                                         "upRepeated": self.up,
744                                                                         "down": self.down,
745                                                                         "downRepeated": self.down,
746                                                                         "showMovies": self.editCurTimer
747                                                                         },-2)
748                 self.onLayoutFinish.append(self.onLayoutReady)
749
750         def onLayoutReady(self):
751                 service = self.session.nav.getCurrentService()
752                 info = service and service.info()
753                 if (info is not None) and not(config.plugins.MerlinEPG.StartFirst.value):
754                         nameROH = info.getName().replace('\xc2\x86', '').replace('\xc2\x87', '')
755                         for idx in range(1, len(self.list)):
756                                 name = str(idx) + ". " + nameROH
757                                 if name == self.list[idx-1]:
758                                         break
759                         self["prg_list"].moveToIndex(idx-1)
760                 else:
761                         self["prg_list"].moveToIndex(0)
762                 self.updateInfos()
763
764         def onSelectionChanged(self):
765                 curEV = self["epg_list"].getCurrent()
766                 event = curEV[0]
767                 ext = event and event.getExtendedDescription() or ""
768                 self["fullEventInfo"].setText(str(ext))
769
770         def prgUp(self):
771                 self["prg_list"].down()
772                 self.updateInfos()
773         
774         def prgDown(self):
775                 self["prg_list"].up()
776                 self.updateInfos()
777
778         def prgPlus(self):
779                 self["prg_list"].pageDown()
780                 self.updateInfos()
781
782         def prgMinus(self):
783                 self["prg_list"].pageUp()
784                 self.updateInfos()
785
786         def getChannels(self):
787                 indx = 0
788                 serviceHandler = eServiceCenter.getInstance()
789                 services = serviceHandler.list(eServiceReference('1:7:1:0:0:0:0:0:0:0:(type == 1) || (type == 17) || (type == 195) || (type == 25) FROM BOUQUET "bouquets.tv" ORDER BY bouquet'))
790                 bouquets = services and services.getContent("SN", True)
791                 for bouquet in bouquets:
792                         services = serviceHandler.list(eServiceReference(bouquet[0]))
793                         channels = services and services.getContent("SN", True)
794                         for channel in channels:
795                                 if not channel[0].startswith("1:64:"):
796                                         indx = indx + 1
797                                         self.list.append(str(indx) + ". " + channel[1].replace('\xc2\x86', '').replace('\xc2\x87', ''))
798                                         self.myServices.append(channel)
799                                         self.myBqts.append(bouquet)
800                 return self.list
801
802         def updateInfos(self):
803                 l = self["epg_list"]
804                 l.recalcEntrySize()
805                 CurrentPrg = self.myServices[self["prg_list"].getSelectionIndex()]
806                 self["currCh"].setText(str(CurrentPrg[1]))
807                 myService = ServiceReference(CurrentPrg[0])
808                 l.fillSingleEPG(myService)
809
810         def ok(self):
811                 curEV = self["epg_list"].getCurrent()
812                 event = curEV[0]
813                 service = curEV[1]
814                 if event is not None:
815                         self.session.open(EventViewSimple, event, service)
816                         
817         def ZapTo(self):
818                 if self.srvList==None:
819                         return
820                 CurrentPrg = self.myServices[self["prg_list"].getSelectionIndex()]
821                 CurrentBqt = self.myBqts[self["prg_list"].getSelectionIndex()]
822                 myService = ServiceReference(CurrentPrg[0])
823                 myB = ServiceReference(CurrentBqt[0])
824                 self.srvList.clearPath()
825                 if self.srvList.bouquet_root != myB.ref:
826                         self.srvList.enterPath(self.srvList.bouquet_root)
827                 self.srvList.enterPath(myB.ref)
828                 self.srvList.setCurrentSelection(myService.ref)
829                 self.srvList.zap()
830                 self.close()
831
832         def ZapForRefresh(self):
833                 if self.srvList==None:
834                         return
835                 CurrentPrg = self.myServices[self["prg_list"].getSelectionIndex()]
836                 myService = ServiceReference(CurrentPrg[0])
837                 self.session.nav.playService(myService.ref)
838                 self.CheckForEPG.start(4000, True)
839
840         def CheckItNow(self):
841                 self.CheckForEPG.stop()
842                 self.updateInfos()
843                         
844         def timerAdd(self):
845                 if not AutoTimerPresent:
846                         self.AddConfirmedTimer([None,"NT"])
847                 else:
848                         self.session.openWithCallback(self.AddConfirmedTimer, ChoiceBox, title=_("Select timer type..."), list=[(_("Standard timer"), "NT"),(_("AutoTimer"), "AT"),(_("View AutoTimers"), "ATV")])
849
850         def AddConfirmedTimer(self, answer):
851                 cur = self["epg_list"].getCurrent()
852                 event = cur[0]
853                 serviceref = cur[1]
854                 if event is None:
855                         return
856                 eventid = event.getEventId()
857                 refstr = serviceref.ref.toString()
858                 answer = answer and answer[1]
859                 if answer == "AT":
860                         addAutotimerFromEvent(self.session,evt=event,service=serviceref)
861                 elif answer == "NT":
862                         for timer in self.session.nav.RecordTimer.timer_list:
863                                 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
864                                         cb_func = lambda ret : not ret or self.removeTimer(timer)
865                                         self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
866                                         break
867                         else:
868                                 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
869                                 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
870                 elif answer == "ATV":
871                         AutoTimerView(self.session)
872
873         def removeTimer(self, timer):
874                 timer.afterEvent = AFTEREVENT.NONE
875                 self.session.nav.RecordTimer.removeEntry(timer)
876
877         def finishedAdd(self, answer):
878                 if answer[0]:
879                         entry = answer[1]
880                         simulTimerList = self.session.nav.RecordTimer.record(entry)
881                         if simulTimerList is not None:
882                                 for x in simulTimerList:
883                                         if x.setAutoincreaseEnd(entry):
884                                                 self.session.nav.RecordTimer.timeChanged(x)
885                                 simulTimerList = self.session.nav.RecordTimer.record(entry)
886                                 if simulTimerList is not None:
887                                         self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
888
889         def finishSanityCorrection(self, answer):
890                 self.finishedAdd(answer)
891
892         def menuClicked(self):
893                 self.session.open(MerlinPGsetup)
894
895         def go2now(self):
896                 self["epg_list"].instance.moveSelection(self["epg_list"].instance.moveTop)
897
898         def myhelp(self):
899                 self.session.open(ShowMe, "/usr/lib/enigma2/python/Plugins/Extensions/MerlinEPG/help.jpg")
900
901         def up(self):
902                 self["epg_list"].moveUp()
903
904         def down(self):
905                 self["epg_list"].moveDown()
906
907         def left(self):
908                 self["epg_list"].instance.moveSelection(self["epg_list"].instance.pageUp)
909
910         def right(self):
911                 self["epg_list"].instance.moveSelection(self["epg_list"].instance.pageDown)
912
913         def editCurTimer(self):
914                 cur = self["epg_list"].getCurrent()
915                 event = cur[0]
916                 serviceref = cur[1]
917                 if event is None:
918                         return
919                 eventid = event.getEventId()
920                 refstr = serviceref.ref.toString()
921                 for timer in self.session.nav.RecordTimer.timer_list:
922                         if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
923                                 self.session.open(TimerEntry, timer)
924
925
926
927
928
929
930