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