save and restore volume
[enigma2.git] / mytest.py
1 from enigma import *
2 from tools import *
3
4 import traceback
5 import Screens.InfoBar
6
7 import sys
8 import time
9
10 import ServiceReference
11
12 from Navigation import Navigation
13
14 from skin import readSkin, applyAllAttributes
15
16 from Components.config import configfile
17
18 had = dict()
19
20 def dump(dir, p = ""):
21         if isinstance(dir, dict):
22                 for (entry, val) in dir.items():
23                         dump(val, p + "(dict)/" + entry)
24         if hasattr(dir, "__dict__"):
25                 for name, value in dir.__dict__.items():
26                         if not had.has_key(str(value)):
27                                 had[str(value)] = 1
28                                 dump(value, p + "/" + str(name))
29                         else:
30                                 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
31         else:
32                 print p + ":" + str(dir)
33
34 # + ":" + str(dir.__class__)
35
36 # display
37
38 class OutputDevice:
39         def create(self, screen): pass
40
41 # display: HTML
42
43 class HTMLOutputDevice(OutputDevice):
44         def create(self, comp):
45                 print comp.produceHTML()
46
47 html = HTMLOutputDevice()
48
49 class GUIOutputDevice(OutputDevice):
50         parent = None
51         def create(self, comp, desktop):
52                 comp.createGUIScreen(self.parent, desktop)
53
54 class Session:
55         def __init__(self):
56                 self.desktop = None
57                 self.delayTimer = eTimer()
58                 self.delayTimer.timeout.get().append(self.processDelay)
59                 
60                 self.currentDialog = None
61                 
62                 self.dialogStack = [ ]
63         
64         def processDelay(self):
65                 self.execEnd()
66                 
67                 callback = self.currentDialog.callback
68                 retval = self.currentDialog.returnValue
69                 
70                 if self.currentDialog.isTmp:
71                         self.currentDialog.doClose()
72                 
73                         del self.currentDialog.instance
74 #                       dump(self.currentDialog)
75                         del self.currentDialog
76                 else:
77                         del self.currentDialog.callback
78                 
79                 self.popCurrent()
80                 if callback is not None:
81                         callback(*retval)
82
83         def execBegin(self):
84                         self.currentDialog.execBegin()
85                         self.currentDialog.instance.show()
86                 
87         def execEnd(self):
88                         self.currentDialog.execEnd()
89                         self.currentDialog.instance.hide()
90         
91         def create(self, screen, arguments):
92                 # creates an instance of 'screen' (which is a class)
93                 return screen(self, *arguments)
94         
95         def instantiateDialog(self, screen, *arguments):
96                 # create dialog
97                 
98                 try:
99                         dlg = self.create(screen, arguments)
100                 except:
101                         print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
102                         print '-'*60
103                         traceback.print_exc(file=sys.stdout)
104                         quitMainloop(5)
105                         print '-'*60
106                 
107                 # read skin data
108                 readSkin(dlg, None, dlg.skinName, self.desktop)
109
110                 # create GUI view of this dialog
111                 assert self.desktop != None
112                 dlg.instance = eWindow(self.desktop)
113                 applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
114                 gui = GUIOutputDevice()
115                 gui.parent = dlg.instance
116                 gui.create(dlg, self.desktop)
117                 
118                 return dlg
119          
120         def pushCurrent(self):
121                 if self.currentDialog:
122                         self.dialogStack.append(self.currentDialog)
123                         self.execEnd()
124         
125         def popCurrent(self):
126                 if len(self.dialogStack):
127                         self.currentDialog = self.dialogStack.pop()
128                         self.execBegin()
129
130         def execDialog(self, dialog):
131                 self.pushCurrent()
132                 self.currentDialog = dialog
133                 self.currentDialog.isTmp = False
134                 self.currentDialog.callback = None # would cause re-entrancy problems.
135                 self.execBegin()
136
137         def openWithCallback(self, callback, screen, *arguments):
138                 self.open(screen, *arguments)
139                 self.currentDialog.callback = callback
140
141         def open(self, screen, *arguments):
142                 self.pushCurrent()
143                 self.currentDialog = self.instantiateDialog(screen, *arguments)
144                 self.currentDialog.isTmp = True
145                 self.currentDialog.callback = None
146                 self.execBegin()
147
148         def keyEvent(self, code):
149                 print "code " + str(code)
150
151         def close(self, *retval):
152                 self.currentDialog.returnValue = retval
153                 self.delayTimer.start(0, 1)
154
155
156 def runScreenTest():
157         session = Session()
158         session.desktop = getDesktop()
159         
160         session.nav = Navigation()
161         
162         session.open(Screens.InfoBar.InfoBar)
163
164         CONNECT(keyPressedSignal(), session.keyEvent)
165         
166         runMainloop()
167         
168         configfile.save()
169         
170         session.nav.shutdown()
171         
172         return 0
173
174 import keymapparser
175 keymapparser.readKeymap()
176 import skin
177 skin.loadSkin(getDesktop())
178
179 import Components.InputDevice
180 Components.InputDevice.InitInputDevices()
181
182 import Components.AVSwitch
183 Components.AVSwitch.InitAVSwitch()
184
185 import Components.Network
186 Components.Network.InitNetwork()
187
188 import Components.Lcd
189 Components.Lcd.InitLcd()
190
191 import Components.SetupDevices
192 Components.SetupDevices.InitSetupDevices()
193
194 import Components.RFmod
195 Components.RFmod.InitRFmod()
196
197 import Components.NimManager
198
199 # first, setup a screen
200 try:
201         runScreenTest()
202 except:
203         print 'EXCEPTION IN PYTHON STARTUP CODE:'
204         print '-'*60
205         traceback.print_exc(file=sys.stdout)
206         quitMainloop(5)
207         print '-'*60