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