- ask before start/stop record
[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                         print sys.getrefcount(self.currentDialog)
72                         del self.currentDialog.instance
73 #                       dump(self.currentDialog)
74                         del self.currentDialog
75                 else:
76                         del self.currentDialog.callback
77                 
78                 self.popCurrent()
79                 if callback is not None:
80                         callback(*retval)
81
82         def execBegin(self):
83                         self.currentDialog.execBegin()
84                         self.currentDialog.instance.show()
85                 
86         def execEnd(self):
87                         self.currentDialog.execEnd()
88                         self.currentDialog.instance.hide()
89         
90         def create(self, screen, arguments):
91                 # creates an instance of 'screen' (which is a class)
92                 return screen(self, *arguments)
93         
94         def instantiateDialog(self, screen, *arguments):
95                 # create dialog
96                 
97                 try:
98                         dlg = self.create(screen, arguments)
99                 except:
100                         print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
101                         print '-'*60
102                         traceback.print_exc(file=sys.stdout)
103                         quitMainloop()
104                         print '-'*60
105                 
106                 # read skin data
107                 readSkin(dlg, None, dlg.skinName, self.desktop)
108
109                 # create GUI view of this dialog
110                 assert self.desktop != None
111                 dlg.instance = eWindow(self.desktop)
112                 applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
113                 gui = GUIOutputDevice()
114                 gui.parent = dlg.instance
115                 gui.create(dlg, self.desktop)
116                 
117                 return dlg
118          
119         def pushCurrent(self):
120                 if self.currentDialog:
121                         self.dialogStack.append(self.currentDialog)
122                         self.execEnd()
123         
124         def popCurrent(self):
125                 if len(self.dialogStack):
126                         self.currentDialog = self.dialogStack.pop()
127                         self.execBegin()
128
129         def execDialog(self, dialog):
130                 self.pushCurrent()
131                 self.currentDialog = dialog
132                 self.currentDialog.isTmp = False
133                 self.currentDialog.callback = None # would cause re-entrancy problems.
134                 self.execBegin()
135
136         def openWithCallback(self, callback, screen, *arguments):
137                 self.open(screen, *arguments)
138                 self.currentDialog.callback = callback
139
140         def open(self, screen, *arguments):
141                 self.pushCurrent()
142                 self.currentDialog = self.instantiateDialog(screen, *arguments)
143                 self.currentDialog.isTmp = True
144                 self.currentDialog.callback = None
145                 self.execBegin()
146
147         def keyEvent(self, code):
148                 print "code " + str(code)
149
150         def close(self, *retval):
151                 self.currentDialog.returnValue = retval
152                 self.delayTimer.start(0, 1)
153
154
155 def runScreenTest():
156         session = Session()
157         session.desktop = getDesktop()
158         
159         session.nav = Navigation()
160         
161         session.open(Screens.InfoBar.InfoBar)
162
163         CONNECT(keyPressedSignal(), session.keyEvent)
164         
165         runMainloop()
166         
167         session.nav.shutdown()
168         
169         return 0
170
171 import keymapparser
172 keymapparser.readKeymap()
173 import skin
174 skin.loadSkin(getDesktop())
175
176 import Components.InputDevice
177 Components.InputDevice.InitInputDevices()
178
179 import Components.AVSwitch
180 Components.AVSwitch.InitAVSwitch()
181
182 import Components.Network
183 Components.Network.InitNetwork()
184
185 import Components.SetupDevices
186 Components.SetupDevices.InitSetupDevices()
187
188 import Components.NimManager
189
190 # first, setup a screen
191 try:
192         runScreenTest()
193 except:
194         print 'EXCEPTION IN PYTHON STARTUP CODE:'
195         print '-'*60
196         traceback.print_exc(file=sys.stdout)
197         quitMainloop()
198         print '-'*60
199
200 # now, run the mainloop
201
202 #pt = eDebugClassPtr()
203 #eDebugClass.getDebug(pt, 12)
204 #p = pt.__deref__()
205 #print pt.x
206 #print p.x
207 #print "removing ptr..."
208 #pt = 0
209 #print "now"
210 #print "p is " + str(p)
211 #print p.x
212 #p = 0
213 #
214 #bla = eDebugClass()
215 #bla = eDebugClass(2)
216 #
217