add some more hacks, add test timer
[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 eButton = None
94 eListboxPythonStringContent = None
95 eListbox = None
96 eEPGCache = None
97 getBestPlayableServiceReference = None
98
99 class eServiceReference:
100
101         isDirectory=1
102         mustDescent=2
103         canDescent=4
104         flagDirectory=isDirectory|mustDescent|canDescent
105         shouldSort=8
106         hasSortKey=16
107         sort1=32
108         isMarker=64
109         isGroup=128
110
111         def __init__(self, ref):
112                 self.ref = ref
113                 self.flags = 0
114
115 iRecordableService = None
116 quitMainloop = None
117 eAVSwitch = None
118 eDVBVolumecontrol = None
119 eDBoxLCD = None
120
121 class eServiceCenter:
122         @classmethod
123         def getInstance(self):
124                 return self.instance
125
126         instance = None
127
128         def __init__(self):
129                 eServiceCenter.instance = self
130
131         def info(self, ref):
132                 return None
133
134 eServiceCenter()
135
136 ##################### ENIGMA CONFIG
137
138 import Components.config
139
140 my_config = [
141 "config.skin.primary_skin=None\n"
142 ]
143
144 Components.config.config.unpickle(my_config)
145
146 ##################### ENIGMA CHROOT
147
148 import Tools.Directories
149
150 chroot="."
151
152 for (x, (y, z)) in Tools.Directories.defaultPaths.items():
153         Tools.Directories.defaultPaths[x] = (chroot + y, z)
154
155 Tools.Directories.defaultPaths[Tools.Directories.SCOPE_SKIN] = ("../data/", Tools.Directories.PATH_DONTCREATE)
156
157 ##################### ENIGMA ACTIONS
158
159 class eActionMap:
160         def __init__(self):
161                 pass
162
163