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