df7f81b2a68e50bb1b510a02d795d477db0c82fc
[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, poll = 0):
14                 Source.__init__(self)
15                 self.function = function
16                 self.fixed = fixed
17                 if poll > 0:
18                         self.poll_timer = eTimer()
19                         self.poll_timer.timeout.get().append(self.poll)
20                         self.poll_timer.start(poll)
21
22         @cached
23         def getBoolean(self):
24                 if self.function is not None:
25                         return self.function()
26                 else:
27                         return self.fixed
28
29         boolean = property(getBoolean)
30
31         def poll(self):
32                 self.changed((self.CHANGED_ALL,))