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