- widget instance is now part of screen
[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 mainMenu(Screen):
42         
43         def goEmu(self):
44                 self["title"].setText("EMUs ARE ILLEGAL AND NOT SUPPORTED!")
45         
46         def goTimeshift(self):
47                 self["title"].setText("JUST PRESS THE YELLOW BUTTON!")
48         
49         def goHDTV(self):
50                 self["title"].setText("HDTV GREEN FLASHES: ENABLED")
51         
52         def goScan(self):
53                 self.session.open(serviceScan)
54         
55         def goClock(self):
56                 self.session.open(clockDisplay, Clock())
57
58         def okbuttonClick(self):
59                 selection = self["menu"].getCurrent()
60                 selection[1]()
61         
62         def __init__(self, session):
63                 Screen.__init__(self, session)
64                 b = Button("ok")
65
66                 self["actions"] = ActionMap(["OkCancelActions"], 
67                         {
68                                 "ok": self.okbuttonClick,
69                                 "cancel": self.close
70                         })
71
72                 b.onClick = [ self.okbuttonClick ]
73                 self["okbutton"] = b
74                 self["title"] = Header("Main Menu! - press ok to leave!")
75                 self["menu"] = MenuList(
76                         [
77                                 ("Close Main Menu", self.close),
78                                 ("Service Scan", self.goScan),
79                                 ("Quit", quitMainloop),
80                                 ("EMU SETUP", self.goEmu),
81                                 ("TIMESHIFT SETUP", self.goTimeshift),
82                                 ("HDTV PIP CONFIG", self.goHDTV),
83                                 ("wie spaet ists?!", self.goClock)
84                         ])
85
86 #class mainMenu(Screen):
87 #       def __init__(self):
88 #               GUISkin.__init__(self)
89 #               
90 #               self["title"] = Header("this is the\nMAIN MENU !!!");
91 #               self["okbutton"] = Button("ok")
92 #               self["okbutton"].onClick = [ self.close ]
93
94 class channelSelection(Screen):
95         def __init__(self, session):
96                 Screen.__init__(self, session)
97                 
98                 self["list"] = ServiceList()
99                 self["list"].setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(provider=="ARD") && (type == 1)"""))
100                 
101                 self["okbutton"] = Button("ok", [self.channelSelected])
102                 
103                 class ChannelActionMap(ActionMap):
104                         def action(self, contexts, action):
105                                 if action[:7] == "bouquet":
106                                         print "setting root to " + action[8:]
107                                         self.csel["list"].setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
108                                 else:
109                                         ActionMap.action(self, contexts, action)
110
111                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions"], 
112                         {
113                                 "cancel": self.close,
114                                 "ok": self.channelSelected,
115                                 "mark": self.doMark
116                         })
117                 self["actions"].csel = self
118
119         def doMark(self):
120                 ref = self["list"].getCurrent()
121                 if self["list"].isMarked(ref):
122                         self["list"].removeMarked(ref)
123                 else:
124                         self["list"].addMarked(ref)
125                 
126         def channelSelected(self):
127                 self.session.nav.playService(self["list"].getCurrent())
128                 self.close()
129                 pass
130
131 class infoBar(Screen):
132         def __init__(self, session):
133                 Screen.__init__(self, session)
134                 
135                 self["actions"] = ActionMap( [ "InfobarActions" ], 
136                         {
137                                 "switchChannel": self.switchChannel,
138                                 "mainMenu": self.mainMenu
139                         })
140                 self["okbutton"] = Button("mainMenu", [self.mainMenu])
141                 
142                 self["CurrentTime"] = Clock()
143                 
144                 self["ServiceName"] = ServiceName(self.session.nav)
145                 
146                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
147                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
148
149                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
150                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
151         
152         def mainMenu(self):
153                 self.session.open(mainMenu)
154                 
155         def switchChannel(self):
156                 self.session.open(channelSelection)
157
158 # a clock display dialog
159 class clockDisplay(Screen):
160         def okbutton(self):
161                 self.session.close()
162         
163         def __init__(self, session, clock):
164                 Screen.__init__(self, session)
165                 self["theClock"] = clock
166                 b = Button("bye")
167                 b.onClick = [ self.okbutton ]
168                 self["okbutton"] = b
169                 self["title"] = Header("clock dialog: here you see the current uhrzeit!")
170
171 class serviceScan(Screen):
172         def ok(self):
173                 if self["scan"].isDone():
174                         self.close()
175         
176         def __init__(self, session):
177                 Screen.__init__(self, session)
178                 
179                 self["scan_progress"] = ProgressBar()
180                 self["scan_state"] = Label("scan state")
181                 self["scan"] = ServiceScan(self["scan_progress"], self["scan_state"])
182
183                 self["okbutton"] = Button("ok", [self.ok])
184                 self["okbutton"].disable()