add orBottomToTop, orRightToLeft, orLeftToRight(orHorizontal), orTopToBottom(OrVertic...
[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.callback.append(self.poll)
20                         self.poll_timer.start(poll)
21                 else:
22                         self.poll_timer = None
23
24         @cached
25         def getBoolean(self):
26                 if self.function is not None:
27                         return self.function()
28                 else:
29                         return self.fixed
30
31         def setBoolean(self, value):
32                 assert self.function is None
33                 self.fixed = value
34                 self.poll()
35
36         boolean = property(getBoolean, setBoolean)
37
38         def poll(self):
39                 self.changed((self.CHANGED_ALL,))
40
41         def destroy(self):
42                 if self.poll_timer:
43                         self.poll_timer.callback.remove(self.poll)
44                 Source.destroy(self)