880274b423940ee761435d5c3ef964e45a21b55f
[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.master = None
11                 self.source = None
12
13         def connectDownstream(self, downstream):
14                 self.downstream_elements.append(downstream)
15                 if self.master is None:
16                         self.master = downstream
17         
18         def connectUpstream(self, upstream):
19                 assert self.source is None
20                 self.source = upstream
21                 self.changed()
22         
23         def connect(self, upstream):
24                 self.connectUpstream(upstream)
25                 upstream.connectDownstream(self)
26
27         # we disconnect from down to up
28         def disconnectAll(self):
29                 # we should not disconnect from upstream if
30                 # there are still elements depending on us.
31                 assert len(self.downstream_elements) == 0, "there are still downstream elements left"
32                 
33                 # Sources don't have a source themselves. don't do anything here.
34                 if self.source is not None:
35                         self.source.disconnectDownstream(self)
36         
37         def disconnectDownstream(self, downstream):
38                 self.downstream_elements.remove(downstream)
39                 if self.master == downstream:
40                         self.master = None
41                 
42                 if len(self.downstream_elements) == 0:
43                         self.disconnectAll()
44
45         # default action: push downstream
46         def changed(self, *args, **kwargs):
47                 self.downstream_elements.changed(*args, **kwargs)
48
49         def reconnectUpstream(self, new_upstream):
50                 assert self.source is not None
51                 self.source = new_upstream