- hopefully fixed some python/refcount stuff (__deref__ is still evil!)
[enigma2.git] / screens.py
1 from components import *
2 import sys
3 from enigma import quitMainloop
4
5 # some screens
6 def doGlobal(screen):
7         screen["clock"] = Clock()
8
9 class Screen(dict, HTMLSkin, GUISkin):
10         """ bla """
11
12         def __init__(self, session):
13                 self.skinName = self.__class__.__name__
14                 self.session = session
15                 GUISkin.__init__(self)
16                 
17         def execBegin(self):
18                 for (name, val) in self.items():
19                         val.execBegin()
20         
21         def execEnd(self):
22                 for (name, val) in self.items():
23                         val.execEnd()
24         
25         # never call this directly - it will be called from the session!
26         def doClose(self):
27                 GUISkin.close(self)
28                 
29                 for (name, val) in self.items():
30                         print "%s -> %d" % (name, sys.getrefcount(val))
31                         del self[name]
32         
33         def close(self, retval=None):
34                 self.session.close()
35
36 class mainMenu(Screen):
37         
38         def goEmu(self):
39                 self["title"].setText("EMUs ARE ILLEGAL AND NOT SUPPORTED!")
40         
41         def goTimeshift(self):
42                 self["title"].setText("JUST PRESS THE YELLOW BUTTON!")
43         
44         def goHDTV(self):
45                 self["title"].setText("HDTV GREEN FLASHES: ENABLED")
46         
47         def goScan(self):
48                 self.session.open(serviceScan)
49         
50         def goClock(self):
51                 self.session.open(clockDisplay, Clock())
52
53         def okbuttonClick(self):
54                 selection = self["menu"].getCurrent()
55                 selection[1]()
56         
57         def __init__(self, session):
58                 Screen.__init__(self, session)
59                 b = Button("ok")
60
61                 self["actions"] = ActionMap("MainMenuActions", 
62                         {
63                                 "selected": self.okbuttonClick
64                         })
65
66                 b.onClick = [ self.okbuttonClick ]
67                 self["okbutton"] = b
68                 self["title"] = Header("Main Menu! - press ok to leave!")
69                 self["menu"] = MenuList(
70                         [
71                                 ("Close Main Menu", self.close),
72                                 ("Service Scan", self.goScan),
73                                 ("Quit", quitMainloop),
74                                 ("EMU SETUP", self.goEmu),
75                                 ("TIMESHIFT SETUP", self.goTimeshift),
76                                 ("HDTV PIP CONFIG", self.goHDTV),
77                                 ("wie spaet ists?!", self.goClock)
78                         ])
79
80 #class mainMenu(Screen):
81 #       def __init__(self):
82 #               GUISkin.__init__(self)
83 #               
84 #               self["title"] = Header("this is the\nMAIN MENU !!!");
85 #               self["okbutton"] = Button("ok")
86 #               self["okbutton"].onClick = [ self.close ]
87
88 class channelSelection(Screen):
89         def __init__(self, session):
90                 Screen.__init__(self, session)
91                 
92                 self["list"] = ServiceList()
93                 self["list"].setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:PREMIERE"))
94                 
95                 self["okbutton"] = Button("ok", [self.channelSelected])
96                 
97                 class ChannelActionMap(ActionMap):
98                         def action(self, context, action):
99                                 if action[:7] == "bouquet":
100                                         print "setting root to " + action[8:]
101                                         self.csel["list"].setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
102                                 else:
103                                         ActionMap.action(self, context, action)
104
105                 self["actions"] = ChannelActionMap("ChannelSelectActions", 
106                         {
107                                 "selectChannel": self.channelSelected,
108                         })
109                 self["actions"].csel = self
110
111         def channelSelected(self):
112                 self.session.nav.playService(self["list"].getCurrent())
113                 self.close()
114                 pass
115
116 class infoBar(Screen):
117         def __init__(self, session):
118                 Screen.__init__(self, session)
119                 
120                 self["actions"] = ActionMap("InfobarActions", 
121                         {
122                                 "switchChannel": self.switchChannel,
123                                 "mainMenu": self.mainMenu
124                         })
125                 self["okbutton"] = Button("mainMenu", [self.mainMenu])
126                 
127                 self["CurrentTime"] = Clock()
128                 
129                 self["ServiceName"] = ServiceName(self.session.nav)
130                 
131                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
132                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
133
134                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
135                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
136         
137         def mainMenu(self):
138                 self.session.open(mainMenu)
139                 
140         def switchChannel(self):
141                 self.session.open(channelSelection)
142
143 # a clock display dialog
144 class clockDisplay(Screen):
145         def okbutton(self):
146                 self.session.close()
147         
148         def __init__(self, session, clock):
149                 Screen.__init__(self, session)
150                 self["theClock"] = clock
151                 b = Button("bye")
152                 b.onClick = [ self.okbutton ]
153                 self["okbutton"] = b
154                 self["title"] = Header("clock dialog: here you see the current uhrzeit!")
155
156 class serviceScan(Screen):
157         def ok(self):
158                 if self["scan"].isDone():
159                         self.close()
160         
161         def __init__(self, session):
162                 Screen.__init__(self, session)
163                 
164                 self["scan_progress"] = ProgressBar()
165                 self["scan_state"] = Label("scan state")
166                 self["scan"] = ServiceScan(self["scan_progress"], self["scan_state"])
167
168                 self["okbutton"] = Button("ok", [self.ok])
169                 self["okbutton"].disable()