now infobar disappears after 5s - animation is broken now
[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.VolumeBar import VolumeBar
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
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                 self.volumeBar = VolumeBar()            
34                 
35                 self.state = self.STATE_HIDDEN
36                 
37                 self.hideTimer = eTimer()
38                 self.hideTimer.timeout.get().append(self.doTimerHide)
39                 #self.hideTimer.start(1000)
40
41
42                 self["actions"] = ActionMap( [ "InfobarActions" ], 
43                         {
44                                 "switchChannelUp": self.switchChannelUp,
45                                 "switchChannelDown": self.switchChannelDown,
46                                 "mainMenu": self.mainMenu,
47                                 "zapUp": self.zapUp,
48                                 "zapDown": self.zapDown,
49                                 "volumeUp": self.volUp,
50                                 "volumeDown": self.volDown,
51                                 "volumeMute": self.volMute,
52                                 "instantRecord": self.instantRecord,
53                                 "hide": self.hide,
54                                 "toggleShow": self.toggleShow,
55                                 "showMovies": self.showMovies,
56                                 "quit": self.quit
57                         })
58 #               self["okbutton"] = Button("mainMenu", [self.mainMenu])
59                 
60                 self["CurrentTime"] = Clock()
61                 # ServicePosition(self.session.nav, ServicePosition.TYPE_REMAINING)
62                 # Clock()
63
64                 self["Volume"] = self.volumeBar
65                 
66                 self["ServiceName"] = ServiceName(self.session.nav)
67                 
68                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
69                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
70
71                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
72                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
73                 
74                 self.recording = None
75                 
76                 self.pos = 0
77         
78         def mainMenu(self):
79                 print "loading mainmenu XML..."
80                 menu = mdom.childNodes[0]
81                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
82                 self.session.open(MainMenu, menu, menu.childNodes)
83
84         def switchChannelUp(self):      
85                 self.servicelist.moveUp()
86                 self.session.execDialog(self.servicelist)
87
88         def switchChannelDown(self):    
89                 self.servicelist.moveDown()
90                 self.session.execDialog(self.servicelist)
91
92         def hide(self): 
93                 self.instance.hide()
94
95         def doTimerHide(self):
96                 if self.state == self.STATE_SHOWN:
97                         self.instance.hide()
98                         self.state = self.STATE_HIDDEN
99
100         def toggleShow(self):
101                 if self.state == self.STATE_SHOWN:
102                         self.instance.hide()
103                         #pls check animation support, sorry
104 #                       self.startHide()
105                         self.state = self.STATE_HIDDEN
106                 else:
107                         self.instance.show()
108 #                       self.startShow()
109                         self.state = self.STATE_SHOWN
110                         #TODO: make it customizable
111                         self.hideTimer.start(5000)
112
113         def     zapUp(self):
114                 self.servicelist.moveUp()
115                 self.servicelist.zap()
116
117         def     zapDown(self):
118                 self.servicelist.moveDown()
119                 self.servicelist.zap()
120
121         def     volUp(self):
122                 eDVBVolumecontrol.getInstance().volumeUp()
123                 self.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
124
125         def     volDown(self):
126                 eDVBVolumecontrol.getInstance().volumeDown()
127                 self.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
128                 
129         def startShow(self):
130                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
131                 self.state = self.STATE_SHOWN
132         
133         def startHide(self):
134                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
135                 self.state = self.STATE_HIDDEN
136
137         def     volMute(self):
138                 eDVBVolumecontrol.getInstance().volumeToggleMute()
139                 self.volumeBar.setValue(eDVBVolumecontrol.getInstance().getVolume())
140
141         def     quit(self):
142                 configfile.save()
143                 quitMainloop()
144                 
145         def instantRecord(self):
146                 #self.session.open(MessageBox, "this would be an instant recording! do you really know what you're doing?!")
147                 #return
148         
149                 if self.recording != None:
150                         print "remove entry"
151                         self.session.nav.RecordTimer.removeEntry(self.recording)
152                         self.recording = None
153                 else:
154                         serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
155                         
156                         # try to get event info
157                         epg = None
158                         service = self.session.nav.getCurrentService()
159                         if service != None:
160                                 info = iServiceInformationPtr()
161                                 if not service.info(info):
162                                         ev = eServiceEventPtr()
163                                         if info.getEvent(ev, 0) == 0:
164                                                 epg = ev
165                         # fix me, description. 
166                         self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 30, serviceref, epg, "instant record")
167         
168         def showMovies(self):
169                 self.session.open(MovieSelection)
170