Changeset - 929ccd4ec800
[Not reviewed]
default
0 2 0
Drew Perttula - 13 years ago 2012-06-09 10:03:36
drewp@bigasterisk.com
live reloading of curveview.py, very nice
Ignore-this: f7362d3c4f5215c1fe060fe8f06ebfe5
2 files changed with 49 insertions and 26 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -19,25 +19,25 @@ import time, textwrap, os, optparse, url
 
import louie as dispatcher 
 
from twisted.python.util import sibpath
 
from rdflib import URIRef
 
from rdflib import Graph
 
import rdflib
 
import logging
 
log = logging.getLogger()
 

	
 
import run_local
 
from light9 import showconfig, prof
 
from light9.curvecalc.zoomcontrol import Zoomcontrol
 
from light9.curvecalc.curve import Curveset
 
from light9.curvecalc.curveview import Curvesetview
 
from light9.curvecalc import curveview 
 
from light9.curvecalc.musicaccess import Music, currentlyPlayingSong
 
from light9.wavelength import wavelength
 
from light9.uihelpers import toplevelat
 
from light9.namespaces import L9
 
from light9.curvecalc.subterm import read_all_subs, savekey, graphPathForSubterms
 
from light9.curvecalc.subtermview import add_one_subterm
 
from light9.curvecalc.output import Output
 

	
 
def makeGraph():
 
    graphOrig = showconfig.getGraph()
 
    graph = Graph() # a copy, since we're going to add subs into it
 
    for s in graphOrig:
 
