Mercurial > code > home > repos > light9
comparison light8/Patch.py @ 0:45b12307c695
Initial revision
author | drewp |
---|---|
date | Wed, 03 Jul 2002 09:37:57 +0000 |
parents | |
children | f974a462133f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:45b12307c695 |
---|---|
1 def resolve_name(channelname): | |
2 "Ensure that we're talking about the primary name of the light." | |
3 return get_channel_name(get_dmx_channel(channelname)) | |
4 | |
5 def get_all_channels(): | |
6 """returns primary names for all channels (sorted)""" | |
7 prinames = reverse_patch.values()[:] | |
8 prinames.sort() | |
9 return prinames | |
10 | |
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: | |
19 raise ValueError("Invalid channel name: %s" % name) | |
20 | |
21 def get_channel_name(dmxnum): | |
22 try: | |
23 return reverse_patch[dmxnum] | |
24 except KeyError: | |
25 return str(dmxnum) | |
26 | |
27 def reload_data(): | |
28 global patch, reverse_patch | |
29 import patchdata | |
30 | |
31 reload(patchdata) | |
32 loadedpatch = patchdata.patch | |
33 patch = {} | |
34 reverse_patch = {} | |
35 for k, v in loadedpatch.items(): | |
36 if type(k) is tuple: | |
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 | |
43 | |
44 # importing patch will load initial data | |
45 reload_data() | |
46 |