Mercurial > code > home > repos > light9
annotate bin/subcomposer @ 810:f29788d1c8c9
kc/sc session control
Ignore-this: bd0be61e7cd08e65118fdb96914470dc
author | drewp@bigasterisk.com |
---|---|
date | Mon, 23 Jul 2012 12:03:06 +0000 |
parents | 317c2d2e22da |
children | 6885c2fa9369 |
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 |
810 | 14 from light9.rdfdb import clientsession |
0 | 15 |
16 class Subcomposer(tk.Frame): | |
810 | 17 def __init__(self, master, graph, session): |
0 | 18 tk.Frame.__init__(self, master, bg='black') |
803 | 19 self.graph = graph |
810 | 20 self.session = session |
0 | 21 |
803 | 22 self.levelbox = Levelbox(self, graph) |
0 | 23 self.levelbox.pack(side='top') |
24 | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
25 self.savebox = EntryCommand(self, cmd=self.savenewsub) |
0 | 26 self.savebox.pack(side='top') |
27 | |
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
|
28 self.loadbox = EntryCommand(self, verb="Load", cmd=self.loadsub) |
0 | 29 self.loadbox.pack(side='top') |
30 | |
31 def alltozero(): | |
803 | 32 for lev in self.levelbox.levels: |
33 lev.setlevel(0) | |
0 | 34 |
149 | 35 tk.Button(self, text="all to zero", command=alltozero).pack(side='top') |
0 | 36 |
803 | 37 dispatcher.connect(self.sendupdate, "levelchanged") |
0 | 38 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
39 def fill_both_boxes(self, subname): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
40 for box in [self.savebox, self.loadbox]: |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
41 box.set(subname) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
42 |
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
|
43 def savenewsub(self, subname): |
0 | 44 leveldict={} |
45 for i,lev in zip(range(len(self.levels)),self.levels): | |
46 if lev!=0: | |
47 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
|
48 |
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
|
49 s=Submaster.Submaster(subname,leveldict=leveldict) |
0 | 50 s.save() |
802 | 51 |
810 | 52 # this is going to be more like 'tie to sub' and 'untied' |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
53 def loadsub(self, subname): |
0 | 54 """puts a sub into the levels, replacing old level values""" |
577 | 55 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
|
56 self.set_levels(s.get_dmx_list()) |
0 | 57 dispatcher.send("levelchanged") |
802 | 58 |
803 | 59 def toDmxLevels(self): |
60 # the dmx levels we edit and output, range is 0..1 (dmx chan 1 is | |
61 # the 0 element) | |
62 out = {} | |
63 for lev in self.levelbox.levels: | |
64 out[lev.channelnum] = lev.currentlevel | |
65 if not out: | |
66 return [] | |
67 | |
68 return [out.get(i, 0) for i in range(max(out.keys()) + 1)] | |
69 | |
0 | 70 def sendupdate(self): |
803 | 71 dmxclient.outputlevels(self.toDmxLevels(), twisted=True) |
802 | 72 |
0 | 73 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
74 class EntryCommand(tk.Frame): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
75 def __init__(self, master, verb="Save", cmd=None): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
76 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
|
77 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
|
78 self.cmd = cmd |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
79 self.entry = tk.Entry(self) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
80 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
|
81 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
82 self.entry.bind("<Return>", self.action) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
83 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
|
84 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
85 def action(self, *args): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
86 subname = self.entry.get() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
87 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
|
88 print "sub", self.cmd, subname |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
89 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
90 def set(self, text): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
91 self.entry.delete(0, 'end') |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
92 self.entry.insert(0, text) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
93 |
149 | 94 |
0 | 95 ############################# |
96 | |
97 if __name__ == "__main__": | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
98 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
|
99 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
|
100 help="don't save/restore window geometry") |
810 | 101 clientsession.add_option(parser) |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
102 opts, args = parser.parse_args() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
103 |
0 | 104 root=tk.Tk() |
105 root.config(bg='black') | |
147 | 106 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
|
107 if not opts.no_geometry: |
810 | 108 toplevelat("subcomposer - %s" % opts.session, root) |
0 | 109 |
803 | 110 graph = SyncedGraph("subcomposer") |
810 | 111 session = clientsession.getUri('subcomposer', opts) |
803 | 112 |
810 | 113 sc = Subcomposer(root, graph, session) |
0 | 114 sc.pack() |
115 | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
116 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
|
117 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
|
118 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
119 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
|
120 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
|
121 sc.loadsub(args[0]) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
122 sc.fill_both_boxes(args[0]) |
228
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
209
diff
changeset
|
123 |
803 | 124 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
|
125 |
810 | 126 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
803 | 127 tksupport.install(root,ms=10) |
128 prof.run(reactor.run, profile=False) |