- fixed filter source (not yet fully implemented anyway)
[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                 self.currentDialog.doClose()
75                 
76                 dump(self.currentDialog)
77                 print sys.getrefcount(self.currentDialog)
78                 del self.currentDialog
79                 del self.currentWindow
80                 
81                 if len(self.dialogStack):
82                         (self.currentDialog, self.currentWindow) = self.dialogStack.pop()
83                         self.execBegin()
84                         
85         def execBegin(self):
86                         self.currentDialog.execBegin()
87                         self.currentWindow.show()
88                 
89         def execEnd(self):
90                         self.currentDialog.execEnd()
91                         self.currentWindow.hide()
92         
93         def create(self, screen, arguments):
94                 return screen(self, *arguments)
95         
96         def open(self, screen, *arguments):
97                 if self.currentDialog:
98                         self.dialogStack.append((self.currentDialog, self.currentWindow))
99                         self.execEnd()
100                 
101                 self.currentDialog = self.create(screen, arguments)
102                 
103                 if self.desktop != None:
104                         self.currentWindow = eWindow(self.desktop)
105
106                         gui = GUIOutputDevice()
107                         gui.parent = self.currentWindow
108                         gui.create(self.currentDialog)
109
110                         applyGUIskin(self.currentDialog, self.currentWindow, None, self.currentDialog.skinName)
111
112                         self.execBegin()
113                 else:
114                         self.currentWindow = None
115
116         def keyEvent(self, code):
117 #               print "code " + str(code)
118                 if code == 32:
119                         self.currentDialog["okbutton"].instance.push()
120
121                 if code == 33:
122                         self.currentDialog["channelSwitcher"].instance.push()
123                 
124                 if code >= 0x30 and code <= 0x39:
125                         try:
126                                 self.currentDialog["menu"].instance.moveSelection(code - 0x31)
127                         except:
128                                 self.currentDialog["list"].instance.moveSelection(code - 0x31)
129
130         def close(self):
131                 self.delayTimer.start(0, 1)
132
133 def runScreenTest():
134         session = Session()
135         session.desktop = getDesktop()
136         
137         session.nav = pNavigation()
138         
139         session.open(infoBar)
140
141         CONNECT(keyPressedSignal(), session.keyEvent)
142         
143         runMainloop()
144         
145         return 0
146
147 import keymapparser
148 keymapparser.readKeymap()
149
150 # first, setup a screen
151 runScreenTest()
152
153 # now, run the mainloop
154
155 #pt = eDebugClassPtr()
156 #eDebugClass.getDebug(pt, 12)
157 #p = pt.__deref__()
158 #print pt.x
159 #print p.x
160 #print "removing ptr..."
161 #pt = 0
162 #print "now"
163 #print "p is " + str(p)
164 #print p.x
165 #p = 0
166 #
167 #bla = eDebugClass()
168 #bla = eDebugClass(2)
169 #
170