open EPGSelection screen from infobar by pressing the red key
[enigma2.git] / lib / python / Screens / InfoBar.py
1 from Screen import Screen
2 from EpgSelection import EPGSelection
3 from ChannelSelection import ChannelSelection
4 from Components.Clock import Clock
5 from Components.ActionMap import ActionMap
6 from Components.ActionMap import NumberActionMap
7 from Components.Button import Button
8 from Components.ServiceName import ServiceName
9 from Components.EventInfo import EventInfo
10 from Components.ServicePosition import ServicePosition
11 from Components.config import configfile
12 from Components.Label import Label
13
14 from Screens.MessageBox import MessageBox
15 from Screens.MovieSelection import MovieSelection
16 from Screens.Volume import Volume
17 from Screens.Mute import Mute
18
19 from enigma import *
20
21 import time
22
23 # hack alert!
24 from Menu import MainMenu, mdom
25
26 class NumberZap(Screen):
27         def quit(self):
28                 self.Timer.stop()
29                 self.close()
30
31         def keyOK(self):
32                 self.Timer.stop()
33                 print "do the action here"
34                 self.close()
35
36         def keyNumberGlobal(self, number):
37                 self.Timer.start(3000)          #reset timer
38                 self.field = self.field + str(number)
39                 self["number"].setText(self.field)
40
41         def __init__(self, session, number):
42                 Screen.__init__(self, session)
43                 self.field = str(number)
44                 
45                 self["number"] = Label(self.field)
46
47                 self["actions"] = NumberActionMap( [ "SetupActions" ], 
48                         {
49                                 "cancel": self.quit,
50                                 "ok": self.keyOK,
51                                 "1": self.keyNumberGlobal,
52                                 "2": self.keyNumberGlobal,
53                                 "3": self.keyNumberGlobal,
54                                 "4": self.keyNumberGlobal,
55                                 "5": self.keyNumberGlobal,
56                                 "6": self.keyNumberGlobal,
57                                 "7": self.keyNumberGlobal,
58                                 "8": self.keyNumberGlobal,
59                                 "9": self.keyNumberGlobal,
60                                 "0": self.keyNumberGlobal
61                         })
62
63                 self.Timer = eTimer()
64                 self.Timer.timeout.get().append(self.keyOK)
65                 self.Timer.start(3000)
66
67
68 class InfoBar(Screen):
69         STATE_HIDDEN = 0
70         STATE_HIDING = 1
71         STATE_SHOWING = 2
72         STATE_SHOWN = 3
73         
74         def __init__(self, session):
75                 Screen.__init__(self, session)
76
77                 #instantiate forever
78                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
79                 
80                 self.state = self.STATE_HIDDEN
81                 
82                 self.volumeDialog = self.session.instantiateDialog(Volume)
83                 self.muteDialog = self.session.instantiateDialog(Mute)
84                 
85                 self.hideTimer = eTimer()
86                 self.hideTimer.timeout.get().append(self.doTimerHide)
87                 #self.hideTimer.start(1000)
88                 
89                 self.hideVolTimer = eTimer()
90                 self.hideVolTimer.timeout.get().append(self.volHide)
91
92                 #self["actions"] = ActionMap( [ "InfobarActions" ], 
93                 self["actions"] = NumberActionMap( [ "InfobarActions" ], 
94                         {
95                                 "switchChannelUp": self.switchChannelUp,
96                                 "switchChannelDown": self.switchChannelDown,
97                                 "mainMenu": self.mainMenu,
98                                 "zapUp": self.zapUp,
99                                 "zapDown": self.zapDown,
100                                 "volumeUp": self.volUp,
101                                 "volumeDown": self.volDown,
102                                 "volumeMute": self.volMute,
103                                 "instantRecord": self.instantRecord,
104                                 "hide": self.hide,
105                                 "toggleShow": self.toggleShow,
106                                 "showMovies": self.showMovies,
107                                 "quit": self.quit,
108                                 "1": self.keyNumberGlobal,
109                                 "2": self.keyNumberGlobal,
110                                 "3": self.keyNumberGlobal,
111                                 "4": self.keyNumberGlobal,
112                                 "5": self.keyNumberGlobal,
113                                 "6": self.keyNumberGlobal,
114                                 "7": self.keyNumberGlobal,
115                                 "8": self.keyNumberGlobal,
116                                 "9": self.keyNumberGlobal,
117                                 "0": self.keyNumberGlobal,
118                                 "showEPGList": self.showEPGList
119                         })
120 #               self["okbutton"] = Button("mainMenu", [self.mainMenu])
121                 
122                 self["CurrentTime"] = Clock()
123                 # ServicePosition(self.session.nav, ServicePosition.TYPE_REMAINING)
124                 # Clock()
125
126                 self["ServiceName"] = ServiceName(self.session.nav)
127                 
128                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
129                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
130
131                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
132                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
133                 
134                 self.recording = None
135                 
136                 self.pos = 0
137         
138         def mainMenu(self):
139                 print "loading mainmenu XML..."
140                 menu = mdom.childNodes[0]
141                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
142                 self.session.open(MainMenu, menu, menu.childNodes)
143
144         def keyNumberGlobal(self, number):
145                 print "You pressed number " + str(number)
146                 self.session.open(NumberZap, number)
147
148         def switchChannelUp(self):      
149                 self.servicelist.moveUp()
150                 self.session.execDialog(self.servicelist)
151
152         def switchChannelDown(self):    
153                 self.servicelist.moveDown()
154                 self.session.execDialog(self.servicelist)
155
156         def hide(self): 
157                 self.instance.hide()
158
159         def doTimerHide(self):
160                 if self.state == self.STATE_SHOWN:
161                         self.instance.hide()
162                         self.state = self.STATE_HIDDEN
163
164         def toggleShow(self):
165                 if self.state == self.STATE_SHOWN:
166                         self.instance.hide()
167                         #pls check animation support, sorry
168 #                       self.startHide()
169                         self.state = self.STATE_HIDDEN
170                 else:
171                         self.instance.show()
172 #                       self.startShow()
173                         self.state = self.STATE_SHOWN
174                         #TODO: make it customizable
175                         self.hideTimer.start(5000)
176
177         def     zapUp(self):
178                 self.servicelist.moveUp()
179                 self.servicelist.zap()
180
181         def     zapDown(self):
182                 self.servicelist.moveDown()
183                 self.servicelist.zap()
184
185         def     volUp(self):
186                 eDVBVolumecontrol.getInstance().volumeUp()
187                 self.volumeDialog.instance.show()
188                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
189                 self.hideVolTimer.start(3000)
190
191         def     volDown(self):
192                 eDVBVolumecontrol.getInstance().volumeDown()
193                 self.volumeDialog.instance.show()
194                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
195                 self.hideVolTimer.start(3000)
196                 
197         def volHide(self):
198                 self.volumeDialog.instance.hide()
199
200         def startShow(self):
201                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
202                 self.state = self.STATE_SHOWN
203         
204         def startHide(self):
205                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
206                 self.state = self.STATE_HIDDEN
207
208         def     volMute(self):
209                 eDVBVolumecontrol.getInstance().volumeToggleMute()
210                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
211                 
212                 if (eDVBVolumecontrol.getInstance().isMuted()):
213                         self.muteDialog.instance.show()
214                 else:
215                         self.muteDialog.instance.hide()
216
217         def showEPGList(self):
218 # TODO hier irgendwie EPGSelection benutzen und setRoot benutzen um nen service zu uebergeben
219 # self.session.nav.getCurrentlyPlayingServiceReference() sollte das wohl sein
220                 self.session.open(EPGSelection)
221
222         def quit(self):
223                 configfile.save()
224                 quitMainloop()
225         
226         def stopCurrentRecording(self): 
227                 print "remove entry"
228                 self.session.nav.RecordTimer.removeEntry(self.recording)
229                 self.recording = None
230         
231         def startInstantRecording(self):
232                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
233                         
234                 # try to get event info
235                 epg = None
236                 try:
237                         service = self.session.nav.getCurrentService()
238                         info = service.info()
239                         ev = info.getEvent(0)
240                         epg = ev
241                 except:
242                         pass
243                 
244                 # fix me, description. 
245                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 30, serviceref, epg, "instant record")
246
247         def recordQuestionCallback(self, answer):
248                 if answer == False:
249                         return
250                 
251                 if self.recording != None:
252                         self.stopCurrentRecording()
253                 else:
254                         self.startInstantRecording()
255
256         def instantRecord(self):
257                 if self.recording != None:
258                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
259                 else:
260                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
261
262         def showMovies(self):
263                 self.session.open(MovieSelection)