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