RecordTimer.py: fix typo
[vuplus_dvbapp] / 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
100 class eEPGCache:
101         @classmethod
102         def getInstance(self):
103                 return self.instance
104
105         instance = None
106
107         def __init__(self):
108                 eEPGCache.instance = self
109
110         def lookupEventTime(self, ref, query):
111                 return None
112
113 eEPGCache()
114
115 getBestPlayableServiceReference = None
116
117 class pNavigation:
118         def __init__(self):
119                 self.m_event = slot()
120                 self.m_record_event = slot()
121
122         @eventfnc
123         def recordService(self, service):
124                 return iRecordableService(service)
125
126         @eventfnc
127         def stopRecordService(self, service):
128                 service.stop()
129
130         @eventfnc
131         def playService(self, service):
132                 return None
133
134         def __repr__(self):
135                 return "pNavigation"
136
137 eRCInput = None
138 getPrevAsciiCode = None
139
140 class eServiceReference:
141
142         isDirectory=1
143         mustDescent=2
144         canDescent=4
145         flagDirectory=isDirectory|mustDescent|canDescent
146         shouldSort=8
147         hasSortKey=16
148         sort1=32
149         isMarker=64
150         isGroup=128
151
152         def __init__(self, ref):
153                 self.ref = ref
154                 self.flags = 0
155
156         def toString(self):
157                 return self.ref
158
159         def __repr__(self):
160                 return self.toString()
161
162 class iRecordableService:
163         def __init__(self, ref):
164                 self.ref = ref
165
166         @eventfnc
167         def prepare(self, filename, begin, end, event_id):
168                 return 0
169         
170         @eventfnc
171         def start(self):
172                 return 0
173
174         @eventfnc
175         def stop(self):
176                 return 0
177         
178         def __repr__(self):
179                 return "iRecordableService(%s)" % repr(self.ref)
180
181 quitMainloop = None
182
183 class eAVSwitch:
184         @classmethod
185         def getInstance(self):
186                 return self.instance
187
188         instance = None
189
190         def __init__(self):
191                 eAVSwitch.instance = self
192
193         def setColorFormat(self, value):
194                 print "[eAVSwitch] color format set to %d" % value
195
196         def setAspectRatio(self, value):
197                 print "[eAVSwitch] aspect ratio set to %d" % value
198
199         def setWSS(self, value):
200                 print "[eAVSwitch] wss set to %d" % value
201
202         def setSlowblank(self, value):
203                 print "[eAVSwitch] wss set to %d" % value
204
205         def setVideomode(self, value):
206                 print "[eAVSwitch] wss set to %d" % value
207
208         def setInput(self, value):
209                 print "[eAVSwitch] wss set to %d" % value
210
211 eAVSwitch()
212
213 eDVBVolumecontrol = None
214
215 class eRFmod:
216         @classmethod
217         def getInstance(self):
218                 return self.instance
219
220         instance = None
221
222         def __init__(self):
223                 eRFmod.instance = self
224
225         def setFunction(self, value):
226                 print "[eRFmod] set function to %d" % value
227
228         def setTestmode(self, value):
229                 print "[eRFmod] set testmode to %d" % value
230
231         def setSoundFunction(self, value):
232                 print "[eRFmod] set sound function to %d" % value
233
234         def setSoundCarrier(self, value):
235                 print "[eRFmod] set sound carrier to %d" % value
236
237         def setChannel(self, value):
238                 print "[eRFmod] set channel to %d" % value
239
240         def setFinetune(self, value):
241                 print "[eRFmod] set finetune to %d" % value
242
243 eRFmod()
244
245
246 class eDBoxLCD:
247         @classmethod
248         def getInstance(self):
249                 return self.instance
250         
251         instance = None
252         
253         def __init__(self):
254                 eDBoxLCD.instance = self
255
256         def setLCDBrightness(self, value):
257                 print "[eDBoxLCD] set brightness to %d" % value
258
259         def setLCDContrast(self, value):
260                 print "[eDBoxLCD] set contrast to %d" % value
261
262         def setInverted(self, value):
263                 print "[eDBoxLCD] set inverted to %d" % value
264
265 eDBoxLCD();
266
267 Misc_Options = None
268
269 class eServiceCenter:
270         @classmethod
271         def getInstance(self):
272                 return self.instance
273
274         instance = None
275
276         def __init__(self):
277                 eServiceCenter.instance = self
278
279         def info(self, ref):
280                 return None
281
282 eServiceCenter()
283
284 ##################### ENIGMA CHROOT
285
286 print "import directories"
287 import Tools.Directories
288 print "done"
289
290 chroot="."
291
292 for (x, (y, z)) in Tools.Directories.defaultPaths.items():
293         Tools.Directories.defaultPaths[x] = (chroot + y, z)
294
295 Tools.Directories.defaultPaths[Tools.Directories.SCOPE_SKIN] = ("../data/", Tools.Directories.PATH_DONTCREATE)
296 Tools.Directories.defaultPaths[Tools.Directories.SCOPE_CONFIG] = ("/etc/enigma2/", Tools.Directories.PATH_DONTCREATE)
297
298 ##################### ENIGMA CONFIG
299
300 print "import config"
301 import Components.config
302 print "done"
303
304 my_config = [
305 "config.skin.primary_skin=None\n"
306 ]
307
308 Components.config.config.unpickle(my_config)
309
310 ##################### ENIGMA ACTIONS
311
312 class eActionMap:
313         def __init__(self):
314                 pass
315
316
317 ##################### ENIGMA STARTUP:
318
319 def init_nav():
320         print "init nav"
321         import Navigation, NavigationInstance
322         NavigationInstance.instance = Navigation.Navigation()
323
324 def init_record_config():
325         print "init recording"
326         import Components.RecordingConfig
327         Components.RecordingConfig.InitRecordingConfig()
328
329 def init_parental_control():
330         print "init parental"
331         from Components.ParentalControl import InitParentalControl
332         InitParentalControl()
333
334 def init_all():
335         # this is stuff from mytest.py
336         init_nav()
337         
338         init_record_config()
339         init_parental_control()
340         
341         import Components.InputDevice
342         Components.InputDevice.InitInputDevices()
343
344         import Components.AVSwitch
345         Components.AVSwitch.InitAVSwitch()
346
347         import Components.UsageConfig
348         Components.UsageConfig.InitUsageConfig()
349
350         import Components.Network
351         Components.Network.InitNetwork()
352
353         import Components.Lcd
354         Components.Lcd.InitLcd()
355
356         import Components.SetupDevices
357         Components.SetupDevices.InitSetupDevices()
358
359         import Components.RFmod
360         Components.RFmod.InitRFmod()
361
362         import Screens.Ci
363         Screens.Ci.InitCiConfig()