annotate light8/Patch.py @ 116:9ddea0c614ee

much prettier stdout, including a clock (so you can tell the server's running) much prettier stdout, including a clock (so you can tell the server's running) and channel updates only when the levels change, and throttled to every 100 updates even then.
author drewp
date Fri, 13 Jun 2003 06:15:28 +0000
parents 174b35926067
children f2eb20a52555
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
1 from types import TupleType
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 def get_dmx_channel(name):
45b12307c695 Initial revision
drewp
parents:
diff changeset
17 if name in patch:
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 return patch[name]
45b12307c695 Initial revision
drewp
parents:
diff changeset
19
45b12307c695 Initial revision
drewp
parents:
diff changeset
20 try:
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 i = int(name)
45b12307c695 Initial revision
drewp
parents:
diff changeset
22 return i
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
25
45b12307c695 Initial revision
drewp
parents:
diff changeset
26 def get_channel_name(dmxnum):
45b12307c695 Initial revision
drewp
parents:
diff changeset
27 try:
45b12307c695 Initial revision
drewp
parents:
diff changeset
28 return reverse_patch[dmxnum]
45b12307c695 Initial revision
drewp
parents:
diff changeset
29 except KeyError:
45b12307c695 Initial revision
drewp
parents:
diff changeset
30 return str(dmxnum)
45b12307c695 Initial revision
drewp
parents:
diff changeset
31
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
32 def reload_data(dummy):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
33 global patch, reverse_patch
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
34 if dummy:
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
35 import ConfigDummy as Config
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
36 else:
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
37 import Config
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
38
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
39 reload(Config)
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
40 loadedpatch = Config.patch
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
41 patch = {}
45b12307c695 Initial revision
drewp
parents:
diff changeset
42 reverse_patch = {}
45b12307c695 Initial revision
drewp
parents:
diff changeset
43 for k, v in loadedpatch.items():
4
f974a462133f added light8 from the posted light8-1.0.tgz
drewp
parents: 0
diff changeset
44 if type(k) == TupleType:
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
45 for name in k:
45b12307c695 Initial revision
drewp
parents:
diff changeset
46 patch[name] = v
45b12307c695 Initial revision
drewp
parents:
diff changeset
47 reverse_patch[v] = k[0]
45b12307c695 Initial revision
drewp
parents:
diff changeset
48 else:
45b12307c695 Initial revision
drewp
parents:
diff changeset
49 patch[k] = v
45b12307c695 Initial revision
drewp
parents:
diff changeset
50 reverse_patch[v] = k