try to add a epglist (not working yet)
[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.Button import Button
7 from Components.ServiceName import ServiceName
8 from Components.EventInfo import EventInfo
9 from Components.ServicePosition import ServicePosition
10 from Components.config import configfile
11
12 from Screens.MessageBox import MessageBox
13 from Screens.MovieSelection import MovieSelection
14 from Screens.Volume import Volume
15 from Screens.Mute import Mute
16
17 from enigma import *
18
19 import time
20
21 # hack alert!
22 from Menu import MainMenu, mdom
23
24 class InfoBar(Screen):
25         STATE_HIDDEN = 0
26         STATE_HIDING = 1
27         STATE_SHOWING = 2
28         STATE_SHOWN = 3
29         
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 #instantiate forever
34                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
35                 
36                 self.state = self.STATE_HIDDEN
37                 
38                 self.volumeDialog = self.session.instantiateDialog(Volume)
39                 self.muteDialog = self.session.instantiateDialog(Mute)
40                 
41                 self.hideTimer = eTimer()
42                 self.hideTimer.timeout.get().append(self.doTimerHide)
43                 #self.hideTimer.start(1000)
44                 
45                 self.hideVolTimer = eTimer()
46                 self.hideVolTimer.timeout.get().append(self.volHide)
47
48                 self["actions"] = ActionMap( [ "InfobarActions" ], 
49                         {
50                                 "switchChannelUp": self.switchChannelUp,
51                                 "switchChannelDown": self.switchChannelDown,
52                                 "mainMenu": self.mainMenu,
53                                 "zapUp": self.zapUp,
54                                 "zapDown": self.zapDown,
55                                 "volumeUp": self.volUp,
56                                 "volumeDown": self.volDown,
57                                 "volumeMute": self.volMute,
58                                 "instantRecord": self.instantRecord,
59                                 "hide": self.hide,
60                                 "toggleShow": self.toggleShow,
61                                 "showMovies": self.showMovies,
62                                 "quit": self.quit,
63                                 "showEPGList": self.showEPGList
64                         })
65 #               self["okbutton"] = Button("mainMenu", [self.mainMenu])
66                 
67                 self["CurrentTime"] = Clock()
68                 # ServicePosition(self.session.nav, ServicePosition.TYPE_REMAINING)
69                 # Clock()
70
71                 self["ServiceName"] = ServiceName(self.session.nav)
72                 
73                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
74                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
75
76                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
77                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
78                 
79                 self.recording = None
80                 
81                 self.pos = 0
82         
83         def mainMenu(self):
84                 print "loading mainmenu XML..."
85                 menu = mdom.childNodes[0]
86                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
87                 self.session.open(MainMenu, menu, menu.childNodes)
88
89         def switchChannelUp(self):      
90                 self.servicelist.moveUp()
91                 self.session.execDialog(self.servicelist)
92
93         def switchChannelDown(self):    
94                 self.servicelist.moveDown()
95                 self.session.execDialog(self.servicelist)
96
97         def hide(self): 
98                 self.instance.hide()
99
100         def doTimerHide(self):
101                 if self.state == self.STATE_SHOWN:
102                         self.instance.hide()
103                         self.state = self.STATE_HIDDEN
104
105         def toggleShow(self):
106                 if self.state == self.STATE_SHOWN:
107                         self.instance.hide()
108                         #pls check animation support, sorry
109 #                       self.startHide()
110                         self.state = self.STATE_HIDDEN
111                 else:
112                         self.instance.show()
113 #                       self.startShow()
114                         self.state = self.STATE_SHOWN
115                         #TODO: make it customizable
116                         self.hideTimer.start(5000)
117
118         def     zapUp(self):
119                 self.servicelist.moveUp()
120                 self.servicelist.zap()
121
122         def     zapDown(self):
123                 self.servicelist.moveDown()
124                 self.servicelist.zap()
125
126         def     volUp(self):
127                 eDVBVolumecontrol.getInstance().volumeUp()
128                 self.volumeDialog.instance.show()
129                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
130                 self.hideVolTimer.start(3000)
131
132         def     volDown(self):
133                 eDVBVolumecontrol.getInstance().volumeDown()
134                 self.volumeDialog.instance.show()
135                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
136                 self.hideVolTimer.start(3000)
137                 
138         def volHide(self):
139                 self.volumeDialog.instance.hide()
140
141         def startShow(self):
142                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
143                 self.state = self.STATE_SHOWN
144         
145         def startHide(self):
146                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
147                 self.state = self.STATE_HIDDEN
148
149         def     volMute(self):
150                 eDVBVolumecontrol.getInstance().volumeToggleMute()
151                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
152                 
153                 if (eDVBVolumecontrol.getInstance().isMuted()):
154                         self.muteDialog.instance.show()
155                 else:
156                         self.muteDialog.instance.hide()
157
158         def showEPGList(self):
159 # TODO hier irgendwie EPGSelection benutzen und setRoot benutzen um nen service zu uebergeben
160 # self.session.nav.getCurrentlyPlayingServiceReference() sollte das wohl sein
161                 print "hier soll mal ne EPGList aufgehen"
162
163         def quit(self):
164                 configfile.save()
165                 quitMainloop()
166         
167         def stopCurrentRecording(self): 
168                 print "remove entry"
169                 self.session.nav.RecordTimer.removeEntry(self.recording)
170                 self.recording = None
171         
172         def startInstantRecording(self):
173                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
174                         
175                 # try to get event info
176                 epg = None
177                 try:
178                         service = self.session.nav.getCurrentService()
179                         info = service.info()
180                         ev = info.getEvent(0)
181                         epg = ev
182                 except:
183                         pass
184                 
185                 # fix me, description. 
186                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 30, serviceref, epg, "instant record")
187
188         def recordQuestionCallback(self, answer):
189                 if answer == False:
190                         return
191                 
192                 if self.recording != None:
193                         self.stopCurrentRecording()
194                 else:
195                         self.startInstantRecording()
196
197         def instantRecord(self):
198                 if self.recording != None:
199                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
200                 else:
201                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
202
203         def showMovies(self):
204                 self.session.open(MovieSelection)