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