Mercurial > code > home > repos > light9
annotate bin/subcomposer @ 803:ce4fffe8e413
update SC to read rdf graph
Ignore-this: 7f6788bae887723c9ac12644c1a382da
author | drewp@bigasterisk.com |
---|---|
date | Wed, 18 Jul 2012 09:59:10 +0000 |
parents | 5442f5d8979a |
children | 317c2d2e22da |
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 | |
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
201
diff
changeset
|
4 import sys,os,time,atexit |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
5 from optparse import OptionParser |
0 | 6 import Tkinter as tk |
802 | 7 import louie as dispatcher |
803 | 8 from twisted.internet import reactor, tksupport, task |
0 | 9 |
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
201
diff
changeset
|
10 import run_local |
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
201
diff
changeset
|
11 from light9.dmxchanedit import Levelbox |
803 | 12 from light9 import dmxclient, Patch, Submaster, showconfig, prof |
455
9dd2baa41cca
subcomposer remembers window position
drewp@bigasterisk.com
parents:
450
diff
changeset
|
13 from light9.uihelpers import toplevelat |
803 | 14 from light9.rdfdb.syncedgraph import SyncedGraph |
0 | 15 |
16 class Subcomposer(tk.Frame): | |
803 | 17 def __init__(self, master, graph): |
0 | 18 tk.Frame.__init__(self, master, bg='black') |
803 | 19 self.graph = graph |
0 | 20 |
803 | 21 self.levelbox = Levelbox(self, graph) |
0 | 22 self.levelbox.pack(side='top') |
23 | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
24 self.savebox = EntryCommand(self, cmd=self.savenewsub) |
0 | 25 self.savebox.pack(side='top') |
26 | |
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
|
27 self.loadbox = EntryCommand(self, verb="Load", cmd=self.loadsub) |
0 | 28 self.loadbox.pack(side='top') |
29 | |
30 def alltozero(): | |
803 | 31 for lev in self.levelbox.levels: |
32 lev.setlevel(0) | |
0 | 33 |
149 | 34 tk.Button(self, text="all to zero", command=alltozero).pack(side='top') |
0 | 35 |
803 | 36 dispatcher.connect(self.sendupdate, "levelchanged") |
0 | 37 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
38 def fill_both_boxes(self, subname): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
39 for box in [self.savebox, self.loadbox]: |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
40 box.set(subname) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
41 |
0 | 42 def save_levels(self, *args): |
43 levelfile = file("subcomposer.savedlevels","w") | |
44 levelfile.write(" ".join(map(str, self.levels))) | |
802 | 45 |
0 | 46 def load_levels(self): |
47 try: | |
48 levelfile = file("subcomposer.savedlevels","r") | |
49 levels = map(float, levelfile.read().split()) | |
50 self.set_levels(levels) | |
51 except IOError: | |
52 pass | |
802 | 53 |
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
|
54 def savenewsub(self, subname): |
0 | 55 leveldict={} |
56 for i,lev in zip(range(len(self.levels)),self.levels): | |
57 if lev!=0: | |
58 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
|
59 |
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
|
60 s=Submaster.Submaster(subname,leveldict=leveldict) |
0 | 61 s.save() |
802 | 62 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
63 def loadsub(self, subname): |
0 | 64 """puts a sub into the levels, replacing old level values""" |
577 | 65 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
|
66 self.set_levels(s.get_dmx_list()) |
0 | 67 dispatcher.send("levelchanged") |
802 | 68 |
803 | 69 def toDmxLevels(self): |
70 # the dmx levels we edit and output, range is 0..1 (dmx chan 1 is | |
71 # the 0 element) | |
72 out = {} | |
73 for lev in self.levelbox.levels: | |
74 out[lev.channelnum] = lev.currentlevel | |
75 if not out: | |
76 return [] | |
77 | |
78 return [out.get(i, 0) for i in range(max(out.keys()) + 1)] | |
79 | |
0 | 80 def sendupdate(self): |
803 | 81 dmxclient.outputlevels(self.toDmxLevels(), twisted=True) |
802 | 82 |
0 | 83 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
84 class EntryCommand(tk.Frame): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
85 def __init__(self, master, verb="Save", cmd=None): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
86 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
|
87 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
|
88 self.cmd = cmd |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
89 self.entry = tk.Entry(self) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
90 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
|
91 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
92 self.entry.bind("<Return>", self.action) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
93 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
|
94 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
95 def action(self, *args): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
96 subname = self.entry.get() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
97 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
|
98 print "sub", self.cmd, subname |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
99 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
100 def set(self, text): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
101 self.entry.delete(0, 'end') |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
102 self.entry.insert(0, text) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
103 |
149 | 104 |
0 | 105 ############################# |
106 | |
107 if __name__ == "__main__": | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
108 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
|
109 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
|
110 help="don't save/restore window geometry") |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
111 opts, args = parser.parse_args() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
112 |
0 | 113 root=tk.Tk() |
114 root.config(bg='black') | |
147 | 115 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
|
116 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
|
117 toplevelat("subcomposer", root) |
0 | 118 |
803 | 119 graph = SyncedGraph("subcomposer") |
120 | |
121 sc = Subcomposer(root, graph) | |
0 | 122 sc.pack() |
123 | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
124 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
|
125 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
|
126 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
127 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
|
128 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
|
129 sc.loadsub(args[0]) |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
130 sc.fill_both_boxes(args[0]) |
228
9827df597f86
added help texts to subcomposer, curvecalc
drewp@bigasterisk.com
parents:
209
diff
changeset
|
131 |
803 | 132 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
|
133 |
803 | 134 tksupport.install(root,ms=10) |
135 prof.run(reactor.run, profile=False) |