ee09e5771fbb2ea691c84959e3af2670b435e6d4
[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
9 from Screens.MessageBox import MessageBox
10
11 from enigma import *
12
13 import time
14
15 # hack alert!
16 from Menu import *
17
18 class InfoBar(Screen):
19         def __init__(self, session):
20                 Screen.__init__(self, session)
21
22                 #instantiate forever
23                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
24                 
25                 self["actions"] = ActionMap( [ "InfobarActions" ], 
26                         {
27                                 "switchChannelUp": self.switchChannelUp,
28                                 "switchChannelDown": self.switchChannelDown,
29                                 "mainMenu": self.mainMenu,
30                                 "zapUp": self.zapUp,
31                                 "zapDown": self.zapDown,
32                                 "instantRecord": self.instantRecord,
33                                 "hide": self.hide,
34                                 "toggleShow": self.toggleShow
35                         })
36 #               self["okbutton"] = Button("mainMenu", [self.mainMenu])
37                 
38                 self["CurrentTime"] = Clock()
39                 
40                 self["ServiceName"] = ServiceName(self.session.nav)
41                 
42                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
43                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
44
45                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
46                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
47                 
48                 self.recording = None
49         
50         def mainMenu(self):
51                 print "loading mainmenu XML..."
52                 menu = mdom.childNodes[0]
53                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
54                 self.session.open(Menu, menu, menu.childNodes)
55
56         def switchChannelUp(self):      
57                 self.servicelist.moveUp()
58                 self.session.execDialog(self.servicelist)
59
60         def switchChannelDown(self):    
61                 self.servicelist.moveDown()
62                 self.session.execDialog(self.servicelist)
63
64         def hide(self): 
65                 self.instance.hide()
66
67         def toggleShow(self):
68                 if self.instance.isVisible():
69                         self.instance.hide()
70                 else:
71                         self.instance.show()
72
73         def     zapUp(self):
74                 self.servicelist.moveUp()
75                 self.servicelist.zap()
76
77         def     zapDown(self):
78                 self.servicelist.moveDown()
79                 self.servicelist.zap()
80                 
81         def instantRecord(self):
82                 self.session.open(MessageBox, "this would be an instant recording! do you really know what you're doing?!")
83                 return
84         
85                 if self.recording != None:
86                         print "remove entry"
87                         self.session.nav.RecordTimer.removeEntry(self.recording)
88                         self.recording = None
89                 else:
90                         serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
91                         
92                         # try to get event info
93                         epg = None
94                         service = self.session.nav.getCurrentService()
95                         if service != None:
96                                 info = iServiceInformationPtr()
97                                 if not service.info(info):
98                                         ev = eServiceEventPtr()
99                                         if info.getEvent(ev, 0) == 0:
100                                                 epg = ev
101                         # fix me, description. 
102                         self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 30, serviceref, epg, "instant record")
103