Mercurial > code > home > repos > light9
annotate flax/Subcomposer.py @ 144:f433e95f2e42
subcomposer is now a module. You can still run it from the command
subcomposer is now a module. You can still run it from the command
line. If you want it to work as a module, you need to call the
considersendupdate() method with the period of the after loop that it
should use.
author | dmcc |
---|---|
date | Wed, 02 Jul 2003 10:21:59 +0000 |
parents | 45b12307c695 |
children | 6a1f4becb1db |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 | |
3 from __future__ import division, nested_scopes | |
4 import Tkinter as tk | |
5 from dmxchanedit import Levelbox | |
6 import sys,os,time,atexit | |
7 sys.path.append("../light8") | |
8 import dmxclient | |
9 import Patch | |
10 import Submaster | |
11 | |
144
f433e95f2e42
subcomposer is now a module. You can still run it from the command
dmcc
parents:
0
diff
changeset
|
12 import dispatcher |
0 | 13 |
14 class Subcomposer(tk.Frame): | |
144
f433e95f2e42
subcomposer is now a module. You can still run it from the command
dmcc
parents:
0
diff
changeset
|
15 def __init__(self, master, levelboxopts=None, dmxdummy=0, numchannels=68): |
0 | 16 tk.Frame.__init__(self, master, bg='black') |
17 self.dmxdummy = dmxdummy | |
18 self.numchannels = numchannels | |
19 | |
20 self.levels = [0]*68 # levels should never get overwritten, just edited | |
21 | |
22 self.levelbox = Levelbox(self) | |
23 self.levelbox.pack(side='top') | |
24 # the dmx levels we edit and output, range is 0..1 (dmx chan 1 is | |
25 # the 0 element) | |
26 self.levelbox.setlevels(self.levels) | |
27 | |
28 self.savebox = Savebox(self, self.levels, cmd=self.savenewsub) | |
29 self.savebox.pack(side='top') | |
30 | |
31 self.loadbox = Savebox(self, self.levels, verb="Load", cmd=self.loadsub) | |
32 self.loadbox.pack(side='top') | |
33 | |
34 def alltozero(): | |
35 self.set_levels([0] * self.numchannels) | |
36 dispatcher.send("levelchanged") | |
37 | |
38 tk.Button(self, text="all to zero", command=alltozero).pack(side='top') | |
39 | |
40 dispatcher.connect(self.levelchanged,"levelchanged") | |
41 dispatcher.connect(self.sendupdate,"levelchanged") | |
42 | |
144
f433e95f2e42
subcomposer is now a module. You can still run it from the command
dmcc
parents:
0
diff
changeset
|
43 self.persistentlevels() |
0 | 44 |
45 self.lastupdate=0 # time we last sent to dmx | |
46 | |
47 self.lastsent=[] # copy of levels | |
48 | |
49 def persistentlevels(self): | |
50 """adjusts levels from subcomposer.savedlevels, if possible; and | |
51 arranges to save the levels in that file upon exit""" | |
52 self.load_levels() | |
53 atexit.register(self.save_levels) | |
54 def save_levels(self, *args): | |
55 levelfile = file("subcomposer.savedlevels","w") | |
56 levelfile.write(" ".join(map(str, self.levels))) | |
57 def load_levels(self): | |
58 try: | |
59 levelfile = file("subcomposer.savedlevels","r") | |
60 levels = map(float, levelfile.read().split()) | |
61 self.set_levels(levels) | |
62 except IOError: | |
63 pass | |
64 def levelchanged(self, channel=None, newlevel=None): | |
65 if channel is not None and newlevel is not None: | |
66 if channel>len(self.levels): | |
67 return | |
68 self.levels[channel-1]=max(0,min(1,float(newlevel))) | |
69 self.levelbox.setlevels(self.levels) | |
144
f433e95f2e42
subcomposer is now a module. You can still run it from the command
dmcc
parents:
0
diff
changeset
|
70 def savenewsub(self, subname): |
0 | 71 leveldict={} |
72 for i,lev in zip(range(len(self.levels)),self.levels): | |
73 if lev!=0: | |
74 leveldict[Patch.get_channel_name(i+1)]=lev | |
75 | |
76 s=Submaster.Submaster(subname,leveldict) | |
77 s.save() | |
144
f433e95f2e42
subcomposer is now a module. You can still run it from the command
dmcc
parents:
0
diff
changeset
|
78 def loadsub(self, subname): |
0 | 79 """puts a sub into the levels, replacing old level values""" |
80 s=Submaster.Submasters().get_sub_by_name(subname) | |
81 self.levels[:]=[0]*68 | |
82 self.levels[:]=s.get_dmx_list() | |
83 dispatcher.send("levelchanged") | |
84 def sendupdate(self): | |
85 if not self.dmxdummy: | |
86 dmxclient.outputlevels(self.levels) | |
87 self.lastupdate = time.time() | |
88 self.lastsent = self.levels[:] | |
89 def considersendupdate(self, use_after_loop=0): | |
90 """If use_after_loop is true, it is the period of the after loop.""" | |
91 if self.lastsent != self.levels or time.time() > self.lastupdate + 1: | |
92 self.sendupdate() | |
93 if use_after_loop: | |
94 self.after(use_after_loop, self.considersendupdate, use_after_loop) | |
95 def set_levels(self, levels): | |
96 self.levels[:] = levels | |
97 dispatcher.send("levelchanged") | |
98 | |
99 def Savebox(master, levels, verb="Save", cmd=None): | |
100 f=tk.Frame(master,bd=2,relief='raised') | |
101 tk.Label(f,text="Sub name:").pack(side='left') | |
102 e=tk.Entry(f) | |
103 e.pack(side='left',exp=1,fill='x') | |
104 def cb(*args): | |
105 subname=e.get() | |
106 cmd(levels,subname) | |
107 print "sub",verb,subname | |
108 e.bind("<Return>",cb) | |
109 tk.Button(f,text=verb,command=cb).pack(side='left') | |
110 return f | |
111 | |
112 ############################# | |
113 | |
114 if __name__ == "__main__": | |
115 root=tk.Tk() | |
116 root.config(bg='black') | |
117 | |
144
f433e95f2e42
subcomposer is now a module. You can still run it from the command
dmcc
parents:
0
diff
changeset
|
118 sc = Subcomposer(root, dmxdummy=1) |
0 | 119 sc.pack() |
120 | |
121 while 1: | |
122 if 0: | |
123 for i in range(20): # don't let Tk take all the time | |
124 tk._tkinter.dooneevent() | |
125 print "loop" | |
126 else: | |
127 root.update() | |
128 | |
129 sc.considersendupdate() | |
130 time.sleep(.01) |