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