diff bin/curvecalc @ 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 836ea837cae9
children db265102f7b5
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"""