Mercurial > code > home > repos > light9
annotate bin/subcomposer @ 804:317c2d2e22da
SC channel sort
Ignore-this: e97aabaf8011f385a661a519bdb3dd84
author | drewp@bigasterisk.com |
---|---|
date | Wed, 18 Jul 2012 10:07:22 +0000 |
parents | ce4fffe8e413 |
children | f29788d1c8c9 |
rev | line source |
---|---|
729
b5efddd80dad
update more shbang lines
Drew Perttula <drewp@bigasterisk.com>
parents:
577
diff
changeset
|
1 #!bin/python |
0 | 2 |
3 from __future__ import division, nested_scopes | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
4 from optparse import OptionParser |
0 | 5 import Tkinter as tk |
802 | 6 import louie as dispatcher |
803 | 7 from twisted.internet import reactor, tksupport, task |
0 | 8 |
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
201
diff
changeset
|
9 import run_local |
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
201
diff
changeset
|
10 from light9.dmxchanedit import Levelbox |
803 | 11 from light9 import dmxclient, Patch, Submaster, showconfig, prof |
455
9dd2baa41cca
subcomposer remembers window position
drewp@bigasterisk.com
parents:
450
diff
changeset
|
12 from light9.uihelpers import toplevelat |
803 | 13 from light9.rdfdb.syncedgraph import SyncedGraph |
0 | 14 |
15 class Subcomposer(tk.Frame): | |
803 | 16 def __init__(self, master, graph): |
0 | 17 tk.Frame.__init__(self, master, bg='black') |
803 | 18 self.graph = graph |
0 | 19 |
803 | 20 self.levelbox = Levelbox(self, graph) |
0 | 21 self.levelbox.pack(side='top') |
22 | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
23 self.savebox = EntryCommand(self, cmd=self.savenewsub) |
0 | 24 self.savebox.pack(side='top') |
25 | |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
342
diff
changeset
|
26 self.loadbox = EntryCommand(self, verb="Load", cmd=self.loadsub) |
0 | 27 self.loadbox.pack(side='top') |
28 | |
29 def alltozero(): | |
803 | 30 for lev in self.levelbox.levels: |
31 lev.setlevel(0) | |
0 | 32 |
149 | 33 tk.Button(self, text="all to zero", command=alltozero).pack(side='top') |
0 | 34 |
803 | 35 dispatcher.connect(self.sendupdate, "levelchanged") |
0 | 36 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
37 def fill_both_boxes(self, subname): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
38 for box in [self.savebox, self.loadbox]: |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
39 box.set(subname) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
40 |
0 | 41 def save_levels(self, *args): |
42 levelfile = file("subcomposer.savedlevels","w") | |
43 levelfile.write(" ".join(map(str, self.levels))) | |
802 | 44 |
0 | 45 def load_levels(self): |
46 try: | |
47 levelfile = file("subcomposer.savedlevels","r") | |
48 levels = map(float, levelfile.read().split()) | |
49 self.set_levels(levels) | |
50 except IOError: | |
51 pass | |
802 | 52 |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
342
diff
changeset
|
53 def savenewsub(self, subname): |
0 | 54 leveldict={} |
55 for i,lev in zip(range(len(self.levels)),self.levels): | |
56 if lev!=0: | |
57 leveldict[Patch.get_channel_name(i+1)]=lev | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
58 |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
342
diff
changeset
|
59 s=Submaster.Submaster(subname,leveldict=leveldict) |
0 | 60 s.save() |
802 | 61 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
62 def loadsub(self, subname): |
0 | 63 """puts a sub into the levels, replacing old level values""" |
577 | 64 s=Submaster.Submasters(showconfig.getGraph()).get_sub_by_name(subname) |
380
a13f2caf6f25
fix SC dragging after you load a sub
Drew Perttula <drewp@bigasterisk.com>
parents:
351
diff
changeset
|
65 self.set_levels(s.get_dmx_list()) |
0 | 66 dispatcher.send("levelchanged") |
802 | 67 |
803 | 68 def toDmxLevels(self): |
69 # the dmx levels we edit and output, range is 0..1 (dmx chan 1 is | |
70 # the 0 element) | |
71 out = {} | |
72 for lev in self.levelbox.levels: | |
73 out[lev.channelnum] = lev.currentlevel | |
74 if not out: | |
75 return [] | |
76 | |
77 return [out.get(i, 0) for i in range(max(out.keys()) + 1)] | |
78 | |
0 | 79 def sendupdate(self): |
803 | 80 dmxclient.outputlevels(self.toDmxLevels(), twisted=True) |
802 | 81 |
0 | 82 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
83 class EntryCommand(tk.Frame): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
84 def __init__(self, master, verb="Save", cmd=None): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
85 tk.Frame.__init__(self, master, bd=2, relief='raised') |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
86 tk.Label(self, text="Sub name:").pack(side='left') |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
87 self.cmd = cmd |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
88 self.entry = tk.Entry(self) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
89 self.entry.pack(side='left', expand=True, fill='x') |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
90 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
91 self.entry.bind("<Return>", self.action) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
92 tk.Button(self, text=verb, command=self.action).pack(side='left') |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
93 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
94 def action(self, *args): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
95 subname = self.entry.get() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
96 self.cmd(subname) |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
342
diff
changeset
|
97 print "sub", self.cmd, subname |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
98 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
99 def set(self, text): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
100 self.entry.delete(0, 'end') |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
101 self.entry.insert(0, text) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
102 |
149 | 103 |
0 | 104 ############################# |
105 | |
106 if __name__ == "__main__": | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
107 parser = OptionParser(usage="%prog [subname]") |
458
8b307310cc1b
when KC launches SC to edit a sub, don't place the window right on the main SC window
drewp@bigasterisk.com
parents:
455
diff
changeset
|
108 parser.add_option('--no-geometry', action='store_true', |
8b307310cc1b
when KC launches SC to edit a sub, don't place the window right on the main SC window
drewp@bigasterisk.com
parents:
455
diff
changeset
|
109 help="don't save/restore window geometry") |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
110 opts, args = parser.parse_args() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
111 |
0 | 112 root=tk.Tk() |
113 root.config(bg='black') | |
147 | 114 root.tk_setPalette("#004633") |
458
8b307310cc1b
when KC launches SC to edit a sub, don't place the window right on the main SC window
drewp@bigasterisk.com
parents:
455
diff
changeset
|
115 if not opts.no_geometry: |
8b307310cc1b
when KC launches SC to edit a sub, don't place the window right on the main SC window
drewp@bigasterisk.com
parents:
455
diff
changeset
|
116 toplevelat("subcomposer", root) |
0 | 117 |
803 | 118 graph = SyncedGraph("subcomposer") |
119 | |
120 sc = Subcomposer(root, graph) | |
0 | 121 sc.pack() |
122 | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
123 tk.Label(root,text="Bindings: B1 adjust level; B2 set full; B3 instant bump", |
228
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
209
diff
changeset
|
124 font="Helvetica -12 italic",anchor='w').pack(side='top',fill='x') |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
125 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
126 if len(args) == 1: |
458
8b307310cc1b
when KC launches SC to edit a sub, don't place the window right on the main SC window
drewp@bigasterisk.com
parents:
455
diff
changeset
|
127 root.config(bg='green') # trying to make these look distinctive |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
128 sc.loadsub(args[0]) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
129 sc.fill_both_boxes(args[0]) |
228
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
209
diff
changeset
|
130 |
803 | 131 task.LoopingCall(sc.sendupdate).start(1) |
557
4e558643c952
subcomposer: squelch the exception we got every time we exited
David McClosky <dmcc@bigasterisk.com>
parents:
458
diff
changeset
|
132 |
803 | 133 tksupport.install(root,ms=10) |
134 prof.run(reactor.run, profile=False) |