Mercurial > code > home > repos > light9
changeset 892:95e311bffbd9
working on curvecalc graph sync
Ignore-this: 25bd530ef945e05004a45f381983db93
author | drewp@bigasterisk.com |
---|---|
date | Sat, 08 Jun 2013 22:55:03 +0000 |
parents | 27d2f148b630 |
children | 1b19038f42e2 |
files | bin/curvecalc light9/curvecalc/output.py light9/curvecalc/subterm.py light9/curvecalc/subtermview.py |
diffstat | 4 files changed, 75 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/curvecalc Sat Jun 08 21:22:24 2013 +0000 +++ b/bin/curvecalc Sat Jun 08 22:55:03 2013 +0000 @@ -30,7 +30,7 @@ from light9.curvecalc.musicaccess import Music, currentlyPlayingSong from light9.wavelength import wavelength from light9.namespaces import L9 -from light9.curvecalc.subterm import savekey, graphPathForSubterms +from light9.curvecalc.subterm import savekey, graphPathForSubterms, Subterm from light9.curvecalc.subtermview import add_one_subterm from light9.curvecalc.output import Output from light9.gtkpyconsole import togglePyConsole @@ -43,9 +43,9 @@ pass class Main(object): - def __init__(self, graph, opts, session, curveset, subterms, music): + def __init__(self, graph, opts, session, curveset, music): self.graph, self.opts, self.session = graph, opts, session - self.curveset, self.subterms, self.music = curveset, subterms, music + self.curveset, self.music = curveset, music self.lastSeenInputTime = 0 wtree = self.wtree = gtk.Builder() @@ -83,7 +83,7 @@ ec.show() wtree.get_object("subterms").connect("add", self.onSubtermChildAdded) - graph.addHandler(self.add_subterms_for_song) + graph.addHandler(self.set_subterms_from_graph) self.refreshCurveView() self.makeStatusLines(wtree.get_object("status")) @@ -97,6 +97,8 @@ # that's not enough- deeper windows don't accept the # event. mainwin.forall(connect) # not very effective + + # this probably isn't rerunning often enough to catch new data connect(wtree.get_object("subterms")) # works for that area # may not work @@ -166,10 +168,7 @@ return self.currentSong() def makeSubterm(self, newname, withCurve=False, expr=None): - uri = L9['sub/%s' % newname] - with self.graph.currentState() as current: - if (uri, RDF.type, L9.Subterm) in current: - raise SubtermExists("already have a subterm named %r" % newname) + uri = self.currentSong() + "/sub/%f" % time.time() ctx = self.songSubtermsContext() self.graph.patch(Patch(addQuads=[ @@ -181,20 +180,18 @@ if withCurve: self.curveset.new_curve(newname) - def add_subterms_for_song(self): + def set_subterms_from_graph(self): master = self.wtree.get_object("subterms") + log.info("removing subterm widgets") [master.remove(c) for c in master.get_children()] song = self.graph.value(self.session, L9['currentSong']) - for st in self.graph.objects(song, L9['subterm']): + for st in set(self.graph.objects(song, L9['subterm'])): log.info("song %s has subterm %s", song, st) - add_one_subterm(self.graph, - self.graph.value(st, L9['sub']), - self.curveset, - self.subterms, - master, - self.graph.value(st, L9['expression'])) + #term = Subterm(self.graph, st, self.songSubtermsContext()) + #add_one_subterm(term, self.curveset, master) + master.show_all() def refreshTheme(self): @@ -246,7 +243,7 @@ def onSave(self, *args): with self.graph.currentState() as g: savekey(g.value(self.session, L9['currentSong']), - self.subterms, self.curveset) + self.curveset) def makeStatusLines(self, master): """various labels that listen for dispatcher signals""" @@ -348,7 +345,6 @@ pass curveset = Curveset(sliders=opts.sliders) - subterms = [] def curvesetReload(): # not sure if this clears right or not yet @@ -362,12 +358,12 @@ graph.addHandler(curvesetReload) log.debug("startup: output %s", time.time() - startTime) - out = Output(subterms, music) + out = Output(music) mt = MaxTime(graph, session) dispatcher.connect(lambda: mt.get(), "get max time", weak=False) - start = Main(graph, opts, session, curveset, subterms, music) + start = Main(graph, opts, session, curveset, music) dispatcher.send("show all") @@ -410,7 +406,6 @@ clientsession.add_option(parser) opts, args = parser.parse_args() - logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s") log.setLevel(logging.DEBUG if opts.debug else logging.INFO) log.debug("startup: music %s", time.time() - startTime)
--- a/light9/curvecalc/output.py Sat Jun 08 21:22:24 2013 +0000 +++ b/light9/curvecalc/output.py Sat Jun 08 22:55:03 2013 +0000 @@ -1,13 +1,16 @@ -import time +import time, logging from twisted.internet import reactor from light9 import Submaster, dmxclient from louie import dispatcher +log = logging.getLogger("output") + +firstWarn = False class Output: lastsendtime=0 lastsendlevs=None - def __init__(self, subterms, music): - self.subterms, self.music = subterms, music + def __init__(self, music): + self.music = music self.recent_t=[] self.later = None @@ -44,8 +47,14 @@ self.send_dmx(t) def send_dmx(self,t): + global firstWarn + if not firstWarn: + log.warn("skipping Output.send_dmx") + firstWarn = True + return dispatcher.send("curves to sliders", t=t) scaledsubs=[] + # this needs to use graph instead for st in self.subterms: scl = st.scaled(t) scaledsubs.append(scl)
--- a/light9/curvecalc/subterm.py Sat Jun 08 21:22:24 2013 +0000 +++ b/light9/curvecalc/subterm.py Sat Jun 08 22:55:03 2013 +0000 @@ -2,7 +2,9 @@ from rdflib import Graph, URIRef, RDF, RDFS, Literal from louie import dispatcher import light9.Effects -from light9 import Submaster, showconfig, Patch, prof +from light9 import Submaster, showconfig, prof +from light9.Patch import get_dmx_channel +from light9.rdfdb.patch import Patch from light9.namespaces import L9 log = logging.getLogger() @@ -41,7 +43,7 @@ def chan(name): return Submaster.Submaster( name=name, - levels={Patch.get_dmx_channel(name) : 1.0}) + levels={get_dmx_channel(name) : 1.0}) glo['chan'] = chan def smooth_random(speed=1): @@ -107,12 +109,22 @@ return locals() expr = property(**expr()) -class Subterm: +class Subterm(object): """one Submaster and its Subexpr""" - def __init__(self, submaster, subexpr): - self.submaster, self.subexpr = submaster, subexpr - + def __init__(self, graph, subterm, saveCtx): + self.graph, self.uri = graph, subterm + self.ensureExpression(saveCtx) + + def ensureExpression(self, saveCtx): + with self.graph.currentState() as current: + if current.value(self.uri, L9['expression']) is None: + self.graph.patch(Patch(addQuads=[ + (self.uri, L9['expression'], Literal("..."), saveCtx), + ])) + def scaled(self, t): + log.warn("skipping Subterm.scaled") + return 0 subexpr_eval = self.subexpr.eval(t) # we prevent any exceptions from escaping, since they cause us to # stop sending levels @@ -129,8 +141,7 @@ return Submaster.Submaster(name='Error: %s' % str(e), levels={}) def __repr__(self): - return "<Subterm %s %s>" % (self.submaster, self.subexpr) - + return "<Subterm %s>" % self.uri def graphPathForSubterms(song): return showconfig.subtermsForSong(showconfig.songFilenameFromURI(song)) + ".n3" @@ -148,7 +159,7 @@ graph.add((uri, L9['expression'], Literal(subterm.subexpr.expr))) return graph -def savekey(song, subterms, curveset): +def savekey(song, curveset): log.info("saving %r", song) g = createSubtermGraph(song, subterms) g.serialize(graphPathForSubterms(song), format="nt")
--- a/light9/curvecalc/subtermview.py Sat Jun 08 21:22:24 2013 +0000 +++ b/light9/curvecalc/subtermview.py Sat Jun 08 22:55:03 2013 +0000 @@ -11,8 +11,8 @@ keep = [] class Subexprview(object): - def __init__(self, se): - self.subexpr = se + def __init__(self, graph, ownerSubterm): + self.graph, self.ownerSubterm = graph, ownerSubterm self.box = gtk.HBox() @@ -28,65 +28,61 @@ self.entryBuffer.connect("deleted-text", self.entry_changed) self.entryBuffer.connect("inserted-text", self.entry_changed) dispatcher.connect(self.expr_changed, "expr_changed", - sender=self.subexpr) + sender=self.ownerSubterm) - dispatcher.connect(self.exprError, "expr_error", sender=self.subexpr) - log.info("made %r %r" % (id(self), self.__dict__)) + dispatcher.connect(self.exprError, "expr_error", sender=self.ownerSubterm) keep.append(self.__dict__) def exprError(self, exc): self.error.set_text(str(exc)) def expr_changed(self): + log.warn("skip expr_changed") + return e = str(self.subexpr.expr) if e != self.entryBuffer.get_text(): self.entryBuffer.set_text(e, len(e)) def entry_changed(self, *args): + log.warn("skip entry_changed") + return self.subexpr.expr = self.entryBuffer.get_text() class Subtermview(object): """ has .label and .exprView widgets for you to put in a table """ - def __init__(self, graph, st): + def __init__(self, st): self.subterm = st + self.graph = st.graph - self.label = gtk.Label("sub %s" % self.subterm.submaster.name) - - sev = Subexprview(self.subterm.subexpr) + self.label = gtk.Label("sub") + self.graph.addHandler(self.setName) + + sev = Subexprview(self.graph, self.subterm.uri) self.exprView = sev.box -def add_one_subterm(graph, subUri, curveset, subterms, master, expr=None, show=False): - assert isinstance(subUri, URIRef), subUri - subname = graph.label(subUri) - log.info("%s's label is %s" % (subUri, subname)) - if not subname: # fake sub, like for a chase - st = graph.subjects(L9['sub'], subUri).next() - subname = graph.label(st) - log.info("using parent subterm's name instead. parent %r, name %r" % (st, subname)) - assert subname, "%s has no name" % subUri - if expr is None: - expr = '%s(t)' % subname + def setName(self): + # some of this could be pushed into Submaster + sub = self.graph.value(self.subterm.uri, L9['sub']) + if sub is None: + self.label.set_text("no sub (%s)" % self.subterm.uri) + return + label = self.graph.label(sub) + if label is None: + self.label.set_text("sub %s has no label" % sub) + return + self.label.set_text(label) - # this is what I'd like to have, but the name replacement above is - # too unclear for me to make the change now - #get_global_submasters(graph).get_sub_by_name( +def add_one_subterm(subterm, curveset, master, show=False): + stv = Subtermview(subterm) - # graph.add([(subUri, RDFS.label, Literal(subname))]) # didntknow context yet - sub = Submaster.PersistentSubmaster(graph, subUri) - term = Subterm(sub, Subexpr(curveset, expr, graph)) - subterms.append(term) - - stv = Subtermview(graph, term) y = master.get_property('n-rows') master.attach(stv.label, 0, 1, y, y + 1, xoptions=0, yoptions=0) master.attach(stv.exprView, 1, 2, y, y + 1, yoptions=0) scrollToRowUponAdd(stv.label) if show: master.show_all() - return term - def scrollToRowUponAdd(widgetInRow): """when this table widget is ready, scroll the table so we can see it"""