Mercurial > code > home > repos > light9
comparison attic/Port.py @ 299:6931479b657a
Make attic, move a bunch of old files to it
author | David McClosky <dmcc@bigasterisk.com> |
---|---|
date | Mon, 20 Jun 2005 18:52:21 +0000 |
parents | Port.py@8856efb6516c |
children |
comparison
equal
deleted
inserted
replaced
298:d0f29e247af4 | 299:6931479b657a |
---|---|
1 from nodetypes import DiscoType | |
2 | |
3 ANY = -1 | |
4 | |
5 class Port: | |
6 def __setattr__(self, key, value): | |
7 '''Alias for __setitem___''' | |
8 self[key] = value | |
9 def __setitem__(self, key, value): | |
10 pass | |
11 def __getattr__(self, key): | |
12 '''Alias for __getitem___''' | |
13 return self[key] | |
14 def __getitem__(self, key): | |
15 pass | |
16 | |
17 class InputPort(Port): | |
18 def __init__(self, allowedtype, required=1, maxpins=ANY): | |
19 self.pins = [] | |
20 | |
21 class OutputPort(Port): | |
22 def __init__(self): | |
23 self.pins = [] | |
24 | |
25 class Pin: | |
26 def __init__(self, connection, value=DiscoType): | |
27 pass | |
28 | |
29 ''' | |
30 Snippet Pi=3: RFC 2: New port semantics | |
31 | |
32 # an example of the max node's op | |
33 def changed(self, inputs): | |
34 # note how this function does not use stateaccess, as it doesn't use state | |
35 return max(inputs.values()) | |
36 | |
37 # so, how the heck does this work? | |
38 # we check the function to get the names of kw args in the function. | |
39 # we always pass self, but everything else is optional | |
40 # the node asked for inputs, which looks like this: | |
41 # inputs = {'portname' : PortObj, 'portname2', PortObj} | |
42 # somehow, the PortObjs are max'ible. | |
43 # the node has only one output so it can just return the value to set the | |
44 # output. (maybe) | |
45 # alteratively, if we decide that you always return a new dict of outputs: | |
46 # return {'outputportname' : max(inputs.values())} | |
47 # which isn't horrible, but not great | |
48 | |
49 # another example: an adder. the node has ports A and B, and an output C: | |
50 # C also gets capped at stateaccess[min]. | |
51 def changed(self, a, b, c, stateaccess): | |
52 c.set(max(stateaccess['min'], a + b)) | |
53 return {} | |
54 | |
55 # or: | |
56 def changed(self, a, b, stateaccess): | |
57 c = max(stateaccess['min'], a + b) | |
58 return {'c' : c} | |
59 | |
60 # which i think is clearer. doing all port changes at the end has some | |
61 # book-keeping advantages (we can detect easily which ports are changed) | |
62 # the counter node could work this way: | |
63 | |
64 def changed(self, someoutput): | |
65 return {'someoutput' : someoutput + 1} | |
66 ''' | |
67 | |
68 ''' | |
69 type 1: a, b, d, e | |
70 type 2: b, c, d, f | |
71 | |
72 conversion maps: | |
73 a -> [ ] | |
74 b -> b | |
75 d -> d | |
76 e -> f | |
77 ''' |