Mercurial > code > home > repos > light9
annotate light8/Patch.py @ 143:79aabb5db3ce
new subs from today's show
author | drewp |
---|---|
date | Sun, 15 Jun 2003 15:20:53 +0000 |
parents | f2eb20a52555 |
children |
rev | line source |
---|---|
85
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
1 def resolve_name(channelname): |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
2 "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
|
3 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
|
4 |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
5 def get_all_channels(): |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
6 """returns primary names for all channels (sorted)""" |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
7 prinames = reverse_patch.values()[:] |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
8 prinames.sort() |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
9 return prinames |
174b35926067
converts subs from dicts to tab-sep-values and back again
drewp
parents:
42
diff
changeset
|
10 |
0 | 11 def get_dmx_channel(name): |
12 if name in patch: | |
13 return patch[name] | |
14 | |
15 try: | |
16 i = int(name) | |
17 return i | |
18 except ValueError: | |
42
5e4fb4ac2d18
corrected Patch's error behavior and subediting's catching behavior
drewp
parents:
4
diff
changeset
|
19 raise ValueError("Invalid channel name: %s" % name) |
0 | 20 |
21 def get_channel_name(dmxnum): | |
22 try: | |
23 return reverse_patch[dmxnum] | |
24 except KeyError: | |
25 return str(dmxnum) | |
26 | |
129 | 27 def reload_data(): |
0 | 28 global patch, reverse_patch |
129 | 29 import patchdata |
0 | 30 |
129 | 31 reload(patchdata) |
32 loadedpatch = patchdata.patch | |
0 | 33 patch = {} |
34 reverse_patch = {} | |
35 for k, v in loadedpatch.items(): | |
129 | 36 if type(k) is tuple: |
0 | 37 for name in k: |
38 patch[name] = v | |
39 reverse_patch[v] = k[0] | |
40 else: | |
41 patch[k] = v | |
42 reverse_patch[v] = k | |
129 | 43 |
44 # importing patch will load initial data | |
45 reload_data() | |
46 |