Mercurial > code > home > repos > light9
changeset 897:fc651955d6d9
curvecalc takes drops for new subterms and also to edit the sub of an existing one
Ignore-this: 448a61f7631d59bcd909869dc6300194
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sun, 09 Jun 2013 08:48:22 +0000 |
parents | d5fd119a9acf |
children | db265102f7b5 |
files | bin/curvecalc light9/curvecalc/curve.py light9/curvecalc/curvecalc.glade light9/curvecalc/subterm.py light9/curvecalc/subtermview.py show/dance2013/demo.html |
diffstat | 6 files changed, 68 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/curvecalc Sun Jun 09 01:13:34 2013 +0000 +++ b/bin/curvecalc Sun Jun 09 08:48:22 2013 +0000 @@ -18,19 +18,18 @@ import time, textwrap, os, optparse, gtk, linecache, signal, traceback, json from urlparse import parse_qsl import louie as dispatcher -from rdflib import URIRef, Graph, Literal, RDF, RDFS +from rdflib import URIRef, Literal, RDF, RDFS import logging -log = logging.getLogger() -import run_local +from run_local import log from light9 import showconfig, prof, networking from light9.rdfdb import clientsession from light9.curvecalc.curve import Curveset from light9.curvecalc import curveview -from light9.curvecalc.musicaccess import Music, currentlyPlayingSong +from light9.curvecalc.musicaccess import Music from light9.wavelength import wavelength from light9.namespaces import L9 -from light9.curvecalc.subterm import savekey, graphPathForSubterms, Subterm +from light9.curvecalc.subterm import Subterm from light9.curvecalc.subtermview import add_one_subterm from light9.curvecalc.output import Output from light9.gtkpyconsole import togglePyConsole @@ -77,6 +76,7 @@ def setSong(): songChoice(graph.value(session, L9['currentSong'])) graph.addHandler(setSong) + # next here, watch songChoice and patch the graph ec = EditChoice(graph, songChoice, label="Editing song:") wtree.get_object("currentSongEditChoice").add(ec) @@ -94,13 +94,17 @@ targets=[('text/uri-list', 0, 0)], actions=gtk.gdk.ACTION_COPY) w.connect("drag-data-received", self.onDataReceived) - connect(mainwin) + #connect(mainwin) # that's not enough- deeper windows don't accept the # event. - mainwin.forall(connect) # not very effective + #mainwin.forall(connect) # not very effective + wtree.get_object("newSubZone").drag_dest_set(flags=gtk.DEST_DEFAULT_ALL, + targets=[('text/uri-list', 0, 0)], + actions=gtk.gdk.ACTION_COPY) + # this probably isn't rerunning often enough to catch new data - connect(wtree.get_object("subterms")) # works for that area + #connect(wtree.get_object("subterms")) # works for that area # may not work wtree.get_object("paned1").set_position(600) @@ -114,11 +118,6 @@ uri = URIRef(data) subName = self.graph.label(uri) - if not list(self.graph.subjects(L9['sub'], uri)): - # might be a new one just created in KC - print "didn't find %r, reloading subs" % uri - self.onReloadSubs() - try: self.makeSubterm(subName, withCurve=True) except SubtermExists: @@ -129,6 +128,11 @@ curveView.add_points([(t - .5, 0), (t, 1)]) + def onDragDataInNewSubZone(self, widget, context, x, y, selection, + targetType, time): + self.makeSubterm(newname="cx", withCurve=True, + sub=URIRef(selection.data.strip())) + def handleSubtermDrop(self, data): params = parse_qsl(data.split('?')[1]) flattened = dict(params) @@ -175,19 +179,25 @@ def songSubtermsContext(self): return self.currentSong() - def makeSubterm(self, newname, withCurve=False, expr=None): + def makeSubterm(self, newname, withCurve=False, expr=None, sub=None): uri = self.currentSong() + "/sub/%f" % time.time() ctx = self.songSubtermsContext() - self.graph.patch(Patch(addQuads=[ + quads = [ (uri, RDF.type, L9.Subterm, ctx), (uri, RDFS.label, Literal(newname), ctx), (self.currentSong(), L9['subterm'], uri, ctx), - ])) + ] + if sub is not None: + quads.append((uri, L9['sub'], sub, ctx)) + if expr is not None: + quads.append((uri, L9['expression'], Literal(expr), ctx)) + self.graph.patch(Patch(addQuads=quads)) if withCurve: self.curveset.new_curve(newname) - + return uri + def set_subterms_from_graph(self): master = self.wtree.get_object("subterms") log.info("removing subterm widgets") @@ -252,8 +262,13 @@ def onSave(self, *args): with self.graph.currentState() as g: - savekey(g.value(self.session, L9['currentSong']), - self.curveset) + song = g.value(self.session, L9['currentSong']) + + log.info("saving curves for %r", song) + self.curveset.save(basename=os.path.join( + showconfig.curvesDir(), + showconfig.songFilenameFromURI(song))) + log.info("saved") def makeStatusLines(self, master): """various labels that listen for dispatcher signals"""
--- a/light9/curvecalc/curve.py Sun Jun 09 01:13:34 2013 +0000 +++ b/light9/curvecalc/curve.py Sun Jun 09 08:48:22 2013 +0000 @@ -151,6 +151,7 @@ This fires 'add_curve' dispatcher events to announce the new curves. """ + log.info("Curveset.load %s", basename) for filename in sorted(glob.glob("%s-*"%basename), key=self.sorter): curvename = filename[filename.rfind('-')+1:] if skipMusic and curvename in ['music', 'smooth_music']:
--- a/light9/curvecalc/curvecalc.glade Sun Jun 09 01:13:34 2013 +0000 +++ b/light9/curvecalc/curvecalc.glade Sun Jun 09 08:48:22 2013 +0000 @@ -511,9 +511,9 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="n_columns">2</property> + <signal name="add" handler="onSubtermChildAdded" swapped="no"/> <signal name="child-added" handler="onSubtermChildAdded" swapped="no"/> <signal name="map" handler="onSubtermsMap" swapped="no"/> - <signal name="add" handler="onSubtermChildAdded" swapped="no"/> <child> <placeholder/> </child> @@ -526,9 +526,22 @@ </child> </object> <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="newSubZone"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Drop new sub here</property> + <signal name="drag-data-received" handler="onDragDataInNewSubZone" swapped="no"/> + </object> + <packing> <property name="expand">True</property> <property name="fill">True</property> - <property name="position">0</property> + <property name="position">1</property> </packing> </child> <child> @@ -536,21 +549,7 @@ <property name="visible">True</property> <property name="can_focus">False</property> <child> - <object class="GtkButton" id="button1"> - <property name="label" translatable="yes">Reload subs (C-r)</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_action_appearance">False</property> - <property name="image">image2</property> - <accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK"/> - <signal name="clicked" handler="onReloadSubs" swapped="no"/> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> + <placeholder/> </child> <child> <object class="GtkButton" id="button2"> @@ -575,7 +574,7 @@ <packing> <property name="expand">False</property> <property name="fill">False</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> </object>
--- a/light9/curvecalc/subterm.py Sun Jun 09 01:13:34 2013 +0000 +++ b/light9/curvecalc/subterm.py Sun Jun 09 08:48:22 2013 +0000 @@ -133,28 +133,3 @@ def __repr__(self): return "<Subterm %s>" % self.uri - -def graphPathForSubterms(song): - return showconfig.subtermsForSong(showconfig.songFilenameFromURI(song)) + ".n3" - -def createSubtermGraph(song, subterms): - """rdf graph describing the subterms, readable by add_subterms_for_song""" - graph = Graph() - for subterm in subterms: - assert subterm.submaster.name, "submaster %r has no name" % subterm.submaster - uri = URIRef(song + "/subterm/" + subterm.submaster.name) - graph.add((song, L9['subterm'], uri)) - graph.add((uri, RDF.type, L9['Subterm'])) - graph.add((uri, RDFS.label, Literal(subterm.submaster.name))) - graph.add((uri, L9['sub'], L9['sub/%s' % subterm.submaster.name])) - graph.add((uri, L9['expression'], Literal(subterm.subexpr.expr))) - return graph - -def savekey(song, curveset): - log.info("saving %r", song) - g = createSubtermGraph(song, subterms) - g.serialize(graphPathForSubterms(song), format="nt") - - curveset.save(basename=os.path.join(showconfig.curvesDir(), - showconfig.songFilenameFromURI(song))) - log.info("saved")
--- a/light9/curvecalc/subtermview.py Sun Jun 09 01:13:34 2013 +0000 +++ b/light9/curvecalc/subtermview.py Sun Jun 09 08:48:22 2013 +0000 @@ -1,6 +1,6 @@ import gtk, logging from louie import dispatcher -from rdflib import Literal +from rdflib import Literal, URIRef from light9.namespaces import L9 log = logging.getLogger() @@ -58,10 +58,22 @@ self.label = gtk.Label("sub") self.graph.addHandler(self.setName) + + self.label.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL, + targets=[('text/uri-list', 0, 0)], + actions=gtk.gdk.ACTION_COPY) + self.label.connect("drag-data-received", self.onDataReceivedOnLabel) sev = Subexprview(self.graph, self.subterm.uri, self.subterm.saveContext) self.exprView = sev.box + def onDataReceivedOnLabel(self, widget, context, x, y, selection, + targetType, time): + self.graph.patchObject(self.subterm.saveContext, + self.subterm.uri, + L9['sub'], + URIRef(selection.data.strip())) + def setName(self): # some of this could be pushed into Submaster sub = self.graph.value(self.subterm.uri, L9['sub'])
--- a/show/dance2013/demo.html Sun Jun 09 01:13:34 2013 +0000 +++ b/show/dance2013/demo.html Sun Jun 09 08:48:22 2013 +0000 @@ -3,3 +3,6 @@ <p><a href="http://light9.bigasterisk.com/show/dance2013/sub/demo1">demo1 sub</a></p> <p><a href="http://light9.bigasterisk.com/show/dance2013/sub/demo2">demo2 sub</a></p> <p><a href="http://light9.bigasterisk.com/show/dance2013/sub/demo3">demo3 sub</a></p> + +<p><a href="http://light9.bigasterisk.com/show/dance2013/song1">song1</a></p> +<p><a href="http://light9.bigasterisk.com/show/dance2013/song2">song2</a></p>