Changeset - 3d1112a894df
[Not reviewed]
default
0 3 0
Drew Perttula - 13 years ago 2012-06-15 07:00:49
drewp@bigasterisk.com
drag subs from KC into CC to make a new subterm (if needed) and curve and some points that turn the sub on right now. some bugs about adding a subterm more than once
Ignore-this: 2c90a5d00c667ea38f23b0e6b36061dc
3 files changed with 50 insertions and 25 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -12,15 +12,14 @@ todo: curveview should preserve more obj
 
from __future__ import division
 

	
 
from twisted.internet import gtk2reactor
 
gtk2reactor.install()
 
from twisted.internet import reactor
 

	
 
import time, textwrap, os, optparse, urllib2, gtk, gobject, linecache, signal, traceback
 
import time, textwrap, os, optparse, gtk, linecache, signal, traceback
 
import louie as dispatcher 
 
from twisted.python.util import sibpath
 
from rdflib import URIRef, Graph, Literal, RDF, RDFS
 
import logging
 
log = logging.getLogger()
 

	
 
import run_local
 
from light9 import showconfig, prof
 
@@ -39,12 +38,15 @@ def makeGraph():
 
    graph = Graph() # a copy, since we're going to add subs into it
 
    for s in graphOrig:
 
        graph.add(s)
 
    read_all_subs(graph)
 
    return graph
 

	
 
class SubtermExists(ValueError):
 
    pass
 

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

	
 
        wtree = self.wtree = gtk.Builder()
 
@@ -70,12 +72,39 @@ class Main(object):
 
        wtree.get_object("subterms").connect("add", self.onSubtermChildAdded)
 
        self.add_subterms_for_song(song, curveset, subterms)
 
        self.refreshCurveView()       
 
        
 
        self.makeStatusLines(wtree.get_object("status"))
 

	
 
        def connect(w):
 
            w.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL,
 
                            targets=[('text/uri-list', 0, 0)],
 
                            actions=gtk.gdk.ACTION_COPY)
 
            w.connect("drag-data-received", self.onDataReceived)
 
        connect(mainwin)
 
        # that's not enough- deeper windows don't accept the
 
        # event. 
 
        mainwin.forall(connect) # not very effective
 
        connect(wtree.get_object("subterms")) # works for that area
 

	
 
    def onDataReceived(self, widget, context, x, y, selection,
 
                       targetType, time):
 
        uri = URIRef(selection.data.strip())
 
        subName = self.graph.label(uri)
 

	
 
        try:
 
            self.makeSubterm(subName, withCurve=True)
 
        except SubtermExists:
 
            pass
 
        curveView = self.curvesetView.row(subName).curveView
 
        t = curveView.current_time()
 
        print "time", t
 
        curveView.add_point((t - .5, 0))
 
        curveView.add_point((t, 1))
 
            
 

	
 
    def onNewCurve(self, *args):
 
        dialog = self.wtree.get_object("newCurve")
 
        entry = self.wtree.get_object("newCurveName")
 
        # if you don't have songx, that should be the suggested name
 
        entry.set_text("")
 
        if dialog.run() == 1:
 
@@ -88,24 +117,29 @@ class Main(object):
 
        # (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()
 
            uri = L9['sub/%s' % newname]
 
            self.graph.add((uri, RDF.type, L9.Subterm))
 
            self.graph.add((uri, RDFS.label, Literal(newname)))
 
            add_one_subterm(self.graph, uri,
 
                            self.curveset, self.subterms,
 
                            self.wtree.get_object("subterms"),
 
                            None, show=True)
 
            if self.wtree.get_object("newSubtermMakeCurve").get_active():
 
                self.curveset.new_curve(newname)
 
            
 
            wc = self.wtree.get_object("newSubtermMakeCurve").get_active()
 
            self.makeSubterm(newname, withCurve=wc)
 
        dialog.hide()
 

	
 
    def makeSubterm(self, newname, withCurve=False):
 
        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)))
 
        add_one_subterm(self.graph, uri,
 
                        self.curveset, self.subterms,
 
                        self.wtree.get_object("subterms"),
 
                        None, show=True)
 
        if withCurve:
 
            self.curveset.new_curve(newname)
 

	
 
    def refreshTheme(self):
 
        gtk.rc_reparse_all()
 
        reactor.callLater(1, self.refreshTheme)
 

	
 
    def onSubtermChildAdded(self, subtermsTable, *args):
 
        # this would probably work, but isn't getting called
 
@@ -216,13 +250,13 @@ class Main(object):
 

	
 
                # this is scheduled after some tk shuffling, to
 
                # try to minimize the number of times we redraw
 
                # the curve at startup. If tk is very slow, it's
 
                # ok. You'll just get some wasted redraws.
 
                self.curvesetView.goLive()
 
            except Exception, e:
 
            except Exception:
 
                print "reload failed:"
 
                traceback.print_exc()
 
        if self.opts.reload:
 
            reactor.callLater(1, self.refreshCurveView)
 

	
 
    def onReloadSubs(self, *args): # wants to be ctrl-r  too
light9/curvecalc/curve.py
Show inline comments
 
@@ -173,12 +173,14 @@ class Curveset(object):
 
        self.markers.save("%s.markers" % basename)
 

	
 
    def curveNamesInOrder(self):
 
        return sorted(self.curves.keys(), key=self.sorter)
 
            
 
    def add_curve(self,name,curve):
 
        if name in self.curves:
 
            raise ValueError("can't add a second curve named %r" % name)
 
        self.curves[name] = curve
 
        self.curveName[curve] = name
 

	
 
        if self.sliders and name not in ['smooth_music', 'music']:
 
            num = len(self.sliderCurve) + 1
 
            if num <= 8:
light9/curvecalc/curveview.py
Show inline comments
 
@@ -369,24 +369,13 @@ class Curveview(object):
 
        self.root.connect("button-press-event", self.onCanvasPress)
 

	
 
        self.widget.connect("key-press-event", self.onKeyPress)
 

	
 
        self.widget.connect("focus-in-event", self.onFocusIn)
 
        self.widget.connect("focus-out-event", self.onFocusOut)
 
        #self.widget.connect("event", self.onAny)
 

	
 
        # this is actually for subterms or mainwin, but i test here for reloads.
 
        self.widget.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL,
 
                                  targets=[('text/uri-list', 0, 0)],
 
                                  actions=gtk.gdk.ACTION_COPY)
 
        self.widget.connect("drag-data-received", self.onDataReceived)
 

	
 

	
 
    def onDataReceived(self, widget, context, x, y, selection, targetType, time):
 
        print "recv", repr(selection.data)
 
        
 
        #self.widget.connect("event", self.onAny)       
 

	
 
    def onAny(self, w, event):
 
        print "   %s on %s" % (event, w)
 
        
 
    def onFocusIn(self, *args):
 
        dispatcher.send("all curves lose selection", butNot=self)
0 comments (0 inline, 0 general)