annotate flax/subcomposer @ 142:feddef0d2fd4

now can load a sub into the display too
author drewp
date Sun, 15 Jun 2003 15:19:53 +0000
parents 6dfe10a54fc4
children
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
142
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
26 def levelchanged(channel=None,newlevel=None):
128
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
27 global lb, levels
142
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
28 if channel is not None and newlevel is not None:
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
29 if channel>len(levels):
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
30 return
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
31 levels[channel-1]=max(0,min(1,float(newlevel)))
128
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
32 lb.setlevels(levels)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
33
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
34 def savenewsub(levels,subname):
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
35 leveldict={}
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
36 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
37 if lev!=0:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
38 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
39
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
40 s=Submaster.Submaster(subname,leveldict)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
41 s.save()
142
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
42 def loadsub(levels,subname):
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
43 """puts a sub into the levels, replacing old level values"""
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
44 s=Submaster.Submasters().get_sub_by_name(subname)
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
45 levels[:]=[0]*68
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
46 levels[:]=s.get_dmx_list()
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
47 dispatcher.send("levelchanged")
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
48 def Savebox(master,levels,verb="Save",
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
49 cmd=savenewsub):
128
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
50 f=tk.Frame(master,bd=2,relief='raised')
142
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
51 tk.Label(f,text="Sub name:").pack(side='left')
128
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
52 e=tk.Entry(f)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
53 e.pack(side='left',exp=1,fill='x')
142
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
54 def cb(*args):
128
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
55 subname=e.get()
142
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
56 cmd(levels,subname)
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
57 print "sub",verb,subname
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
58 e.bind("<Return>",cb)
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
59 tk.Button(f,text=verb,command=cb).pack(side='left')
128
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
60 return f
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
61
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
62 #############################
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 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
65 persistentlevels()
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 root=tk.Tk()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
68 root.config(bg='black')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
69
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
70 lb=Levelbox(root)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
71 lb.pack(side='top')
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 savebox=Savebox(root,levels)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
74 savebox.pack(side='top')
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
75
142
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
76 loadbox=Savebox(root,levels,verb="Load",cmd=loadsub)
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
77 loadbox.pack(side='top')
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
78
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
79 def alltozero():
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
80 levels[:]=[0]*68
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
81 dispatcher.send("levelchanged")
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
82 tk.Button(root,text="all to zero",command=alltozero).pack(side='top')
feddef0d2fd4 now can load a sub into the display too
drewp
parents: 128
diff changeset
83
128
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
84 # 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
85 # the 0 element)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
86 lb.setlevels(levels)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
87
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
88 dispatcher.connect(levelchanged,"levelchanged")
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
89
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
90 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
91
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
92 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
93
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
94 lastsent=[] # copy of levels
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 def sendupdate():
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
97 global levels,lastupdate,lastsent
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
98 dmxclient.outputlevels(levels)
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
99 lastupdate=time.time()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
100 lastsent=levels[:]
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
101
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
102 dispatcher.connect(sendupdate,"levelchanged")
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
103
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
104 while 1:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
105
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
106 if 0:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
107 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
108 tk._tkinter.dooneevent()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
109 print "loop"
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
110 else:
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
111 root.update()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
112
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
113 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
114 sendupdate()
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
115
6dfe10a54fc4 new program to adjust indiv dmx channels and save the settings as new submasters
drewp
parents:
diff changeset
116 time.sleep(.01)