remove debug
[enigma2.git] / lib / python / Screens / EpgSelection.py
1 from Screen import Screen
2 from Components.Button import Button
3 from Components.Pixmap import Pixmap
4 from Components.Label import Label
5 from Components.EpgList import *
6 from Components.ActionMap import ActionMap
7 from Components.ScrollLabel import ScrollLabel
8 from Screens.EventView import EventViewSimple
9 from TimeDateInput import TimeDateInput
10 from enigma import eServiceReference, eServiceEventPtr
11 from Screens.FixedMenu import FixedMenu
12 from RecordTimer import RecordTimerEntry, parseEvent
13 from TimerEdit import TimerEditList
14 from TimerEntry import TimerEntry
15 from ServiceReference import ServiceReference
16 from Components.config import config, currentConfigSelectionElement
17 from time import localtime, time
18
19 import xml.dom.minidom
20
21 class EPGSelection(Screen):
22         def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
23                 Screen.__init__(self, session)
24                 self.bouquetChangeCB = bouquetChangeCB
25                 self.ask_time = -1 #now
26                 self["key_red"] = Button("")
27                 self.closeRecursive = False
28                 if isinstance(service, str) and eventid != None:
29                         self.type = EPG_TYPE_SIMILAR
30                         self["key_yellow"] = Button()
31                         self["key_blue"] = Button()
32                         self["key_red"] = Button()
33                         self.currentService=service
34                         self.eventid = eventid
35                         self.zapFunc = None
36                 elif isinstance(service, eServiceReference) or isinstance(service, str):
37                         self.type = EPG_TYPE_SINGLE
38                         self["key_yellow"] = Button()
39                         self["key_blue"] = Button()
40                         self.currentService=ServiceReference(service)
41                         self.zapFunc = None
42                 else:
43                         self.skinName = "EPGSelectionMulti"
44                         self.type = EPG_TYPE_MULTI
45                         self["key_yellow"] = Button(_("Prev"))
46                         self["key_blue"] = Button(_("Next"))
47                         self["now_button"] = Pixmap()
48                         self["next_button"] = Pixmap()
49                         self["more_button"] = Pixmap()
50                         self["now_button_sel"] = Pixmap()
51                         self["next_button_sel"] = Pixmap()
52                         self["more_button_sel"] = Pixmap()
53                         self["now_text"] = Label()
54                         self["next_text"] = Label()
55                         self["more_text"] = Label()
56                         self["date"] = Label()
57                         self.services = service
58                         self.zapFunc = zapFunc
59
60                 self["key_green"] = Button(_("Add timer"))
61                 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
62
63                 class ChannelActionMap(ActionMap):
64                         def action(self, contexts, action):
65                                 return ActionMap.action(self, contexts, action)
66
67                 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
68                         {
69                                 "cancel": self.closeScreen,
70                                 "ok": self.eventSelected,
71                                 "timerAdd": self.timerAdd,
72                                 "yellow": self.yellowButtonPressed,
73                                 "blue": self.blueButtonPressed,
74                                 "info": self.infoKeyPressed,
75                                 "red": self.zapTo,
76                                 "input_date_time": self.enterDateTime,
77                                 "nextBouquet": self.nextBouquet,
78                                 "prevBouquet": self.prevBouquet
79                         })
80                 self["actions"].csel = self
81
82                 self.onLayoutFinish.append(self.onCreate)
83
84         def nextBouquet(self):
85                 if self.bouquetChangeCB:
86                         self.bouquetChangeCB(1, self)
87
88         def prevBouquet(self):
89                 if self.bouquetChangeCB:
90                         self.bouquetChangeCB(-1, self)
91
92         def enterDateTime(self):
93                 if self.type == EPG_TYPE_MULTI:
94                         self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput)
95
96         def onDateTimeInputClosed(self, ret):
97                 if len(ret) > 1:
98                         if ret[0]:
99                                 self.ask_time=ret[1]
100                                 self["list"].fillMultiEPG(self.services, ret[1])
101
102         def closeScreen(self):
103                 self.close(self.closeRecursive)
104
105         def infoKeyPressed(self):
106                 cur = self["list"].getCurrent()
107                 event = cur[0]
108                 service = cur[1]
109                 if event is not None:
110                         if self.type != EPG_TYPE_SIMILAR:
111                                 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
112                         else:
113                                 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
114
115         def openSimilarList(self, eventid, refstr):
116                 self.session.open(EPGSelection, refstr, None, eventid)
117
118         def setServices(self, services):
119                 self.services = services
120                 self.onCreate()
121
122         #just used in multipeg
123         def onCreate(self):
124                 l = self["list"]
125                 l.recalcEntrySize()
126                 if self.type == EPG_TYPE_MULTI:
127                         l.fillMultiEPG(self.services, self.ask_time)
128                 elif self.type == EPG_TYPE_SINGLE:
129                         l.fillSingleEPG(self.currentService)
130                 else:
131                         l.fillSimilarList(self.currentService, self.eventid)
132
133         def eventViewCallback(self, setEvent, setService, val):
134                 l = self["list"]
135                 old = l.getCurrent()
136                 if val == -1:
137                         self.moveUp()
138                 elif val == +1:
139                         self.moveDown()
140                 cur = l.getCurrent()
141                 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
142                         self.eventViewCallback(setEvent, setService, val)
143                 else:
144                         setService(cur[1])
145                         setEvent(cur[0])
146
147         def zapTo(self): # just used in multiepg
148                 if self.zapFunc and self["key_red"].getText() == "Zap":
149                         lst = self["list"]
150                         count = lst.getCurrentChangeCount()
151                         if count == 0:
152                                 self.closeRecursive = True
153                                 ref = lst.getCurrent()[1]
154                                 self.zapFunc(ref.ref)
155
156         def eventSelected(self):
157                 self.infoKeyPressed()
158
159         def yellowButtonPressed(self):
160                 if self.type == EPG_TYPE_MULTI:
161                         self["list"].updateMultiEPG(-1)
162
163         def blueButtonPressed(self):
164                 if self.type == EPG_TYPE_MULTI:
165                         self["list"].updateMultiEPG(1)
166
167         def timerAdd(self):
168                 cur = self["list"].getCurrent()
169                 event = cur[0]
170                 serviceref = cur[1]
171                 if event is None:
172                         return
173                 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
174                 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
175
176         def timerEditFinished(self, answer):
177                 if answer[0]:
178                         self.session.nav.RecordTimer.record(answer[1])
179                 else:
180                         print "Timeredit aborted"       
181
182         def moveUp(self):
183                 self["list"].moveUp()
184
185         def moveDown(self):
186                 self["list"].moveDown()
187
188         def applyButtonState(self, state):
189                 if state == 0:
190                         self["now_button"].hide()
191                         self["now_button_sel"].hide()
192                         self["next_button"].hide()
193                         self["next_button_sel"].hide()
194                         self["more_button"].hide()
195                         self["more_button_sel"].hide()
196                         self["now_text"].hide()
197                         self["next_text"].hide()
198                         self["more_text"].hide()
199                         self["key_red"].setText("")
200                 else:
201                         if state == 1:
202                                 self["key_red"].setText("Zap")
203                                 self["now_button_sel"].show()
204                                 self["now_button"].hide()
205                         else:
206                                 self["now_button"].show()
207                                 self["now_button_sel"].hide()
208                                 self["key_red"].setText("")
209
210                         if state == 2:
211                                 self["next_button_sel"].show()
212                                 self["next_button"].hide()
213                         else:
214                                 self["next_button"].show()
215                                 self["next_button_sel"].hide()
216
217                         if state == 3:
218                                 self["more_button_sel"].show()
219                                 self["more_button"].hide()
220                         else:
221                                 self["more_button"].show()
222                                 self["more_button_sel"].hide()
223
224         def onSelectionChanged(self):
225                 if self.type == EPG_TYPE_MULTI:
226                         count = self["list"].getCurrentChangeCount()
227                         if self.ask_time != -1:
228                                 self.applyButtonState(0)
229                         elif count > 1:
230                                 self.applyButtonState(3)
231                         elif count > 0:
232                                 self.applyButtonState(2)
233                         else:
234                                 self.applyButtonState(1)
235                         days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
236                         datastr = ""
237                         event = self["list"].getCurrent()[0]
238                         if event is not None:
239                                 now = time()
240                                 beg = event.getBeginTime()
241                                 nowTime = localtime(now)
242                                 begTime = localtime(beg)
243                                 if nowTime[2] != begTime[2]:
244                                         datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
245                                 else:
246                                         datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
247                         self["date"].setText(datestr)