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