- add new listbox content type for multiple strings
[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 #               assert self.session == None, "a screen can only exec one per time"
19 #               self.session = session
20                 for (name, val) in self.items():
21                         val.execBegin()
22         
23         def execEnd(self):
24                 for (name, val) in self.items():
25                         val.execEnd()
26 #               assert self.session != None, "execEnd on non-execing screen!"
27 #               self.session = None
28         
29         # never call this directly - it will be called from the session!
30         def doClose(self):
31                 GUISkin.close(self)
32                 
33                 del self.session
34                 for (name, val) in self.items():
35                         print "%s -> %d" % (name, sys.getrefcount(val))
36                         del self[name]
37         
38         def close(self, retval=None):
39                 self.session.close()
40
41 class configTest(Screen):
42
43         def __init__(self, session):
44                 Screen.__init__(self, session)
45                 
46
47                 self["config"] = ConfigList(
48                         [
49                                 configEntry("HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/SDTV/FLASHES/GREEN"),
50                                 configEntry("HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/HDTV/FLASHES/GREEN"),
51                         ])
52
53                 self["actions"] = ActionMap(["OkCancelActions"], 
54                         {
55                                 "ok": self["config"].toggle,
56                                 "cancel": self.close
57                         })
58                 
59
60 class mainMenu(Screen):
61         
62         def goSetup(self):
63                 self.session.open(configTest)
64         
65         def goTimeshift(self):
66                 self["title"].setText("JUST PRESS THE YELLOW BUTTON!")
67         
68         def goHDTV(self):
69                 self["title"].setText("HDTV GREEN FLASHES: ENABLED")
70         
71         def goScan(self):
72                 self.session.open(serviceScan)
73         
74         def goClock(self):
75                 self.session.open(clockDisplay, Clock())
76
77         def okbuttonClick(self):
78                 selection = self["menu"].getCurrent()
79                 selection[1]()
80         
81         def __init__(self, session):
82                 Screen.__init__(self, session)
83                 b = Button("ok")
84
85                 self["actions"] = ActionMap(["OkCancelActions"], 
86                         {
87                                 "ok": self.okbuttonClick,
88                                 "cancel": self.close
89                         })
90
91                 b.onClick = [ self.okbuttonClick ]
92                 self["okbutton"] = b
93                 self["title"] = Header("Main Menu! - press ok to leave!")
94                 self["menu"] = MenuList(
95                         [
96                                 ("Close Main Menu", self.close),
97                                 ("Service Scan", self.goScan),
98                                 ("Quit", quitMainloop),
99                                 ("setup", self.goSetup),
100                                 ("TIMESHIFT SETUP", self.goTimeshift),
101                                 ("HDTV PIP CONFIG", self.goHDTV),
102                                 ("wie spaet ists?!", self.goClock)
103                         ])
104
105 class channelSelection(Screen):
106         def __init__(self, session):
107                 Screen.__init__(self, session)
108                 
109                 self["list"] = ServiceList()
110                 self["list"].setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(provider=="ARD") && (type == 1)"""))
111                 
112                 self["okbutton"] = Button("ok", [self.channelSelected])
113                 
114                 class ChannelActionMap(ActionMap):
115                         def action(self, contexts, action):
116                                 if action[:7] == "bouquet":
117                                         print "setting root to " + action[8:]
118                                         self.csel["list"].setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
119                                 else:
120                                         ActionMap.action(self, contexts, action)
121
122                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions"], 
123                         {
124                                 "cancel": self.close,
125                                 "ok": self.channelSelected,
126                                 "mark": self.doMark
127                         })
128                 self["actions"].csel = self
129
130         def doMark(self):
131                 ref = self["list"].getCurrent()
132                 if self["list"].isMarked(ref):
133                         self["list"].removeMarked(ref)
134                 else:
135                         self["list"].addMarked(ref)
136                 
137         def channelSelected(self):
138                 self.session.nav.playService(self["list"].getCurrent())
139                 self.close()
140                 pass
141
142 class infoBar(Screen):
143         def __init__(self, session):
144                 Screen.__init__(self, session)
145                 
146                 self["actions"] = ActionMap( [ "InfobarActions" ], 
147                         {
148                                 "switchChannel": self.switchChannel,
149                                 "mainMenu": self.mainMenu
150                         })
151                 self["okbutton"] = Button("mainMenu", [self.mainMenu])
152                 
153                 self["CurrentTime"] = Clock()
154                 
155                 self["ServiceName"] = ServiceName(self.session.nav)
156                 
157                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
158                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
159
160                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
161                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
162         
163         def mainMenu(self):
164                 self.session.open(mainMenu)
165                 
166         def switchChannel(self):
167                 self.session.open(channelSelection)
168
169 # a clock display dialog
170 class clockDisplay(Screen):
171         def okbutton(self):
172                 self.session.close()
173         
174         def __init__(self, session, clock):
175                 Screen.__init__(self, session)
176                 self["theClock"] = clock
177                 b = Button("bye")
178                 b.onClick = [ self.okbutton ]
179                 self["okbutton"] = b
180                 self["title"] = Header("clock dialog: here you see the current uhrzeit!")
181
182 class serviceScan(Screen):
183         def ok(self):
184                 print "ok"
185                 if self["scan"].isDone():
186                         self.close()
187         
188         def cancel(self):
189                 print "cancel not yet implemented ;)"
190         
191         def __init__(self, session):
192                 Screen.__init__(self, session)
193                 
194                 self["scan_progress"] = ProgressBar()
195                 self["scan_state"] = Label("scan state")
196                 self["scan"] = ServiceScan(self["scan_progress"], self["scan_state"])
197
198                 self["actions"] = ActionMap(["OkCancelActions"], 
199                         {
200                                 "ok": self.ok,
201                                 "cancel": self.cancel
202                         })
203