Changeset - fc651955d6d9
[Not reviewed]
default
0 6 0
Drew Perttula - 12 years ago 2013-06-09 08:48:22
drewp@bigasterisk.com
curvecalc takes drops for new subterms and also to edit the sub of an existing one
Ignore-this: 448a61f7631d59bcd909869dc6300194
6 files changed with 67 insertions and 62 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -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,18 +179,24 @@ 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")
 
@@ -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"""
light9/curvecalc/curve.py
Show inline comments
 
@@ -151,6 +151,7 @@ class Curveset(object):
 

	
 
        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']:
light9/curvecalc/curvecalc.glade
Show inline comments
 
@@ -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>
light9/curvecalc/subterm.py
Show inline comments
 
@@ -133,28 +133,3 @@ class Subterm(object):
 

	
 
    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")
light9/curvecalc/subtermview.py
Show inline comments
 
import gtk, logging
 
from louie import dispatcher
 
from rdflib import Literal
 
from rdflib import Literal, URIRef
 
from light9.namespaces import L9
 
log = logging.getLogger()
 

	
 
@@ -59,9 +59,21 @@ class Subtermview(object):
 
        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'])
show/dance2013/demo.html
Show inline comments
 
@@ -3,3 +3,6 @@ some resources
 
<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>
0 comments (0 inline, 0 general)