remove ancient debug stuff
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ActionMap import NumberActionMap
4 from Components.Label import Label
5 from Components.config import configfile
6 from ChannelSelection import ChannelSelection
7
8
9 from Components.ServiceName import ServiceName
10 from Components.EventInfo import EventInfo
11 from Components.ServicePosition import ServicePosition
12
13 from EpgSelection import EPGSelection
14
15 from Screens.MessageBox import MessageBox
16 from Screens.MovieSelection import MovieSelection
17 from Screens.Volume import Volume
18 from Screens.Mute import Mute
19 from Screens.Standby import Standby
20
21 #from enigma import eTimer, eDVBVolumecontrol, quitMainloop
22 from enigma import *
23
24 # hack alert!
25 from Menu import MainMenu, mdom
26
27 class InfoBarVolumeControl:
28         """Volume control, handles volUp, volDown, volMute actions and display 
29         a corresponding dialog"""
30         
31         def __init__(self):
32                 self["VolumeActions"] = ActionMap( ["InfobarVolumeActions"] ,
33                         {
34                                 "volumeUp": self.volUp,
35                                 "volumeDown": self.volDown,
36                                 "volumeMute": self.volMute,
37                         })
38
39                 self.volumeDialog = self.session.instantiateDialog(Volume)
40                 self.muteDialog = self.session.instantiateDialog(Mute)
41
42                 self.hideVolTimer = eTimer()
43                 self.hideVolTimer.timeout.get().append(self.volHide)
44         
45         def     volUp(self):
46                 eDVBVolumecontrol.getInstance().volumeUp()
47                 self.volumeDialog.instance.show()
48                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
49                 self.hideVolTimer.start(3000)
50
51         def     volDown(self):
52                 eDVBVolumecontrol.getInstance().volumeDown()
53                 self.volumeDialog.instance.show()
54                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
55                 self.hideVolTimer.start(3000)
56                 
57         def volHide(self):
58                 self.volumeDialog.instance.hide()
59
60         def     volMute(self):
61                 eDVBVolumecontrol.getInstance().volumeToggleMute()
62                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
63                 
64                 if (eDVBVolumecontrol.getInstance().isMuted()):
65                         self.muteDialog.instance.show()
66                 else:
67                         self.muteDialog.instance.hide()
68
69 class InfoBarShowHide:
70         """ InfoBar show/hide control, accepts toggleShow and hide actions, might start
71         fancy animations. """
72         STATE_HIDDEN = 0
73         STATE_HIDING = 1
74         STATE_SHOWING = 2
75         STATE_SHOWN = 3
76         
77         def __init__(self):
78                 self["ShowHideActions"] = ActionMap( ["InfobarShowHideActions"] ,
79                         {
80                                 "toggleShow": self.toggleShow,
81                                 "hide": self.hide,
82                         })
83
84                 self.state = self.STATE_HIDDEN
85                 
86                 self.hideTimer = eTimer()
87                 self.hideTimer.timeout.get().append(self.doTimerHide)
88                 #self.hideTimer.start(1000)
89
90         def hide(self): 
91                 self.instance.hide()
92
93         def doTimerHide(self):
94                 if self.state == self.STATE_SHOWN:
95                         self.instance.hide()
96                         self.state = self.STATE_HIDDEN
97
98         def toggleShow(self):
99                 if self.state == self.STATE_SHOWN:
100                         self.instance.hide()
101                         #pls check animation support, sorry
102 #                       self.startHide()
103                         self.state = self.STATE_HIDDEN
104                 else:
105                         self.instance.show()
106 #                       self.startShow()
107                         self.state = self.STATE_SHOWN
108                         #TODO: make it customizable
109                         self.hideTimer.start(5000)
110
111         def startShow(self):
112                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
113                 self.state = self.STATE_SHOWN
114         
115         def startHide(self):
116                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
117                 self.state = self.STATE_HIDDEN
118
119 class NumberZap(Screen):
120         def quit(self):
121                 self.Timer.stop()
122                 self.close()
123
124         def keyOK(self):
125                 self.Timer.stop()
126                 print "do the action here"
127                 self.close()
128
129         def keyNumberGlobal(self, number):
130                 self.Timer.start(3000)          #reset timer
131                 self.field = self.field + str(number)
132                 self["number"].setText(self.field)
133                 if len(self.field) >= 4:
134                         self.keyOK()
135
136         def __init__(self, number):
137                 Screen.__init__(self)
138                 self.field = str(number)
139                 
140                 self["number"] = Label(self.field)
141
142                 self["actions"] = NumberActionMap( [ "SetupActions" ], 
143                         {
144                                 "cancel": self.quit,
145                                 "ok": self.keyOK,
146                                 "1": self.keyNumberGlobal,
147                                 "2": self.keyNumberGlobal,
148                                 "3": self.keyNumberGlobal,
149                                 "4": self.keyNumberGlobal,
150                                 "5": self.keyNumberGlobal,
151                                 "6": self.keyNumberGlobal,
152                                 "7": self.keyNumberGlobal,
153                                 "8": self.keyNumberGlobal,
154                                 "9": self.keyNumberGlobal,
155                                 "0": self.keyNumberGlobal
156                         })
157
158                 self.Timer = eTimer()
159                 self.Timer.timeout.get().append(self.keyOK)
160                 self.Timer.start(3000)
161
162 class InfoBarPowerKey:
163         """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
164         
165         def __init__(self):
166                 self.powerKeyTimer = eTimer()
167                 self.powerKeyTimer.timeout.get().append(self.powertimer)
168                 self["PowerKeyActions"] = ActionMap( ["PowerKeyActions"],
169                         {
170                                 "powerdown": self.powerdown,
171                                 "powerup": self.powerup,
172                         })
173
174         def powertimer(self):   
175                 print "PowerOff - Now!"
176                 self.quit()
177         
178         def powerdown(self):
179                 self.standbyblocked = 0
180                 self.powerKeyTimer.start(3000)
181
182         def powerup(self):
183                 self.powerKeyTimer.stop()
184                 if self.standbyblocked == 0:
185                         self.standbyblocked = 1
186                         self.session.open(Standby, self)
187
188         def quit(self):
189                 #       self.session.open(Standby, self)
190                 configfile.save()
191                 quitMainloop(0)
192
193
194 class InfoBarNumberZap:
195         """ Handles an initial number for NumberZapping """
196         def __init__(self):
197                 self["NumberZapActions"] = NumberActionMap( [ "NumberZapActions"],
198                         {
199                                 "1": self.keyNumberGlobal,
200                                 "2": self.keyNumberGlobal,
201                                 "3": self.keyNumberGlobal,
202                                 "4": self.keyNumberGlobal,
203                                 "5": self.keyNumberGlobal,
204                                 "6": self.keyNumberGlobal,
205                                 "7": self.keyNumberGlobal,
206                                 "8": self.keyNumberGlobal,
207                                 "9": self.keyNumberGlobal,
208                                 "0": self.keyNumberGlobal,
209                         })
210
211         def keyNumberGlobal(self, number):
212                 print "You pressed number " + str(number)
213                 self.session.open(NumberZap, number)
214
215 class InfoBarChannelSelection:
216         """ ChannelSelection - handles the channelSelection dialog and the initial 
217         channelChange actions which open the channelSelection dialog """
218         def __init__(self):
219                 #instantiate forever
220                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
221
222                 self["ChannelSelectActions"] = ActionMap( ["InfoBarChannelSelection"],
223                         {
224                                 "switchChannelUp": self.switchChannelUp,
225                                 "switchChannelDown": self.switchChannelDown,
226                                 "zapUp": self.zapUp,
227                                 "zapDown": self.zapDown,
228                         })
229                         
230         def switchChannelUp(self):      
231                 self.servicelist.moveUp()
232                 self.session.execDialog(self.servicelist)
233
234         def switchChannelDown(self):    
235                 self.servicelist.moveDown()
236                 self.session.execDialog(self.servicelist)
237
238         def     zapUp(self):
239                 self.servicelist.moveUp()
240                 self.servicelist.zap()
241
242         def     zapDown(self):
243                 self.servicelist.moveDown()
244                 self.servicelist.zap()
245
246 class InfoBarMenu:
247         """ Handles a menu action, to open the (main) menu """
248         def __init__(self):
249                 self["MenuActions"] = ActionMap( [ "InfoBarMenuActions" ], 
250                         {
251                                 "mainMenu": self.mainMenu,
252                         })
253
254         def mainMenu(self):
255                 print "loading mainmenu XML..."
256                 menu = mdom.childNodes[0]
257                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
258                 self.session.open(MainMenu, menu, menu.childNodes)
259
260 class InfoBarEPG:
261         """ EPG - Opens an EPG list when the showEPGList action fires """
262         def __init__(self):
263                 self["EPGActions"] = ActionMap( [ "InfobarEPGActions" ], 
264                         {
265                                 "showEPGList": self.showEPGList,
266                         })
267
268         def showEPGList(self):
269                 ref=self.session.nav.getCurrentlyPlayingServiceReference()
270                 ptr=eEPGCache.getInstance()
271                 if ptr.startTimeQuery(ref) != -1:
272                         self.session.open(EPGSelection, ref)
273                 else:
274                         print 'no epg for service', ref.toString()
275
276 class InfoBarEvent:     
277         """provides a current/next event info display"""
278         def __init__(self):
279                 self["Event_Now_StartTime"] = EventInfo(self.session.nav, EventInfo.Now_StartTime)
280                 self["Event_Next_StartTime"] = EventInfo(self.session.nav, EventInfo.Next_StartTime)
281                                 
282                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
283                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
284
285                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
286                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
287
288 class InfoBarServiceName:
289         def __init__(self):
290                 self["ServiceName"] = ServiceName(self.session.nav)
291
292 class InfoBarPVR:
293         """handles PVR specific actions like seeking, pause"""
294         def __init__(self):
295                 self["PVRActions"] = ActionMap( [ "InfobarPVRActions" ], 
296                         {
297                                 "pauseService": self.pauseService,
298                                 "unPauseService": self.unPauseService,
299                                 
300                                 "seekFwd": self.seekFwd,
301                                 "seekBack": self.seekBack,
302                         })
303                 
304         def pauseService(self):
305                 self.session.nav.pause(1)
306                 
307         def unPauseService(self):
308                 self.session.nav.pause(0)
309         
310         def doSeek(self, dir, seektime):
311                 service = self.session.nav.getCurrentService()
312                 if service is None:
313                         return
314                 
315                 seekable = service.seek()
316                 if seekable is None:
317                         return
318                 seekable.seekRelative(dir, 90 * seektime)
319
320         def seekFwd(self):
321                 self.doSeek(+1, 10000)
322         
323         def seekBack(self):
324                 self.doSeek(-1, 10000)
325
326 class InfoBarInstantRecord:
327         """Instant Record - handles the instantRecord action in order to 
328         start/stop instant records"""
329         def __init__(self):
330                 self["InstnantRecordActions"] = ActionMap( [ "InfoBarInstantRecord" ],
331                         {
332                                 "instantRecord": self.instantRecord,
333                         })
334                 self.recording = None
335
336         def stopCurrentRecording(self): 
337                 self.session.nav.RecordTimer.removeEntry(self.recording)
338                 self.recording = None
339         
340         def startInstantRecording(self):
341                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
342                         
343                 # try to get event info
344                 epg = None
345                 try:
346                         service = self.session.nav.getCurrentService()
347                         info = service.info()
348                         ev = info.getEvent(0)
349                         epg = ev
350                 except:
351                         pass
352                 
353                 # fix me, description. 
354                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
355
356         def recordQuestionCallback(self, answer):
357                 if answer == False:
358                         return
359                 
360                 if self.recording != None:
361                         self.stopCurrentRecording()
362                 else:
363                         self.startInstantRecording()
364
365         def instantRecord(self):
366                 if self.recording != None:
367                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
368                 else:
369                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")