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