Files
@ bdfdfea84510
Branch filter:
Location: light9/bin/subcomposer
bdfdfea84510
8.9 KiB
text/plain
colored logs
Ignore-this: 74b7fb320ebca032b2976da3d00e05ca
Ignore-this: 74b7fb320ebca032b2976da3d00e05ca
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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | #!bin/python
from __future__ import division, nested_scopes
from optparse import OptionParser
import logging
import Tkinter as tk
import louie as dispatcher
from twisted.internet import reactor, tksupport, task
from rdflib import URIRef
from run_local import log
from light9.dmxchanedit import Levelbox
from light9 import dmxclient, Patch, Submaster, showconfig, prof
from light9.uihelpers import toplevelat
from light9.rdfdb.syncedgraph import SyncedGraph
from light9.rdfdb import clientsession
from light9.tkdnd import initTkdnd, dragSourceRegister, dropTargetRegister
log.setLevel(logging.DEBUG)
class _NoNewVal(object):
pass
class Observable(object):
"""
like knockout's observable. Hopefully this can be replaced by a
better python one
"""
def __init__(self, val):
self.val = val
self.subscribers = set()
def __call__(self, newVal=_NoNewVal):
if newVal is _NoNewVal:
return self.val
self.val = newVal
for s in self.subscribers:
s(newVal)
def subscribe(self, cb, callNow=True):
"""cb is called with new values, and also right now with the
current value unless you opt out"""
self.subscribers.add(cb)
if callNow:
cb(self.val)
class Local(object):
"""placeholder for the local uri that EditChoice does not
manage. Set resourceObservable to Local to indicate that you're
unlinked"""
class EditChoice(tk.Frame):
"""
Observable <-> linker UI
widget for tying some UI to a shared resource for editing, or
unlinking it (which means associating it with a local resource
that's not named or shared). This object does not own the choice
of resource; the caller does.
"""
def __init__(self, parent, graph, resourceObservable):
"""
getResource is called to get the URI of the currently
"""
self.frame = tk.Frame(parent, relief='raised',border=8)
self.frame.pack(side='top')
tk.Label(self.frame, text="Editing:").pack(side='left')
self.currentSubFrame = tk.Frame(self.frame)
self.currentSubFrame.pack(side='left')
self.subIcon = tk.Label(self.currentSubFrame, text="sub1",
borderwidth=2,
relief='raised', padx=10, pady=10)
self.subIcon.pack()
self.resourceObservable = resourceObservable
resourceObservable.subscribe(self.uriChanged)
dragSourceRegister(self.subIcon, 'copy', 'text/uri-list',
self.resourceObservable)
def onEv(ev):
self.resourceObservable(ev.data)
return "link"
self.onEv = onEv
# it would be nice if I didn't receive my own drags here
dropTargetRegister(self.subIcon, typeList=["*"], onDrop=onEv,
hoverStyle=dict(background="#555500", bd=3,
relief='groove'))
tk.Label(self.currentSubFrame, text="local data (drag sub here)").pack()
b=tk.Button(text="unlink", command=self.switchToLocalSub)
b.pack()
def uriChanged(self, newUri):
print "chg", newUri
# i guess i show the label and icon for this
if newUri is Local:
self.subIcon.config(text="(local)")
else:
self.subIcon.config(text=newUri)
def switchToLocalSub(self):
self.resourceObservable(Local)
class Subcomposer(tk.Frame):
"""
<session> l9:currentSub ?sub is the URI of the sub we're tied to for displaying and
editing. If we don't have a currentSub, then we're actually
editing a session-local sub called <session> l9:currentSub <sessionLocalSub>
Contains an EditChoice widget
UI actions:
- drag a sub uri on here to make it the one we're editing
- button to clear the currentSub (putting it back to
sessionLocalSub, and also resetting sessionLocalSub to be empty
again)
- drag the sub uri off of here to send it to another receiver, but
session local sub is not easily addressable elsewhere
- make a new sub: transfers the current data (from a shared sub or
from the local one) to the new sub. If you're on a local sub,
the new sub is named automatically, ideally something brief,
pretty distinct, readable, and based on the lights that are
on. If you're on a named sub, the new one starts with a
'namedsub 2' style name. The uri can also be with a '2' suffix,
although maybe that will be stupid. If you change the name
before anyone knows about this uri, we could update the current
sub's uri to a slug of the new label.
- rename this sub: not available if you're on a local sub. Sets
the label of a named sub. Might update the uri of the named sub
if it's new enough that no one else would have that uri. Not
sure where we measure that 'new enough' value. Maybe track if
the sub has 'never been dragged out of this subcomposer
session'? But subs will also show up in other viewers and
finders.
"""
def __init__(self, master, graph, session):
tk.Frame.__init__(self, master, bg='black')
self.graph = graph
self.session = session
self.currentSub = Submaster.PersistentSubmaster(graph, URIRef('http://hello'))
self.levelbox = Levelbox(self, graph)
self.levelbox.pack(side='top')
currentUri = Observable(Local)
def pc(val):
print "change viewed sub to", val
currentUri.subscribe(pc)
EditChoice(self, self.graph, currentUri).frame.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 switchToLocalSub(self, *args):
"""
stop editing a shared sub and go back to our local sub
"""
def fill_both_boxes(self, subname):
for box in [self.savebox, self.loadbox]:
box.set(subname)
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()
# this is going to be more like 'tie to sub' and 'untied'
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")
clientsession.add_option(parser)
opts, args = parser.parse_args()
root=tk.Tk()
root.config(bg='black')
root.tk_setPalette("#004633")
initTkdnd(root.tk, 'tkdnd/trunk/')
graph = SyncedGraph("subcomposer")
session = clientsession.getUri('subcomposer', opts)
if not opts.no_geometry:
toplevelat("subcomposer - %s" % opts.session, root, graph, session)
sc = Subcomposer(root, graph, session)
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)
root.protocol('WM_DELETE_WINDOW', reactor.stop)
tksupport.install(root,ms=10)
prof.run(reactor.run, profile=False)
|