Changeset - 3b1a435a29b8
[Not reviewed]
default
0 2 1
Drew Perttula - 12 years ago 2013-06-08 08:22:39
drewp@bigasterisk.com
start fixing curvecalc data model; not done yet
Ignore-this: 9960bef2556cd57da749e921bcf3248
3 files changed with 29 insertions and 6 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -26,24 +26,25 @@ import run_local
 
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.wavelength import wavelength
 
from light9.namespaces import L9
 
from light9.curvecalc.subterm import savekey, graphPathForSubterms
 
from light9.curvecalc.subtermview import add_one_subterm
 
from light9.curvecalc.output import Output
 
from light9.gtkpyconsole import togglePyConsole
 
from light9.rdfdb.syncedgraph import SyncedGraph
 
from light9.rdfdb.patch import Patch
 
from light9.editchoicegtk import EditChoice
 
from light9.observable import Observable
 

	
 
class SubtermExists(ValueError):
 
    pass
 

	
 
class Main(object):
 
    def __init__(self, graph, opts, session, curveset, subterms, music):
 
        self.graph, self.opts, self.session = graph, opts, session
 
        self.curveset, self.subterms, self.music = curveset, subterms, music
 
        self.lastSeenInputTime = 0
 

	
 
@@ -148,31 +149,44 @@ class Main(object):
 
        dialog = self.wtree.get_object("newSubterm")
 
        # the plan is to autocomplete this on existing subterm names
 
        # (but let you make one up, too)
 
        entry = self.wtree.get_object("newSubtermName").get_children()[0]
 
        entry.set_text("")
 
        entry.grab_focus()
 
        if dialog.run() == 1:
 
            newname = entry.get_text()
 
            wc = self.wtree.get_object("newSubtermMakeCurve").get_active()
 
            self.makeSubterm(newname, withCurve=wc)
 
        dialog.hide()
 

	
 
    def currentSong(self):
 
        with self.graph.currentState() as current:
 
            return current.value(self.session, L9['currentSong'])
 

	
 
    def songSubtermsContext(self):
 
        return self.currentSong()
 

	
 
    def makeSubterm(self, newname, withCurve=False, expr=None):
 
        uri = L9['sub/%s' % newname]
 
        if (uri, RDF.type, L9.Subterm) in self.graph:
 
            raise SubtermExists("already have a subterm named %r" % newname)
 
        self.graph.add((uri, RDF.type, L9.Subterm))
 
        self.graph.add((uri, RDFS.label, Literal(newname)))
 
        self.graph.add((self.song, L9['subterm'], uri))
 
        with self.graph.currentState() as current:
 
            if (uri, RDF.type, L9.Subterm) in current:
 
                raise SubtermExists("already have a subterm named %r" % newname)
 

	
 
        ctx = self.songSubtermsContext()
 
        self.graph.patch(Patch(addQuads=[
 
            (uri, RDF.type, L9.Subterm, ctx),
 
            (uri, RDFS.label, Literal(newname), ctx),
 
            (self.currentSong(), L9['subterm'], uri, ctx),
 
            ]))
 
            
 
        if withCurve:
 
            self.curveset.new_curve(newname)
 

	
 
    def add_subterms_for_song(self):
 
        master = self.wtree.get_object("subterms")
 
        [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']):
 
            log.info("song %s has subterm %s", song, st)
 
            add_one_subterm(self.graph,
doc/subterms
Show inline comments
 
new file 100644
 

	
 

	
 
song
 
  -- :subterm -->
 
    st
 
       -- rdfs:label --> "chase 1"
 
       -- :sub --> sub
 
       -- :expression --> "curve1(t)"
 
\ No newline at end of file
light9/curvecalc/subtermview.py
Show inline comments
 
import gtk, logging
 
from louie import dispatcher
 
from rdflib import RDF, RDFS, Literal
 
from rdflib import URIRef
 
from light9 import Submaster
 
from light9.namespaces import L9
 
from light9.curvecalc.subterm import Subterm, Subexpr
 
log = logging.getLogger()
 

	
 
# inspired by http://www.daa.com.au/pipermail/pygtk/2008-August/015772.html
 
# keeping a ref to the __dict__ of the object stops it from getting zeroed
 
keep = []
 

	
 
class Subexprview(object):
 
    def __init__(self, se):
 
        self.subexpr = se
 
@@ -49,24 +49,25 @@ class Subtermview(object):
 
    """
 
    has .label and .exprView widgets for you to put in a table
 
    """
 
    def __init__(self, graph, st):
 
        self.subterm = st
 

	
 
        self.label = gtk.Label("sub %s" % self.subterm.submaster.name)
 

	
 
        sev = Subexprview(self.subterm.subexpr)
 
        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
 

	
 
    # this is what I'd like to have, but the name replacement above is
 
    # too unclear for me to make the change now
0 comments (0 inline, 0 general)