1 from Tools.CList import CList
4 # Render Converter Converter Source
6 # a bidirectional connection
9 self.downstream_elements = CList()
13 def connectDownstream(self, downstream):
14 self.downstream_elements.append(downstream)
15 if self.master is None:
16 self.master = downstream
18 def connectUpstream(self, upstream):
19 assert self.source is None
20 self.source = upstream
23 def connect(self, upstream):
24 self.connectUpstream(upstream)
25 upstream.connectDownstream(self)
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"
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)
37 def disconnectDownstream(self, downstream):
38 self.downstream_elements.remove(downstream)
39 if self.master == downstream:
42 if len(self.downstream_elements) == 0:
45 # default action: push downstream
46 def changed(self, *args, **kwargs):
47 self.downstream_elements.changed(*args, **kwargs)
49 def reconnectUpstream(self, new_upstream):
50 assert self.source is not None
51 self.source = new_upstream