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