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