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