import nimmanager (to initial create instance)
[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
17 # A screen is a function which instanciates all components of a screen into a temporary component.
18 # Thus, the global stuff is a screen, too.
19 # In a screen, components can either be instanciated from the class-tree, cloned (copied) or
20 # "linked" from the instance tree.
21 # A screen itself lives as the container of the components, so a screen is a component, too.
22
23 # we thus have one (static) hierarchy of screens (classes, not instances)
24 # and one with the instanciated components itself (both global and dynamic)
25
26 had = dict()
27
28 def dump(dir, p = ""):
29         if isinstance(dir, dict):
30                 for (entry, val) in dir.items():
31                         dump(val, p + "(dict)/" + entry)
32         if hasattr(dir, "__dict__"):
33                 for name, value in dir.__dict__.items():
34                         if not had.has_key(str(value)):
35                                 had[str(value)] = 1
36                                 dump(value, p + "/" + str(name))
37                         else:
38                                 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
39         else:
40                 print p + ":" + str(dir)
41
42 # + ":" + str(dir.__class__)
43
44 # display
45
46 class OutputDevice:
47         def create(self, screen): pass
48
49 # display: HTML
50
51 class HTMLOutputDevice(OutputDevice):
52         def create(self, comp):
53                 print comp.produceHTML()
54
55 html = HTMLOutputDevice()
56
57 class GUIOutputDevice(OutputDevice):
58         parent = None
59         def create(self, comp, desktop):
60                 comp.createGUIScreen(self.parent, desktop)
61
62 class Session:
63         def __init__(self):
64                 self.desktop = None
65                 self.delayTimer = eTimer()
66                 self.delayTimer.timeout.get().append(self.processDelay)
67                 
68                 self.currentDialog = None
69                 
70                 self.dialogStack = [ ]
71         
72         def processDelay(self):
73                 self.execEnd()
74                 
75                 if self.currentDialog.isTmp:
76                         self.currentDialog.doClose()
77                 
78                         print sys.getrefcount(self.currentDialog)
79                         del self.currentDialog.instance
80 #                       dump(self.currentDialog)
81                         del self.currentDialog
82                 
83                 self.popCurrent()
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                 return screen(self, *arguments)
96         
97         def instantiateDialog(self, screen, *arguments):
98                 # create dialog
99                 
100                 try:
101                         dlg = self.create(screen, arguments)
102                 except:
103                         print 'EXCEPTION IN DIALOG INIT CODE, ABORTING:'
104                         print '-'*60
105                         traceback.print_exc(file=sys.stdout)
106                         quitMainloop()
107                         print '-'*60
108                 
109                 # read skin data
110                 readSkin(dlg, None, dlg.skinName, self.desktop)
111
112                 # create GUI view of this dialog
113                 assert self.desktop != None
114                 dlg.instance = eWindow(self.desktop)
115                 applyAllAttributes(dlg.instance, self.desktop, dlg.skinAttributes)
116                 gui = GUIOutputDevice()
117                 gui.parent = dlg.instance
118                 gui.create(dlg, self.desktop)
119                 
120                 return dlg
121          
122         def pushCurrent(self):
123                 if self.currentDialog:
124                         self.dialogStack.append(self.currentDialog)
125                         self.execEnd()
126         
127         def popCurrent(self):
128                 if len(self.dialogStack):
129                         self.currentDialog = self.dialogStack.pop()
130                         self.execBegin()
131         
132         def execDialog(self, dialog):
133                 self.pushCurrent()
134                 self.currentDialog = dialog
135                 self.currentDialog.isTmp = False
136                 self.execBegin()
137
138         def open(self, screen, *arguments):
139                 self.pushCurrent()
140                 self.currentDialog = self.instantiateDialog(screen, *arguments)
141                 self.currentDialog.isTmp = True
142                 self.execBegin()
143
144         def keyEvent(self, code):
145                 print "code " + str(code)
146
147         def close(self):
148                 self.delayTimer.start(0, 1)
149
150
151 def runScreenTest():
152         session = Session()
153         session.desktop = getDesktop()
154         
155         session.nav = Navigation()
156         
157         session.open(Screens.InfoBar.InfoBar)
158
159         CONNECT(keyPressedSignal(), session.keyEvent)
160         
161         runMainloop()
162         
163         session.nav.shutdown()
164         
165         return 0
166
167 import keymapparser
168 keymapparser.readKeymap()
169 import skin
170 skin.loadSkin(getDesktop())
171
172 import Components.InputDevice
173 Components.InputDevice.InitInputDevices()
174
175 import Components.AVSwitch
176 Components.AVSwitch.InitAVSwitch()
177
178 import Components.Network
179 Components.Network.InitNetwork()
180
181 import Components.SetupDevices
182 Components.SetupDevices.InitSetupDevices()
183
184 import Components.NimManager
185 #Components.NimManager.InitNimManager()
186
187 # first, setup a screen
188 try:
189         runScreenTest()
190 except:
191         print 'EXCEPTION IN PYTHON STARTUP CODE:'
192         print '-'*60
193         traceback.print_exc(file=sys.stdout)
194         quitMainloop()
195         print '-'*60
196
197 # now, run the mainloop
198
199 #pt = eDebugClassPtr()
200 #eDebugClass.getDebug(pt, 12)
201 #p = pt.__deref__()
202 #print pt.x
203 #print p.x
204 #print "removing ptr..."
205 #pt = 0
206 #print "now"
207 #print "p is " + str(p)
208 #print p.x
209 #p = 0
210 #
211 #bla = eDebugClass()
212 #bla = eDebugClass(2)
213 #
214