a8559c065854fdb473dba1112150d13fb869b6f4
[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 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
150 class Navigation:
151         def __init__(self):
152                 self.pnav = pNavigation()
153                 self.pnav.m_event.get().append(self.callEvent)
154                 self.event = [ ]
155                 self.currentlyPlayingService = None
156
157         def callEvent(self, i):
158                 for x in self.event:
159                         x(i)
160         
161         def playService(self, ref):
162                 self.currentlyPlayingServiceReference = None
163                 if not self.pnav.playService(ref):
164                         self.currentlyPlayingServiceReference = ref
165                         return 0
166                 return 1
167         
168         def getCurrentlyPlayingServiceReference(self):
169                 return self.currentlyPlayingServiceReference
170         
171         def recordService(self, ref):
172                 print "recording service: %s" % (str(ref))
173                 print self.pnav.recordService
174                 return self.pnav.recordService(ref)
175         
176         def endRecording(self):
177                 return self.pnav.endRecording()
178         
179         def enqueueService(self, ref):
180                 return self.pnav.enqueueService(ref)
181         
182         def getCurrentService(self):
183                 service = iPlayableServicePtr()
184                 if self.pnav.getCurrentService(service):
185                         return None
186                 return service
187         
188         def getPlaylist(self):
189                 playlist = ePlaylistPtr()
190                 if self.pnav.getPlaylist(playlist):
191                         return None
192                 return playlist
193         
194         def pause(self, p):
195                 return self.pnav.pause(p)
196
197 def runScreenTest():
198         session = Session()
199         session.desktop = getDesktop()
200         
201         session.nav = Navigation()
202         
203         session.open(infoBar)
204
205         CONNECT(keyPressedSignal(), session.keyEvent)
206         
207         runMainloop()
208         
209         return 0
210
211 import keymapparser
212 keymapparser.readKeymap()
213 import skin
214 skin.loadSkin()
215
216 # first, setup a screen
217 runScreenTest()
218
219 # now, run the mainloop
220
221 #pt = eDebugClassPtr()
222 #eDebugClass.getDebug(pt, 12)
223 #p = pt.__deref__()
224 #print pt.x
225 #print p.x
226 #print "removing ptr..."
227 #pt = 0
228 #print "now"
229 #print "p is " + str(p)
230 #print p.x
231 #p = 0
232 #
233 #bla = eDebugClass()
234 #bla = eDebugClass(2)
235 #
236