add missing header
[enigma2.git] / mytest.py
1 from enigma import *
2 from tools import *
3
4 import Screens.InfoBar
5
6 import RecordTimer
7
8 import sys
9 import time
10
11 from skin import applyGUIskin
12
13 # A screen is a function which instanciates all components of a screen into a temporary component.
14 # Thus, the global stuff is a screen, too.
15 # In a screen, components can either be instanciated from the class-tree, cloned (copied) or
16 # "linked" from the instance tree.
17 # A screen itself lives as the container of the components, so a screen is a component, too.
18
19 # we thus have one (static) hierarchy of screens (classes, not instances)
20 # and one with the instanciated components itself (both global and dynamic)
21
22 had = dict()
23
24 def dump(dir, p = ""):
25         if isinstance(dir, dict):
26                 for (entry, val) in dir.items():
27                         dump(val, p + "(dict)/" + entry)
28         if hasattr(dir, "__dict__"):
29                 for name, value in dir.__dict__.items():
30                         if not had.has_key(str(value)):
31                                 had[str(value)] = 1
32                                 dump(value, p + "/" + str(name))
33                         else:
34                                 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
35         else:
36                 print p + ":" + str(dir)
37
38 # + ":" + str(dir.__class__)
39
40 # display
41
42 class OutputDevice:
43         def create(self, screen): pass
44
45 # display: HTML
46
47 class HTMLOutputDevice(OutputDevice):
48         def create(self, comp):
49                 print comp.produceHTML()
50
51 html = HTMLOutputDevice()
52
53 class GUIOutputDevice(OutputDevice):
54         parent = None
55         def create(self, comp):
56                 comp.createGUIScreen(self.parent)
57
58 class Session:
59         def __init__(self):
60                 self.desktop = None
61                 self.delayTimer = eTimer()
62                 self.delayTimer.timeout.get().append(self.processDelay)
63                 
64                 self.currentDialog = None
65                 
66                 self.dialogStack = [ ]
67         
68         def processDelay(self):
69                 self.execEnd()
70                 
71                 if self.currentDialog.isTmp:
72                         self.currentDialog.doClose()
73                 
74                         print sys.getrefcount(self.currentDialog)
75                         del self.currentDialog.instance
76                         dump(self.currentDialog)
77                         del self.currentDialog
78                 
79                 self.popCurrent()
80                         
81         def execBegin(self):
82                         self.currentDialog.execBegin()
83                         self.currentDialog.instance.show()
84                 
85         def execEnd(self):
86                         self.currentDialog.execEnd()
87                         self.currentDialog.instance.hide()
88         
89         def create(self, screen, arguments):
90                 # creates an instance of 'screen' (which is a class)
91                 return screen(self, *arguments)
92         
93         def instantiateDialog(self, screen, *arguments):
94                 dlg = self.create(screen, arguments)
95                 assert self.desktop != None
96                 dlg.instance = eWindow(self.desktop)
97
98                 gui = GUIOutputDevice()
99                 gui.parent = dlg.instance
100                 gui.create(dlg)
101
102                 applyGUIskin(dlg, None, dlg.skinName, self.desktop)
103                 
104                 return dlg
105          
106         def pushCurrent(self):
107                 if self.currentDialog:
108                         self.dialogStack.append(self.currentDialog)
109                         self.execEnd()
110         
111         def popCurrent(self):
112                 if len(self.dialogStack):
113                         self.currentDialog = self.dialogStack.pop()
114                         self.execBegin()
115         
116         def execDialog(self, dialog):
117                 self.pushCurrent()
118                 self.currentDialog = dialog
119                 self.currentDialog.isTmp = False
120                 self.execBegin()
121
122         def open(self, screen, *arguments):
123                 self.pushCurrent()
124                 self.currentDialog = self.instantiateDialog(screen, *arguments)
125                 self.currentDialog.isTmp = True
126                 self.execBegin()
127
128         def keyEvent(self, code):
129 #               print "code " + str(code)
130                 if code == 32:
131                         self.currentDialog["okbutton"].instance.push()
132
133                 if code == 33:
134                         self.currentDialog["channelSwitcher"].instance.push()
135                 
136                 if code >= 0x30 and code <= 0x39:
137                         try:
138                                 self.currentDialog["menu"].instance.moveSelection(code - 0x31)
139                         except:
140                                 self.currentDialog["list"].instance.moveSelection(code - 0x31)
141
142         def close(self):
143                 self.delayTimer.start(0, 1)
144
145 # TODO: remove pNavgation, eNavigation and rewrite this stuff in python.
146 class Navigation:
147         def __init__(self):
148                 self.pnav = pNavigation()
149                 self.pnav.m_event.get().append(self.callEvent)
150                 self.event = [ ]
151                 self.currentlyPlayingService = None
152                 
153                 self.RecordTimer = RecordTimer.RecordTimer()
154
155         def callEvent(self, i):
156                 for x in self.event:
157                         x(i)
158         
159         def playService(self, ref):
160                 self.currentlyPlayingServiceReference = None
161                 if not self.pnav.playService(ref):
162                         self.currentlyPlayingServiceReference = ref
163                         return 0
164                 return 1
165         
166         def getCurrentlyPlayingServiceReference(self):
167                 return self.currentlyPlayingServiceReference
168         
169         def recordService(self, ref):
170                 service = iRecordableServicePtr()
171                 print "recording service: %s" % (str(ref))
172                 if self.pnav.recordService(ref, service):
173                         print "record returned non-zero"
174                         return None
175                 else:
176                         print "ok, recordService didn't fail"
177                         return service
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 recordWithTimer(self, begin, end, ref, epg):
198                 entry = RecordTimer.RecordTimerEntry(begin, end, self, ref, epg)
199                 self.RecordTimer.record(entry)
200                 return entry
201
202 def runScreenTest():
203         session = Session()
204         session.desktop = getDesktop()
205         
206         session.nav = Navigation()
207         
208         session.open(Screens.InfoBar.InfoBar)
209
210         CONNECT(keyPressedSignal(), session.keyEvent)
211         
212         runMainloop()
213         
214         return 0
215
216 import keymapparser
217 keymapparser.readKeymap()
218 import skin
219 skin.loadSkin()
220
221 # first, setup a screen
222 runScreenTest()
223
224 # now, run the mainloop
225
226 #pt = eDebugClassPtr()
227 #eDebugClass.getDebug(pt, 12)
228 #p = pt.__deref__()
229 #print pt.x
230 #print p.x
231 #print "removing ptr..."
232 #pt = 0
233 #print "now"
234 #print "p is " + str(p)
235 #print p.x
236 #p = 0
237 #
238 #bla = eDebugClass()
239 #bla = eDebugClass(2)
240 #
241