annotate flax/subcomposer @ 134:f2f73a2171e6

many adjustments to the loops and timing many adjustments to the loops and timing now sends the hardware updates only when clients change, but at least 1Hz new option to adjust the rate of the loop that considers sending changes (if the lights have changed)
author drewp
date Sat, 14 Jun 2003 14:59:09 +0000
parents 6dfe10a54fc4
children feddef0d2fd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
128
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
1 #!/usr/bin/python
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
2
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
3 from __future__ import division, nested_scopes
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
4 import Tkinter as tk
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
5 from dmxchanedit import Levelbox
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
6 import sys,os,time,atexit
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
7 sys.path.append("../light8")
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
8 import dmxclient
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
9 import Patch
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
10 import Submaster
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
11
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
12 import dispatcher
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
13
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
14 def persistentlevels():
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
15 """adjusts levels from subcomposer.savedlevels, if possible; and
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
16 arranges to save the levels in that file upon exit"""
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
17 global levels
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
18 try:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
19 levels[:]=map(float,file("subcomposer.savedlevels","r").read().split())
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
20 except IOError:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
21 pass
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
22
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
23 atexit.register(lambda: file("subcomposer.savedlevels","w").
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
24 write(" ".join(map(str,levels))))
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
25
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
26 def levelchanged(channel,newlevel):
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
27 global lb, levels
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
28 if channel>len(levels):
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
29 return
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
30 levels[channel-1]=max(0,min(1,float(newlevel)))
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
31 lb.setlevels(levels)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
32
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
33 def savenewsub(levels,subname):
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
34 leveldict={}
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
35 for i,lev in zip(range(len(levels)),levels):
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
36 if lev!=0:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
37 leveldict[Patch.get_channel_name(i+1)]=lev
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
38
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
39 s=Submaster.Submaster(subname,leveldict)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
40 s.save()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
41 def Savebox(master,levels):
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
42 f=tk.Frame(master,bd=2,relief='raised')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
43 tk.Label(f,text="Save this as:").pack(side='left')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
44 e=tk.Entry(f)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
45 e.pack(side='left',exp=1,fill='x')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
46 def cmd():
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
47 subname=e.get()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
48 savenewsub(levels,subname)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
49 print "saved new sub",subname
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
50 tk.Button(f,text="Save",command=cmd).pack(side='left')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
51 return f
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
52
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
53 #############################
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
54
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
55 levels=[0]*68 # levels should never get overwritten, just edited
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
56 persistentlevels()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
57
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
58 root=tk.Tk()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
59 root.config(bg='black')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
60
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
61 lb=Levelbox(root)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
62 lb.pack(side='top')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
63
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
64 savebox=Savebox(root,levels)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
65 savebox.pack(side='top')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
66
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
67 # the dmx levels we edit and output, range is 0..1 (dmx chan 1 is
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
68 # the 0 element)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
69 lb.setlevels(levels)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
70
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
71 dispatcher.connect(levelchanged,"levelchanged")
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
72
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
73 lastupdate=0 # time we last sent to dmx
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
74
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
75 root.update() # get the windows drawn
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
76
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
77 lastsent=[] # copy of levels
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
78
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
79 def sendupdate():
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
80 global levels,lastupdate,lastsent
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
81 dmxclient.outputlevels(levels)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
82 lastupdate=time.time()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
83 lastsent=levels[:]
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
84
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
85 dispatcher.connect(sendupdate,"levelchanged")
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
86
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
87 while 1:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
88
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
89 if 0:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
90 for i in range(20): # don't let Tk take all the time
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
91 tk._tkinter.dooneevent()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
92 print "loop"
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
93 else:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
94 root.update()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
95
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
96 if lastsent!=levels or time.time()>lastupdate+1:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
97 sendupdate()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
98
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
99 time.sleep(.01)