Merge branch 'bug_271_ac3pcm_delay_servicemp3' into experimental
[enigma2.git] / lib / python / Components / Sources / Boolean.py
1 from Source import Source
2 from Components.Element import cached
3 from enigma import eTimer
4
5 # a small warning:
6 # you can use that boolean well to express screen-private
7 # conditional expressions.
8 #
9 # however, if you think that there is ANY interest that another
10 # screen could use your expression, please put your calculation
11 # into a seperate Source, providing a "boolean"-property.
12 class Boolean(Source, object):
13         def __init__(self, fixed = False, function = None, destroy = None, poll = 0):
14                 Source.__init__(self)
15                 self.function = function
16                 self.fixed = fixed
17                 self.post_destroy = destroy
18                 if poll > 0:
19                         self.poll_timer = eTimer()
20                         self.poll_timer.callback.append(self.poll)
21                         self.poll_timer.start(poll)
22                 else:
23                         self.poll_timer = None
24
25         @cached
26         def getBoolean(self):
27                 if self.function is not None:
28                         return self.function()
29                 else:
30                         return self.fixed
31
32         def setBoolean(self, value):
33                 assert self.function is None
34                 self.fixed = value
35                 self.poll()
36
37         boolean = property(getBoolean, setBoolean)
38
39         def poll(self):
40                 self.changed((self.CHANGED_ALL,))
41
42         def destroy(self):
43                 if self.poll_timer:
44                         self.poll_timer.callback.remove(self.poll)
45                 if self.post_destroy is not None:
46                         self.fixed = self.post_destroy
47                         self.poll()
48                 Source.destroy(self)