diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -18,19 +18,18 @@ from twisted.internet import reactor 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 @@ class Main(object): 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 @@ class Main(object): 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 @@ class Main(object): 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 @@ class Main(object): 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 @@ class Main(object): 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 @@ class Main(object): 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"""