Mercurial > code > home > repos > light9
annotate light8/Patch.py @ 119:6f9898f00c9c
now uses dmxclient to talk to dmxserver
author | drewp |
---|---|
date | Fri, 13 Jun 2003 13:59:32 +0000 |
parents | 174b35926067 |
children | f2eb20a52555 |
rev | line source |
---|---|
4 | 1 from types import TupleType |
0 | 2 |
85
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
3 |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
4 def resolve_name(channelname): |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
5 "Ensure that we're talking about the primary name of the light." |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
6 return get_channel_name(get_dmx_channel(channelname)) |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
7 |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
8 |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
9 def get_all_channels(): |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
10 """returns primary names for all channels (sorted)""" |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
11 prinames = reverse_patch.values()[:] |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
12 prinames.sort() |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
13 return prinames |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
14 |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
15 |
0 | 16 def get_dmx_channel(name): |
17 if name in patch: | |
18 return patch[name] | |
19 | |
20 try: | |
21 i = int(name) | |
22 return i | |
23 except ValueError: | |
42
5e4fb4ac2d18
corrected Patch's error behavior and subediting's catching behavior
drewp
parents:
4
diff
changeset
|
24 raise ValueError("Invalid channel name: %s" % name) |
0 | 25 |
26 def get_channel_name(dmxnum): | |
27 try: | |
28 return reverse_patch[dmxnum] | |
29 except KeyError: | |
30 return str(dmxnum) | |
31 | |
4 | 32 def reload_data(dummy): |
0 | 33 global patch, reverse_patch |
4 | 34 if dummy: |
35 import ConfigDummy as Config | |
36 else: | |
37 import Config | |
0 | 38 |
4 | 39 reload(Config) |
40 loadedpatch = Config.patch | |
0 | 41 patch = {} |
42 reverse_patch = {} | |
43 for k, v in loadedpatch.items(): | |
4 | 44 if type(k) == TupleType: |
0 | 45 for name in k: |
46 patch[name] = v | |
47 reverse_patch[v] = k[0] | |
48 else: | |
49 patch[k] = v | |
50 reverse_patch[v] = k |