fix auto inversion,
[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
79                         del self.currentDialog.instance
80 #                       dump(self.currentDialog)
81                         del self.currentDialog
82                 else:
83                         del self.currentDialog.callback
84                 
85                 self.popCurrent()
86                 if callback is not None:
87                         callback(*retval)
88
89         def execBegin(self):
90                 c = self.currentDialog
91                 c.execBegin()
92
93                 # when execBegin opened a new dialog, don't bother showing the old one.
94                 if c == self.currentDialog:
95                         c.instance.show()
96                 
97         def execEnd(self):
98                 self.currentDialog.execEnd()
99                 self.currentDialog.instance.hide()
100         
101         def create(self, screen, arguments):
102                 # creates an instance of 'screen' (which is a class)
103                 try:
104                         return screen(self, *arguments)
105                 except:
106                         errstr = "Screen %s(%s): %s" % (str(screen), str(arguments), sys.exc_info()[0])
107                         print errstr
108                         traceback.print_exc(file=sys.stdout)
109                         quitMainloop(5)
110                         
111         
112         def instantiateDialog(self, screen, *arguments):
113                 # create dialog
114                 
115                 try:
116                         dlg = self.create(screen, arguments)
117                 except:
118                         print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
119                         print '-'*60
120                         traceback.print_exc(file=sys.stdout)
121                         quitMainloop(5)
122                         print '-'*60
123                 
124                 # read skin data
125                 readSkin(dlg, None, dlg.skinName, self.desktop)
126
127                 # create GUI view of this dialog
128                 assert self.desktop != None
129                 dlg.instance = eWindow(self.desktop)
130                 applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
131                 gui = GUIOutputDevice()
132                 gui.parent = dlg.instance
133                 gui.create(dlg, self.desktop)
134                 
135                 return dlg
136          
137         def pushCurrent(self):
138                 if self.currentDialog:
139                         self.dialogStack.append(self.currentDialog)
140                         self.execEnd()
141         
142         def popCurrent(self):
143                 if len(self.dialogStack):
144                         self.currentDialog = self.dialogStack.pop()
145                         self.execBegin()
146                 else:
147                         self.currentDialog = None
148
149         def execDialog(self, dialog):
150                 self.pushCurrent()
151                 self.currentDialog = dialog
152                 self.currentDialog.isTmp = False
153                 self.currentDialog.callback = None # would cause re-entrancy problems.
154                 self.execBegin()
155
156         def openWithCallback(self, callback, screen, *arguments):
157                 dlg = self.open(screen, *arguments)
158                 dlg.callback = callback
159
160         def open(self, screen, *arguments):
161                 self.pushCurrent()
162                 dlg = self.currentDialog = self.instantiateDialog(screen, *arguments)
163                 dlg.isTmp = True
164                 dlg.callback = None
165                 self.execBegin()
166                 return dlg
167
168         def keyEvent(self, code):
169                 print "code " + str(code)
170
171         def close(self, *retval):
172                 self.currentDialog.returnValue = retval
173                 self.delayTimer.start(0, 1)
174
175 def runScreenTest():
176         session = Session()
177         session.desktop = getDesktop()
178         
179         session.nav = Navigation()
180         
181         screensToRun = wizardManager.getWizards()
182         screensToRun.append(Screens.InfoBar.InfoBar)
183         
184         def runNextScreen(session, screensToRun, *result):
185                 if result:
186                         quitMainloop(result)
187
188                 screen = screensToRun[0]
189                 
190                 if len(screensToRun):
191                         session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen)
192                 else:
193                         session.open(screen)
194         
195         runNextScreen(session, screensToRun)
196
197         CONNECT(keyPressedSignal(), session.keyEvent)
198         
199         runMainloop()
200         
201         configfile.save()
202         
203         session.nav.shutdown()
204         
205         return 0
206
207 import keymapparser
208 keymapparser.readKeymap()
209 import skin
210 skin.loadSkin(getDesktop())
211
212 import Components.InputDevice
213 Components.InputDevice.InitInputDevices()
214
215 import Components.AVSwitch
216 Components.AVSwitch.InitAVSwitch()
217
218 import Components.Network
219 Components.Network.InitNetwork()
220
221 import Components.Lcd
222 Components.Lcd.InitLcd()
223
224 import Components.SetupDevices
225 Components.SetupDevices.InitSetupDevices()
226
227 import Components.RFmod
228 Components.RFmod.InitRFmod()
229
230 import Components.NimManager
231
232 # first, setup a screen
233 try:
234         runScreenTest()
235 except:
236         print 'EXCEPTION IN PYTHON STARTUP CODE:'
237         print '-'*60
238         traceback.print_exc(file=sys.stdout)
239         quitMainloop(5)
240         print '-'*60