start to implement a test environment to run seperate components seperately.
[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 ##################### ENIGMA BASE
21
22 class eTimer:
23         def __init__(self):
24                 self.timeout = slot()
25                 self.next_activation = None
26         
27         def start(self, msec, singleshot = False):
28                 self.next_activation = time.time() + msec / 1000.0
29                 self.msec = msec
30                 self.singleshot = singleshot
31                 timers.add(self)
32         
33         def stop():
34                 timers.remove(self)
35
36         def __repr__(self):
37                 return "<eTimer timeout=%s next_activation=%s singleshot=%s>" % (repr(self.timeout), repr(self.next_activation), repr(self.singleshot))
38
39         def do(self):
40                 if self.singleshot:
41                         self.stop()
42                 self.next_activation += self.msec / 1000.0
43                 print "next activation now %d " % self.next_activation
44                 self.timeout()
45
46 def runIteration():
47         running_timers = list(timers)
48         assert len(running_timers), "no running timers, so nothing will ever happen!"
49         running_timers.sort(key=lambda x: x.next_activation)
50         print running_timers
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 #       print "STOP NOW"
70 #       stopped = True
71
72 def run():
73         stoptimer = eTimer()
74         stoptimer.start(10000)
75         stoptimer.timeout.get().append(stop)
76         while not stopped:
77                 runIteration()
78
79
80 ##################### ENIGMA GUI
81
82 eSize = None
83 ePoint = None
84 gFont = None
85 eWindow = None
86 eLabel = None
87 ePixmap = None
88 eWindowStyleManager = None
89 loadPNG = None
90 addFont = None
91 gRGB = None
92 eWindowStyleSkinned = None
93
94 ##################### ENIGMA CONFIG
95
96 import Components.config
97
98 my_config = [
99 "config.skin.primary_skin=None\n"
100 ]
101
102 Components.config.config.unpickle(my_config)
103