Files
@ 317c2d2e22da
Branch filter:
Location: light9/bin/subcomposer
317c2d2e22da
4.1 KiB
text/plain
SC channel sort
Ignore-this: e97aabaf8011f385a661a519bdb3dd84
Ignore-this: e97aabaf8011f385a661a519bdb3dd84
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | #!bin/python
from __future__ import division, nested_scopes
from optparse import OptionParser
import Tkinter as tk
import louie as dispatcher
from twisted.internet import reactor, tksupport, task
import run_local
from light9.dmxchanedit import Levelbox
from light9 import dmxclient, Patch, Submaster, showconfig, prof
from light9.uihelpers import toplevelat
from light9.rdfdb.syncedgraph import SyncedGraph
class Subcomposer(tk.Frame):
def __init__(self, master, graph):
tk.Frame.__init__(self, master, bg='black')
self.graph = graph
self.levelbox = Levelbox(self, graph)
self.levelbox.pack(side='top')
self.savebox = EntryCommand(self, cmd=self.savenewsub)
self.savebox.pack(side='top')
self.loadbox = EntryCommand(self, verb="Load", cmd=self.loadsub)
self.loadbox.pack(side='top')
def alltozero():
for lev in self.levelbox.levels:
lev.setlevel(0)
tk.Button(self, text="all to zero", command=alltozero).pack(side='top')
dispatcher.connect(self.sendupdate, "levelchanged")
def fill_both_boxes(self, subname):
for box in [self.savebox, self.loadbox]:
box.set(subname)
def save_levels(self, *args):
levelfile = file("subcomposer.savedlevels","w")
levelfile.write(" ".join(map(str, self.levels)))
def load_levels(self):
try:
levelfile = file("subcomposer.savedlevels","r")
levels = map(float, levelfile.read().split())
self.set_levels(levels)
except IOError:
pass
def savenewsub(self, subname):
leveldict={}
for i,lev in zip(range(len(self.levels)),self.levels):
if lev!=0:
leveldict[Patch.get_channel_name(i+1)]=lev
s=Submaster.Submaster(subname,leveldict=leveldict)
s.save()
def loadsub(self, subname):
"""puts a sub into the levels, replacing old level values"""
s=Submaster.Submasters(showconfig.getGraph()).get_sub_by_name(subname)
self.set_levels(s.get_dmx_list())
dispatcher.send("levelchanged")
def toDmxLevels(self):
# the dmx levels we edit and output, range is 0..1 (dmx chan 1 is
# the 0 element)
out = {}
for lev in self.levelbox.levels:
out[lev.channelnum] = lev.currentlevel
if not out:
return []
return [out.get(i, 0) for i in range(max(out.keys()) + 1)]
def sendupdate(self):
dmxclient.outputlevels(self.toDmxLevels(), twisted=True)
class EntryCommand(tk.Frame):
def __init__(self, master, verb="Save", cmd=None):
tk.Frame.__init__(self, master, bd=2, relief='raised')
tk.Label(self, text="Sub name:").pack(side='left')
self.cmd = cmd
self.entry = tk.Entry(self)
self.entry.pack(side='left', expand=True, fill='x')
self.entry.bind("<Return>", self.action)
tk.Button(self, text=verb, command=self.action).pack(side='left')
def action(self, *args):
subname = self.entry.get()
self.cmd(subname)
print "sub", self.cmd, subname
def set(self, text):
self.entry.delete(0, 'end')
self.entry.insert(0, text)
#############################
if __name__ == "__main__":
parser = OptionParser(usage="%prog [subname]")
parser.add_option('--no-geometry', action='store_true',
help="don't save/restore window geometry")
opts, args = parser.parse_args()
root=tk.Tk()
root.config(bg='black')
root.tk_setPalette("#004633")
if not opts.no_geometry:
toplevelat("subcomposer", root)
graph = SyncedGraph("subcomposer")
sc = Subcomposer(root, graph)
sc.pack()
tk.Label(root,text="Bindings: B1 adjust level; B2 set full; B3 instant bump",
font="Helvetica -12 italic",anchor='w').pack(side='top',fill='x')
if len(args) == 1:
root.config(bg='green') # trying to make these look distinctive
sc.loadsub(args[0])
sc.fill_both_boxes(args[0])
task.LoopingCall(sc.sendupdate).start(1)
tksupport.install(root,ms=10)
prof.run(reactor.run, profile=False)
|