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