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