@@ -53,38 +53,50 @@ class Main(object):
 
        mainwin = wtree.get_object("MainWindow")
 
        mainwin.connect("destroy", gtk.main_quit)
 
        wtree.connect_signals(self)
 
        mainwin.show_all()
 

	
 
        mainwin.connect("delete-event", lambda *args: reactor.crash())
 
        mainwin.set_title("curvecalc - %s" % graph.label(song))
 
        
 
        self.add_subterms_for_song(song, curveset, subterms,
 
                                   wtree.get_object("subterms")
 
                                   )
 

	
 
        def refreshCurveView():
 
            m = os.path.getmtime(curveview.__file__.replace('.pyc', '.py'))
 

	
 
        curvesetView = Curvesetview(wtree.get_object("curves"), curveset)
 
        self.curvesetView = curvesetView # mem problem; don't let this get lost
 
        
 
        # curvesetview must already exist, since this makes 'add_curve'
 
        # signals for all the initial curves
 
        curveset.load(basename=os.path.join(
 
            showconfig.curvesDir(),
 
            showconfig.songFilenameFromURI(song)),
 
                      skipMusic=opts.skip_music)
 
        # 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.
 
        curvesetView.goLive()
 
            if not hasattr(self, 'curvesetView') or self.curvesetView._mtime != m:
 
                print "reload curveview.py"
 
                curvesVBox = wtree.get_object("curves")
 
                [curvesVBox.remove(c) for c in curvesVBox.get_children()]
 
                reload(curveview)
 
                # mem problem somewhere; need to hold a ref to this
 
                self.curvesetView = curveview.Curvesetview(
 
                    curvesVBox, curveset)
 
                self.curvesetView._mtime = m
 

	
 
                # curvesetview must already exist, since this makes 'add_curve'
 
                # signals for all the initial curves
 
                curveset.load(basename=os.path.join(
 
                    showconfig.curvesDir(),
 
                    showconfig.songFilenameFromURI(song)),
 
                              skipMusic=opts.skip_music)
 
                # 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()
 
                
 
            reactor.callLater(1, refreshCurveView)
 
        refreshCurveView()       
 
        
 
        self.makeStatusLines(wtree.get_object("status"))
 

	
 
        #zc = Zoomcontrol(root)
 

	
 
    def onSave(self, *args):
 
        savekey(song, subterms, curveset)
 

	
 
    def add_subterms_for_song(self, song, curveset, subterms, master):
 
        for st in self.graph.objects(song, L9['subterm']):
 
            log.info("song %s has subterm %s", song, st)
 
            add_one_subterm(self.graph,
light9/curvecalc/curveview.py
Show inline comments
 
@@ -66,25 +66,25 @@ class Sketch:
 
                self.curveview.add_point(p)
 
            
 
        self.curveview.update_curve()
 

	
 
class Curveview(object):
 
    """
 
    graphical curve widget only. Please pack .widget
 
    """
 
    def __init__(self, curve, knobEnabled=False, isMusic=False, **kw):
 
        """knobEnabled=True highlights the previous key and ties it to a
 
        hardware knob"""
 
        self.widget = goocanvas.Canvas()
 
        self.widget.set_property("background-color", "black")
 
        self.widget.set_property("background-color", "gray20")
 
        self.widget.set_size_request(-1, 130)
 
        self.root = self.widget.get_root_item()
 

	
 
        self.redrawsEnabled = False
 
        self.curve = curve
 
        self.knobEnabled = knobEnabled
 
        self._isMusic = isMusic
 
        self._time = 0
 
        self.last_mouse_world = None
 
        self.selected_points=[] # idx of points being dragged
 
        # self.bind("<Enter>",self.focus)
 
        dispatcher.connect(self.input_time, "input time")
 
@@ -414,52 +414,61 @@ class Curveview(object):
 
            
 
        # canvas doesnt have keyboard focus, so i can't easily change the
 
        # cursor when ctrl is pressed
 
        #        def curs(ev):
 
        #            print ev.state
 
        #        self.bind("<KeyPress>",curs)
 
        #        self.bind("<KeyRelease-Control_L>",lambda ev: curs(0))
 
        if 0:
 
            self.tag_bind(line,"<Control-ButtonPress-1>",self.new_point_at_mouse)
 

	
 

	
 
    def _draw_handle_points(self,visible_idxs,visible_points):
 
        return
 
        for i,p in zip(visible_idxs,visible_points):
 
            rad=3
 
            worldp = p
 
            p = self.screen_from_world(p)
 
            dot = self.create_rectangle(p[0]-rad,p[1]-rad,p[0]+rad,p[1]+rad,
 
                                        outline='black',fill='blue',
 
                                        tags=('curve','point', 'handle%d' % i))
 
            dot = goocanvas.Rect(parent=self.curveGroup,
 
                                 x=p[0] - rad, y=p[1] - rad,
 
                                 width=rad * 2, height=rad * 2,
 
                                 stroke_color='gray20',
 
                                 fill_color='blue',
 
                                 line_width=1,
 
                                 #tags=('curve','point', 'handle%d' % i)
 
                                 )
 
            if worldp[1] == 0:
 
                rad += 3
 
                dot2 = self.create_oval(p[0]-rad,p[1]-rad,
 
                                             p[0]+rad,p[1]+rad,
 
                                             outline='darkgreen',
 
                                       tags=('curve','point', 'handle%d' % i))
 
            self.tag_bind('handle%d' % i,"<ButtonPress-1>",
 
                          lambda ev,i=i: self.dotpress(ev,i))
 
                dot2 = goocanvas.Ellipse(parent=self.curveGroup,
 
                                         center_x=p[0],
 
                                         center_y=p[1],
 
                                         radius_x=rad,
 
                                         radius_y=rad,
 
                                         line_width=.8,
 
                                         stroke_color='darkgreen',
 
                                         #tags=('curve','point', 'handle%d' % i)
 
                                         )
 
            #self.tag_bind('handle%d' % i,"<ButtonPress-1>",
 
            #              lambda ev,i=i: self.dotpress(ev,i))
 
            #self.tag_bind('handle%d' % i, "<Key-d>",
 
            #              lambda ev, i=i: self.remove_point_idx(i))
 
                      
 
            self.dots[i]=dot
 

	
 
        def delpoint(ev):
 
            # had a hard time tag_binding to the points, so i trap at
 
            # the widget level (which might be nice anyway when there
 
            # are multiple pts selected)
 
            if self.selected_points:
 
                self.remove_point_idx(*self.selected_points)
 
        self.bind("<Key-Delete>", delpoint)
 
        #self.bind("<Key-Delete>", delpoint)
 

	
 
        self.highlight_selected_dots()
 

	
 
    def find_index_near(self,x,y):
 
        tags = self.gettags(self.find_closest(x, y))
 
        try:
 
            handletags = [t for t in tags if t.startswith('handle')]
 
            return int(handletags[0][6:])
 
        except IndexError:
 
            raise ValueError("no point found")
 
        
 
    def new_point_at_mouse(self, ev):
 
@@ -492,24 +501,25 @@ class Curveview(object):
 
                newsel.append(sp)
 
            for ii in range(len(idxs)):
 
                if ii > i:
 
                    ii -= 1
 
                newidxs.append(idxs[ii])
 

	
 
            self.selected_points[:] = newsel
 
            idxs[:] = newidxs
 
            
 
        self.update_curve()
 

	
 
    def highlight_selected_dots(self):
 
        return
 
        for i,d in self.dots.items():
 
            if i in self.selected_points:
 
                self.itemconfigure(d,fill='red')
 
            else:
 
                self.itemconfigure(d,fill='blue')
 
        
 
    def dotpress(self,ev,dotidx):
 
        self.print_state("dotpress")
 
        if dotidx not in self.selected_points:
 
            self.selected_points=[dotidx]
 
        self.highlight_selected_dots()
 
        self.last_mouse_world = self.world_from_screen(ev.x, ev.y)
 
@@ -563,24 +573,25 @@ class Curveview(object):
 
        self.last_mouse_world = None
 
        self.dragging_dots = False
 

	
 
class CurveRow(object):
 
    """
 
    one of the repeating curve rows (including widgets on the left)
 

	
 
    please pack self.box
 
    """
 
    def __init__(self, name, curve, slider, knobEnabled):
 

	
 
        self.box = gtk.HandleBox()
 
        self.box.set_border_width(1)
 

	
 
        cols = gtk.HBox()
 
        self.box.add(cols)
 
        
 
        controls = gtk.Frame()
 
        controls.set_size_request(115, -1)
 
        controls.set_shadow_type(gtk.SHADOW_OUT)
 
        cols.pack_start(controls, expand=False)
 
        self.setupControls(controls, name, curve, slider)
 

	
 
        self.curveView = Curveview(curve, knobEnabled=knobEnabled,
 
                                   isMusic=name in ['music', 'smooth_music'])
0 comments (0 inline, 0 general)