fix restart of playback after EOF (fixes bug #241)
[enigma2.git] / tests / enigma.py
1 # fake-enigma
2
3 import fake_time
4
5 class slot:
6         def __init__(self):
7                 self.list = [ ]
8
9         def get(self):
10                 return self.list
11
12         def __call__(self):
13                 for x in self.list:
14                         x()
15
16 timers = set()
17
18 import time
19
20 from events import eventfnc
21
22 ##################### ENIGMA BASE
23
24 class eTimer:
25         def __init__(self):
26                 self.timeout = slot()
27                 self.next_activation = None
28                 print "NEW TIMER"
29         
30         def start(self, msec, singleshot = False):
31                 print "start timer", msec
32                 self.next_activation = time.time() + msec / 1000.0
33                 self.msec = msec
34                 self.singleshot = singleshot
35                 timers.add(self)
36         
37         def stop(self):
38                 timers.remove(self)
39
40         def __repr__(self):
41                 return "<eTimer timeout=%s next_activation=%s singleshot=%s>" % (repr(self.timeout), repr(self.next_activation), repr(self.singleshot))
42
43         def do(self):
44                 if self.singleshot:
45                         self.stop()
46                 self.next_activation += self.msec / 1000.0
47                 self.timeout()
48
49 def runIteration():
50         running_timers = list(timers)
51         assert len(running_timers), "no running timers, so nothing will ever happen!"
52         running_timers.sort(key=lambda x: x.next_activation)
53         
54         print "running:", running_timers
55         
56         next_timer = running_timers[0]
57
58         now = time.time()
59         delay = next_timer.next_activation - now 
60         
61         if delay > 0:
62                 time.sleep(delay)
63                 now += delay
64
65         while len(running_timers) and running_timers[0].next_activation <= now:
66                 running_timers[0].do()
67                 running_timers = running_timers[1:]
68
69 stopped = False
70
71 def stop():
72         global stopped
73         stopped = True
74
75 def run(duration = 1000):
76         stoptimer = eTimer()
77         stoptimer.start(duration * 1000.0)
78         stoptimer.callback.append(stop)
79         while not stopped:
80                 runIteration()
81
82
83 ##################### ENIGMA GUI
84
85 eSize = None
86 ePoint = None
87 gFont = None
88 eWindow = None
89 eLabel = None
90 ePixmap = None
91 eWindowStyleManager = None
92 loadPNG = None
93 addFont = None
94 gRGB = None
95 eWindowStyleSkinned = None
96 eButton = None
97 eListboxPythonStringContent = None
98 eListbox = None
99 eSubtitleWidget = None
100
101 class eEPGCache:
102         @classmethod
103         def getInstance(self):
104                 return self.instance
105
106         instance = None
107
108         def __init__(self):
109                 eEPGCache.instance = self
110
111         def lookupEventTime(self, ref, query):
112                 return None
113
114 eEPGCache()
115
116 getBestPlayableServiceReference = None
117
118 class pNavigation:
119         def __init__(self):
120                 self.m_event = slot()
121                 self.m_record_event = slot()
122
123         @eventfnc
124         def recordService(self, service):
125                 return iRecordableService(service)
126
127         @eventfnc
128         def stopRecordService(self, service):
129                 service.stop()
130
131         @eventfnc
132         def playService(self, service):
133                 return None
134
135         def __repr__(self):
136                 return "pNavigation"
137
138 eRCInput = None
139 getPrevAsciiCode = None
140
141 class eServiceReference:
142
143         isDirectory=1
144         mustDescent=2
145         canDescent=4
146         flagDirectory=isDirectory|mustDescent|canDescent
147         shouldSort=8
148         hasSortKey=16
149         sort1=32
150         isMarker=64
151         isGroup=128
152
153         def __init__(self, ref):
154                 self.ref = ref
155                 self.flags = 0
156
157         def toString(self):
158                 return self.ref
159
160         def __repr__(self):
161                 return self.toString()
162
163 class iRecordableService:
164         def __init__(self, ref):
165                 self.ref = ref
166
167         @eventfnc
168         def prepare(self, filename, begin, end, event_id):
169                 return 0
170         
171         @eventfnc
172         def start(self):
173                 return 0
174
175         @eventfnc
176         def stop(self):
177                 return 0
178         
179         def __repr__(self):
180                 return "iRecordableService(%s)" % repr(self.ref)
181
182 quitMainloop = None
183
184 class eAVSwitch:
185         @classmethod
186         def getInstance(self):
187                 return self.instance
188
189         instance = None
190
191         def __init__(self):
192                 eAVSwitch.instance = self
193
194         def setColorFormat(self, value):
195                 print "[eAVSwitch] color format set to %d" % value
196
197         def setAspectRatio(self, value):
198                 print "[eAVSwitch] aspect ratio set to %d" % value
199
200         def setWSS(self, value):
201                 print "[eAVSwitch] wss set to %d" % value
202
203         def setSlowblank(self, value):
204                 print "[eAVSwitch] wss set to %d" % value
205
206         def setVideomode(self, value):
207                 print "[eAVSwitch] wss set to %d" % value
208
209         def setInput(self, value):
210                 print "[eAVSwitch] wss set to %d" % value
211
212 eAVSwitch()
213
214 eDVBVolumecontrol = None
215
216 class eRFmod:
217         @classmethod
218         def getInstance(self):
219                 return self.instance
220
221         instance = None
222
223         def __init__(self):
224                 eRFmod.instance = self
225
226         def setFunction(self, value):
227                 print "[eRFmod] set function to %d" % value
228
229         def setTestmode(self, value):
230                 print "[eRFmod] set testmode to %d" % value
231
232         def setSoundFunction(self, value):
233                 print "[eRFmod] set sound function to %d" % value
234
235         def setSoundCarrier(self, value):
236                 print "[eRFmod] set sound carrier to %d" % value
237
238         def setChannel(self, value):
239                 print "[eRFmod] set channel to %d" % value
240
241         def setFinetune(self, value):
242                 print "[eRFmod] set finetune to %d" % value
243
244 eRFmod()
245
246
247 class eDBoxLCD:
248         @classmethod
249         def getInstance(self):
250                 return self.instance
251         
252         instance = None
253         
254         def __init__(self):
255                 eDBoxLCD.instance = self
256
257         def setLCDBrightness(self, value):
258                 print "[eDBoxLCD] set brightness to %d" % value
259
260         def setLCDContrast(self, value):
261                 print "[eDBoxLCD] set contrast to %d" % value
262
263         def setInverted(self, value):
264                 print "[eDBoxLCD] set inverted to %d" % value
265
266 eDBoxLCD();
267
268 Misc_Options = None
269
270 class eServiceCenter:
271         @classmethod
272         def getInstance(self):
273                 return self.instance
274
275         instance = None
276
277         def __init__(self):
278                 eServiceCenter.instance = self
279
280         def info(self, ref):
281                 return None
282
283 eServiceCenter()
284
285 ##################### ENIGMA CHROOT
286
287 print "import directories"
288 import Tools.Directories
289 print "done"
290
291 chroot="."
292
293 for (x, (y, z)) in Tools.Directories.defaultPaths.items():
294         Tools.Directories.defaultPaths[x] = (chroot + y, z)
295
296 Tools.Directories.defaultPaths[Tools.Directories.SCOPE_SKIN] = ("../data/", Tools.Directories.PATH_DONTCREATE)
297 Tools.Directories.defaultPaths[Tools.Directories.SCOPE_CONFIG] = ("/etc/enigma2/", Tools.Directories.PATH_DONTCREATE)
298
299 ##################### ENIGMA CONFIG
300
301 print "import config"
302 import Components.config
303 print "done"
304
305 my_config = [
306 "config.skin.primary_skin=None\n"
307 ]
308
309 Components.config.config.unpickle(my_config)
310
311 ##################### ENIGMA ACTIONS
312
313 class eActionMap:
314         def __init__(self):
315                 pass
316
317
318 ##################### ENIGMA STARTUP:
319
320 def init_nav():
321         print "init nav"
322         import Navigation, NavigationInstance
323         NavigationInstance.instance = Navigation.Navigation()
324
325 def init_record_config():
326         print "init recording"
327         import Components.RecordingConfig
328         Components.RecordingConfig.InitRecordingConfig()
329
330 def init_parental_control():
331         print "init parental"
332         from Components.ParentalControl import InitParentalControl
333         InitParentalControl()
334
335 def init_all():
336         # this is stuff from mytest.py
337         init_nav()
338         
339         init_record_config()
340         init_parental_control()
341         
342         import Components.InputDevice
343         Components.InputDevice.InitInputDevices()
344
345         import Components.AVSwitch
346         Components.AVSwitch.InitAVSwitch()
347
348         import Components.UsageConfig
349         Components.UsageConfig.InitUsageConfig()
350
351         import Components.Network
352         Components.Network.InitNetwork()
353
354         import Components.Lcd
355         Components.Lcd.InitLcd()
356
357         import Components.SetupDevices
358         Components.SetupDevices.InitSetupDevices()
359
360         import Components.RFmod
361         Components.RFmod.InitRFmod()
362
363         import Screens.Ci
364         Screens.Ci.InitCiConfig()