- actionmap component will not catch (wrong) exceptions anymore
[enigma2.git] / mytest.py
1 from enigma import *
2 from tools import *
3
4
5 import sys
6 import time
7
8 from screens import *
9 from skin import applyGUIskin
10
11 # A screen is a function which instanciates all components of a screen into a temporary component.
12 # Thus, the global stuff is a screen, too.
13 # In a screen, components can either be instanciated from the class-tree, cloned (copied) or
14 # "linked" from the instance tree.
15 # A screen itself lives as the container of the components, so a screen is a component, too.
16
17 # we thus have one (static) hierarchy of screens (classes, not instances)
18 # and one with the instanciated components itself (both global and dynamic)
19
20 had = dict()
21
22 def dump(dir, p = ""):
23         if isinstance(dir, dict):
24                 for (entry, val) in dir.items():
25                         dump(val, p + "(dict)/" + entry)
26         if hasattr(dir, "__dict__"):
27                 for name, value in dir.__dict__.items():
28                         if not had.has_key(str(value)):
29                                 had[str(value)] = 1
30                                 dump(value, p + "/" + str(name))
31                         else:
32                                 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
33         else:
34                 print p + ":" + str(dir)
35
36 # + ":" + str(dir.__class__)
37
38 # defined components
39 components = {}
40
41 # do global
42 doGlobal(components)
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):
60                 comp.createGUIScreen(self.parent)
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                 dlg = self.create(screen, arguments)
99                 assert self.desktop != None
100                 dlg.instance = eWindow(self.desktop)
101
102                 gui = GUIOutputDevice()
103                 gui.parent = dlg.instance
104                 gui.create(dlg)
105
106                 applyGUIskin(dlg, None, dlg.skinName, self.desktop)
107                 
108                 return dlg
109          
110         def pushCurrent(self):
111                 if self.currentDialog:
112                         self.dialogStack.append(self.currentDialog)
113                         self.execEnd()
114         
115         def popCurrent(self):
116                 if len(self.dialogStack):
117                         self.currentDialog = self.dialogStack.pop()
118                         self.execBegin()
119         
120         def execDialog(self, dialog):
121                 self.pushCurrent()
122                 self.currentDialog = dialog
123                 self.currentDialog.isTmp = False
124                 self.execBegin()
125
126         def open(self, screen, *arguments):
127                 self.pushCurrent()
128                 self.currentDialog = self.instantiateDialog(screen, *arguments)
129                 self.currentDialog.isTmp = True
130                 self.execBegin()
131
132         def keyEvent(self, code):
133 #               print "code " + str(code)
134                 if code == 32:
135                         self.currentDialog["okbutton"].instance.push()
136
137                 if code == 33:
138                         self.currentDialog["channelSwitcher"].instance.push()
139                 
140                 if code >= 0x30 and code <= 0x39:
141                         try:
142                                 self.currentDialog["menu"].instance.moveSelection(code - 0x31)
143                         except:
144                                 self.currentDialog["list"].instance.moveSelection(code - 0x31)
145
146         def close(self):
147                 self.delayTimer.start(0, 1)
148
149 def runScreenTest():
150         session = Session()
151         session.desktop = getDesktop()
152         
153         session.nav = pNavigation()
154         
155         session.open(infoBar)
156
157         CONNECT(keyPressedSignal(), session.keyEvent)
158         
159         runMainloop()
160         
161         return 0
162
163 import keymapparser
164 keymapparser.readKeymap()
165 import skin
166 skin.loadSkin()
167
168 # first, setup a screen
169 runScreenTest()
170
171 # now, run the mainloop
172
173 #pt = eDebugClassPtr()
174 #eDebugClass.getDebug(pt, 12)
175 #p = pt.__deref__()
176 #print pt.x
177 #print p.x
178 #print "removing ptr..."
179 #pt = 0
180 #print "now"
181 #print "p is " + str(p)
182 #print p.x
183 #p = 0
184 #
185 #bla = eDebugClass()
186 #bla = eDebugClass(2)
187 #
188