- load palette from png
[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 channelSelection(Screen):
87         def __init__(self, session):
88                 Screen.__init__(self, session)
89                 
90                 self["list"] = ServiceList()
91                 self["list"].setRoot(eServiceReference("""1:0:1:0:0:0:0:0:0:0:(provider=="ARD") && (type == 1)"""))
92                 
93                 self["okbutton"] = Button("ok", [self.channelSelected])
94                 
95                 class ChannelActionMap(ActionMap):
96                         def action(self, contexts, action):
97                                 if action[:7] == "bouquet":
98                                         print "setting root to " + action[8:]
99                                         self.csel["list"].setRoot(eServiceReference("1:0:1:0:0:0:0:0:0:0:" + action[8:]))
100                                 else:
101                                         ActionMap.action(self, contexts, action)
102
103                 self["actions"] = ChannelActionMap(["ChannelSelectActions", "OkCancelActions"], 
104                         {
105                                 "cancel": self.close,
106                                 "ok": self.channelSelected,
107                                 "mark": self.doMark
108                         })
109                 self["actions"].csel = self
110
111         def doMark(self):
112                 ref = self["list"].getCurrent()
113                 if self["list"].isMarked(ref):
114                         self["list"].removeMarked(ref)
115                 else:
116                         self["list"].addMarked(ref)
117                 
118         def channelSelected(self):
119                 self.session.nav.playService(self["list"].getCurrent())
120                 self.close()
121                 pass
122
123 class infoBar(Screen):
124         def __init__(self, session):
125                 Screen.__init__(self, session)
126                 
127                 self["actions"] = ActionMap( [ "InfobarActions" ], 
128                         {
129                                 "switchChannel": self.switchChannel,
130                                 "mainMenu": self.mainMenu
131                         })
132                 self["okbutton"] = Button("mainMenu", [self.mainMenu])
133                 
134                 self["CurrentTime"] = Clock()
135                 
136                 self["ServiceName"] = ServiceName(self.session.nav)
137                 
138                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
139                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
140
141                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
142                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
143         
144         def mainMenu(self):
145                 self.session.open(mainMenu)
146                 
147         def switchChannel(self):
148                 self.session.open(channelSelection)
149
150 # a clock display dialog
151 class clockDisplay(Screen):
152         def okbutton(self):
153                 self.session.close()
154         
155         def __init__(self, session, clock):
156                 Screen.__init__(self, session)
157                 self["theClock"] = clock
158                 b = Button("bye")
159                 b.onClick = [ self.okbutton ]
160                 self["okbutton"] = b
161                 self["title"] = Header("clock dialog: here you see the current uhrzeit!")
162
163 class serviceScan(Screen):
164         def ok(self):
165                 print "ok"
166                 if self["scan"].isDone():
167                         self.close()
168         
169         def __init__(self, session):
170                 Screen.__init__(self, session)
171                 
172                 self["scan_progress"] = ProgressBar()
173                 self["scan_state"] = Label("scan state")
174                 self["scan"] = ServiceScan(self["scan_progress"], self["scan_state"])
175
176                 self["okbutton"] = Button("ok", [self.ok])
177                 self["okbutton"].disable()