add HarddiskManager
[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.SetupDevices
176 Components.SetupDevices.InitSetupDevices()
177
178 # first, setup a screen
179 try:
180         runScreenTest()
181 except:
182         print 'EXCEPTION IN PYTHON STARTUP CODE:'
183         print '-'*60
184         traceback.print_exc(file=sys.stdout)
185         quitMainloop()
186         print '-'*60
187
188 # now, run the mainloop
189
190 #pt = eDebugClassPtr()
191 #eDebugClass.getDebug(pt, 12)
192 #p = pt.__deref__()
193 #print pt.x
194 #print p.x
195 #print "removing ptr..."
196 #pt = 0
197 #print "now"
198 #print "p is " + str(p)
199 #print p.x
200 #p = 0
201 #
202 #bla = eDebugClass()
203 #bla = eDebugClass(2)
204 #
205