display clock png in single epg list for fitting timers (we have a problem with the...
[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 enigma import eServiceReference, eServiceEventPtr
10 from Screens.FixedMenu import FixedMenu
11 from RecordTimer import RecordTimerEntry, parseEvent
12 from TimerEdit import TimerEditList
13 from TimerEntry import TimerEntry
14 from ServiceReference import ServiceReference
15 from Components.config import config, currentConfigSelectionElement
16 from time import localtime
17
18 import xml.dom.minidom
19
20 class EPGSelection(Screen):
21         def __init__(self, session, service, zapFunc=None):
22                 Screen.__init__(self, session)
23                 self["key_red"] = Button("")
24                 self.closeRecursive = False
25                 if isinstance(service, eServiceReference):
26                         self.type = EPG_TYPE_SINGLE
27                         self["key_yellow"] = Button()
28                         self["key_blue"] = Button()
29                         self.currentService=ServiceReference(service)
30                 else:
31                         self.skinName = "EPGSelectionMulti"
32                         self.type = EPG_TYPE_MULTI
33                         self["key_yellow"] = Button(_("Prev"))
34                         self["key_blue"] = Button(_("Next"))
35                         self["now_button"] = Pixmap()
36                         self["next_button"] = Pixmap()
37                         self["more_button"] = Pixmap()
38                         self["now_button_sel"] = Pixmap()
39                         self["next_button_sel"] = Pixmap()
40                         self["more_button_sel"] = Pixmap()
41                         self["now_text"] = Label()
42                         self["next_text"] = Label()
43                         self["more_text"] = Label()
44                         self["date"] = Label()
45                         self.services = service
46                         self.zapFunc = zapFunc
47
48                 self["key_green"] = Button(_("Add timer"))
49                 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
50
51                 class ChannelActionMap(ActionMap):
52                         def action(self, contexts, action):
53                                 ActionMap.action(self, contexts, action)
54
55                 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
56                         {
57                                 "cancel": self.closeScreen,
58                                 "ok": self.eventSelected,
59                                 "timerAdd": self.timerAdd,
60                                 "yellow": self.yellowButtonPressed,
61                                 "blue": self.blueButtonPressed,
62                                 "info": self.infoKeyPressed,
63                                 "zapTo": self.zapTo
64                         })
65                 self["actions"].csel = self
66
67                 self.onLayoutFinish.append(self.onCreate)
68
69         def closeScreen(self):
70                 self.close(self.closeRecursive or self.type == EPG_TYPE_SINGLE)
71
72         def infoKeyPressed(self):
73                 if self.type == EPG_TYPE_MULTI:
74                         cur = self["list"].getCurrent()
75                         event = cur[0]
76                         service = cur[1]
77                 else:
78                         event = self["list"].getCurrent()
79                         service = self.currentService
80                 if event is not None:
81                         self.session.open(EventViewSimple, event, service, self.eventViewCallback)
82
83         #just used in multipeg
84         def onCreate(self):
85                 l = self["list"]
86                 if self.type == EPG_TYPE_MULTI:
87                         l.recalcEntrySize()
88                         l.fillMultiEPG(self.services)
89                 else:
90                         if SINGLE_CPP == 0:
91                                 l.recalcEntrySize()
92                         l.fillSingleEPG(self.currentService)
93
94         def eventViewCallback(self, setEvent, setService, val):
95                 l = self["list"]
96                 old = l.getCurrent()
97                 if val == -1:
98                         self.moveUp()
99                 elif val == +1:
100                         self.moveDown()
101                 cur = l.getCurrent()
102                 if self.type == EPG_TYPE_SINGLE:
103                         setEvent(cur)
104                 else:
105                         if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
106                                 self.eventViewCallback(setEvent, setService, val)
107                         else:
108                                 setEvent(cur[0])
109                                 setService(cur[1])
110
111         def zapTo(self): # just used in multiepg
112                 if self.zapFunc != None:
113                         self.closeRecursive = True
114                         ref = self["list"].getCurrent()[1]
115                         self.zapFunc(ref.ref)
116
117         def eventSelected(self):
118                 if self.type == EPG_TYPE_SINGLE:
119                         self.infoKeyPressed()
120                 else: # EPG_TYPE_MULTI
121                         self.zapTo()
122
123         def yellowButtonPressed(self):
124                 if self.type == EPG_TYPE_MULTI:
125                         self["list"].updateMultiEPG(-1)
126
127         def blueButtonPressed(self):
128                 if self.type == EPG_TYPE_MULTI:
129                         self["list"].updateMultiEPG(1)
130
131         def timerAdd(self):
132                 if self.type == EPG_TYPE_SINGLE:
133                         event = self["list"].getCurrent()
134                         serviceref = self.currentService
135                 else:
136                         cur = self["list"].getCurrent()
137                         event = cur[0]
138                         serviceref = cur[1]
139                 if event is None:
140                         return
141                 newEntry = RecordTimerEntry(serviceref, *parseEvent(event))
142                 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
143
144         def timerEditFinished(self, answer):
145                 if answer[0]:
146                         self.session.nav.RecordTimer.record(answer[1])
147                 else:
148                         print "Timeredit aborted"       
149
150         def moveUp(self):
151                 self["list"].moveUp()
152
153         def moveDown(self):
154                 self["list"].moveDown()
155
156         def applyButtonState(self, state):
157                 if state == 1:
158                         self["now_button_sel"].show()
159                         self["now_button"].hide()
160                 else:
161                         self["now_button"].show()
162                         self["now_button_sel"].hide()
163
164                 if state == 2:
165                         self["next_button_sel"].show()
166                         self["next_button"].hide()
167                 else:
168                         self["next_button"].show()
169                         self["next_button_sel"].hide()
170
171                 if state == 3:
172                         self["more_button_sel"].show()
173                         self["more_button"].hide()
174                 else:
175                         self["more_button"].show()
176                         self["more_button_sel"].hide()
177
178         def onSelectionChanged(self):
179                 if self.type == EPG_TYPE_MULTI:
180                         count = self["list"].getCurrentChangeCount()
181                         if count > 1:
182                                 self.applyButtonState(3)
183                         elif count > 0:
184                                 self.applyButtonState(2)
185                         else:
186                                 self.applyButtonState(1)
187                         days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
188                         datastr = ""
189                         event = self["list"].getCurrent()[0]
190                         if event is not None:
191                                 now = time()
192                                 beg = event.getBeginTime()
193                                 nowTime = localtime(now)
194                                 begTime = localtime(beg)
195                                 if nowTime[2] != begTime[2]:
196                                         datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
197                                 else:
198                                         datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
199                         self["date"].setText(datestr)