use single argument only
[enigma2.git] / lib / python / Components / Element.py
1 from Tools.CList import CList
2
3 # down                       up
4 # Render Converter Converter Source
5
6 # a bidirectional connection
7 class Element:
8         def __init__(self):
9                 self.downstream_elements = CList()
10                 self.upstream_elements = CList()
11                 self.master = None
12                 self.source = None
13
14         def connectDownstream(self, downstream):
15                 self.downstream_elements.append(downstream)
16                 if self.master is None:
17                         self.master = downstream
18         
19         def connectUpstream(self, upstream):
20                 self.upstream_elements.append(upstream)
21                 self.source = upstream # for single-source elements (i.e., most of them.)
22                 self.changed()
23         
24         def connect(self, upstream):
25                 self.connectUpstream(upstream)
26                 upstream.connectDownstream(self)
27
28         # we disconnect from down to up
29         def disconnectAll(self):
30                 # we should not disconnect from upstream if
31                 # there are still elements depending on us.
32                 assert len(self.downstream_elements) == 0, "there are still downstream elements left"
33                 
34                 # disconnect all upstream elements from us
35                 for upstream in self.upstream_elements:
36                         upstream.disconnectDownstream(self)
37         
38         def disconnectDownstream(self, downstream):
39                 self.downstream_elements.remove(downstream)
40                 if self.master == downstream:
41                         self.master = None
42                 
43                 if len(self.downstream_elements) == 0:
44                         self.disconnectAll()
45
46         # default action: push downstream
47         def changed(self, *args, **kwargs):
48                 self.downstream_elements.changed(*args, **kwargs)