1 from Tools.CList import CList
4 # Render Converter Converter Source
6 # a bidirectional connection
8 CHANGED_DEFAULT = 0 # initial "pull" state
9 CHANGED_ALL = 1 # really everything changed
10 CHANGED_CLEAR = 2 # we're expecting a real update soon. don't bother polling NOW, but clear data.
11 CHANGED_SPECIFIC = 3 # second tuple will specify what exactly changed
12 CHANGED_POLL = 4 # a timer expired
15 self.downstream_elements = CList()
20 def connectDownstream(self, downstream):
21 self.downstream_elements.append(downstream)
22 if self.master is None:
23 self.master = downstream
25 def connectUpstream(self, upstream):
26 assert self.source is None
27 self.source = upstream
28 self.changed((self.CHANGED_DEFAULT,))
30 def connect(self, upstream):
31 self.connectUpstream(upstream)
32 upstream.connectDownstream(self)
34 # we disconnect from down to up
35 def disconnectAll(self):
36 # we should not disconnect from upstream if
37 # there are still elements depending on us.
38 assert len(self.downstream_elements) == 0, "there are still downstream elements left"
40 # Sources don't have a source themselves. don't do anything here.
41 if self.source is not None:
42 self.source.disconnectDownstream(self)
44 def disconnectDownstream(self, downstream):
45 self.downstream_elements.remove(downstream)
46 if self.master == downstream:
49 if len(self.downstream_elements) == 0:
52 # default action: push downstream
53 def changed(self, *args, **kwargs):
55 self.downstream_elements.changed(*args, **kwargs)
58 def reconnectUpstream(self, new_upstream):
59 assert self.source is not None
60 self.source = new_upstream