Changeset - 0fb89da08e66
[Not reviewed]
default
0 3 0
Drew Perttula - 11 years ago 2014-06-02 06:04:54
drewp@bigasterisk.com
CC display optimizations. show pre/post curve in area mode. stable curve order
Ignore-this: 43ae4dfcb85afb993b8c6ec5d1810580
3 files changed with 91 insertions and 11 deletions:
0 comments (0 inline, 0 general)
light9/curvecalc/curve.py
Show inline comments
 
@@ -103,12 +103,13 @@ class Curve(object):
 
    def live_input_point(self, new_pt):
 
        x, y = new_pt
 
        exist = self.points_between(x, x + .01)
 
        for pt in exist:
 
            self.remove_point(pt)
 
        self.insert_pt(new_pt)
 
        dispatcher.send("points changed", sender=self)
 
        # now simplify to the left
 
        
 
    def set_points(self, updates):
 
        for i, pt in updates:
 
            self.points[i] = pt
 
            
 
@@ -272,13 +273,13 @@ class Curveset(object):
 
        self.markers.save("%s.markers" % basename)
 
        # this will cause reloads that will clear our curve list
 
        for p in patches:
 
            self.graph.patch(p)
 

	
 
    def sorter(self, name):
 
        return (not name in ['music', 'smooth_music'], name)
 
        return self.curves[name].uri
 
        
 
    def curveNamesInOrder(self):
 
        return sorted(self.curves.keys(), key=self.sorter)
 
            
 
    def add_curve(self, name, curve):
 
        # should be indexing by uri
light9/curvecalc/curveedit.py
Show inline comments
 
"""
 
this may be split out from curvecalc someday, since it doesn't
 
need to be tied to a gui """
 
import cgi
 
import cgi, time
 
from twisted.internet import reactor
 
import cyclone.web, cyclone.httpclient, cyclone.websocket
 
from rdflib import URIRef
 
from lib.cycloneerr import PrettyErrorHandler
 
from run_local import log
 
from louie import dispatcher
light9/curvecalc/curveview.py
Show inline comments
 
from __future__ import division
 
import math, logging
 
import math, logging, traceback
 
from gi.repository import Gtk
 
from gi.repository import Gdk
 
from gi.repository import GooCanvas
 
import louie as dispatcher
 
from rdflib import Literal
 
from twisted.internet import reactor
 
@@ -378,27 +378,45 @@ class Curveview(object):
 
        box.show()
 
        return box
 

	
 
    def trackWidgetSize(self):
 
        """
 
        Also tried:
 
            visibility-notify-event (Gdk.EventMask.VISIBILITY_NOTIFY_MASK)
 
            fires on some resizes but not all.
 

	
 
            visibility-notify-event
 
            (Gdk.EventMask.VISIBILITY_NOTIFY_MASK) fires on some
 
            resizes but maybe not all. Could be doing the right thing,
 
            though
 
        
 
            configure-event seems to never fire.
 

	
 
            size-allocate seems right but i get into infinite bounces
 
            between two sizes
 
        """
 
        def sizeEvent(w, alloc):
 
            p = self.canvas.props
 
            if (alloc.width, alloc.height) != (p.x2, p.y2):
 
                p.x1, p.x2 = 0, alloc.width
 
                p.y1, p.y2 = 0, alloc.height
 
                # calling update_curve in this event usually doesn't work
 
                reactor.callLater(0, self.update_curve)
 
            return False
 
            
 
        self.widget.connect('size-allocate', sizeEvent)
 
        #self.widget.connect('size-allocate', sizeEvent) # see docstring
 

	
 
        def visEvent(w, alloc):
 
            p = self.canvas.props
 
            w = self.widget.get_allocated_width()
 
            h = self.widget.get_allocated_height()
 
            if (w, h) != (p.x2, p.y2):
 
                p.x1, p.x2 = 0, w
 
                p.y1, p.y2 = 0, h
 
                self.update_curve()
 
            return False
 
        self.widget.add_events(Gdk.EventMask.VISIBILITY_NOTIFY_MASK)
 
        self.widget.connect('visibility-notify-event', visEvent)
 
        
 
    def createCanvasWidget(self, parent):
 
        # this is only separate from createOuterWidgets because in the
 
        # past, i worked around display bugs by recreating the whole
 
        # canvas widget. If that's not necessary, this could be more
 
        # clearly combined with createOuterWidgets since there's no
 
@@ -426,17 +444,19 @@ class Curveview(object):
 
        return canvas
 

	
 
    def onAny(self, w, event):
 
        print "   %s on %s" % (event, w)
 
        
 
    def onFocusIn(self, *args):
 
        dispatcher.send('curve row focus change')     
 
        dispatcher.send("all curves lose selection", butNot=self)
 

	
 
        self.widget.modify_bg(Gtk.StateFlags.NORMAL, Gdk.color_parse("red"))
 

	
 
    def onFocusOut(self, widget=None, event=None):
 
        dispatcher.send('curve row focus change')                  
 
        self.widget.modify_bg(Gtk.StateFlags.NORMAL, Gdk.color_parse("gray30"))
 

	
 
        # you'd think i'm unselecting when we lose focus, but we also
 
        # lose focus when the user moves off the toplevel window, and
 
        # that's not a time to forget the selection. See the 'all
 
        # curves lose selection' signal for the fix.
 
@@ -678,14 +698,27 @@ class Curveview(object):
 
                pos = self.screen_from_world(prevKey)
 
                self.create_oval(pos[0] - 8, pos[1] - 8,
 
                                 pos[0] + 8, pos[1] + 8,
 
                                 outline='#800000',
 
                                 tags=('knob',))
 
                dispatcher.send("knob out", value=prevKey[1], curve=self.curve)
 
       
 

	
 
    def update_curve(self, *args):
 
        if not getattr(self, '_pending_update', False):
 
            self._pending_update = True
 
            reactor.callLater(.01, self._update_curve)
 
        
 
    def _update_curve(self):
 
        if not getattr(self, '_pending_update', False):
 
            return
 
        self._pending_update = False
 
        if not self.canvas.is_visible():
 
            # this avoids an occasional crash in something like
 
            # goocanvas_add_item when we write objects to a canvas
 
            # that's gone
 
            return
 
        if not self.redrawsEnabled:
 
            print "no redrawsEnabled, skipping", self
 
            return
 

	
 
        visible_x = (self.world_from_screen(0,0)[0],
 
                     self.world_from_screen(self.canvas.props.x2, 0)[0])
 
@@ -800,17 +833,21 @@ class Curveview(object):
 
        if area:
 
            try:
 
                base = self.screen_from_world((0, 0))[1]
 
            except ZeroDivisionError:
 
                base = -100
 
            base = base + linewidth / 2
 
            areapts = linepts[:]
 
            if len(areapts) >= 1:
 
                areapts.insert(0, (0, areapts[0][1]))
 
                areapts.append((self.canvas.props.x2, areapts[-1][1]))
 
            polyline_new_line(parent=self.curveGroup,
 
                               points=Points(
 
                                   [(linepts[0][0], base)] +
 
                                   linepts +
 
                                   [(linepts[-1][0], base)]),
 
                                   [(areapts[0][0], base)] +
 
                                   areapts +
 
                                   [(areapts[-1][0], base)]),
 
                               close_path=True,
 
                               line_width=0,
 
                               fill_color="green",
 
                               )
 

	
 
        self.pl = polyline_new_line(parent=self.curveGroup,
 
@@ -994,12 +1031,16 @@ class Curveview(object):
 
        self.select_indices([])
 

	
 
    def onScroll(self, widget, event):
 
        t = self.world_from_screen(event.x, 0)[0]
 
        self.zoomControl.zoom_about_mouse(
 
            t, factor=1.5 if event.direction == Gdk.ScrollDirection.DOWN else 1/1.5)
 
        # Don't actually scroll the canvas! (it shouldn't have room to
 
        # scroll anyway, but it does because of some coordinate errors
 
        # and borders and stuff)
 
        return True 
 
        
 
    def onRelease(self, widget, event):
 
        self.print_state("dotrelease")
 

	
 
        if event.state & Gdk.ModifierType.SHIFT_MASK: # relese-B1
 
            self.sketch_release(event)
 
@@ -1039,12 +1080,15 @@ class CurveRow(object):
 
                                   isMusic=name in ['music', 'smooth_music'],
 
                                   zoomControl=zoomControl)
 
        
 
        self.initCurveView()
 
        dispatcher.connect(self.rebuild, "all curves rebuild")
 

	
 
    def isFocus(self):
 
        return self.curveView.widget.is_focus()
 
        
 
    def rebuild(self):
 
        raise NotImplementedError('obsolete, if curves are drawing right')
 
        self.curveView.rebuild()
 
        self.initCurveView()
 
        self.update_ui_to_collapsed_state()
 

	
 
@@ -1052,14 +1096,17 @@ class CurveRow(object):
 
        self.curveView.entered = False  # help suppress bad position events
 
        del self.curveView
 
        self.box.destroy()
 
        
 
    def initCurveView(self):
 
        self.curveView.widget.show()
 
        self.curveView.widget.set_size_request(-1, 100)
 
        self.setHeight(100)
 
        self.cols.pack_start(self.curveView.widget, expand=True, fill=True, padding=0)       
 

	
 
    def setHeight(self, h):
 
        self.curveView.widget.set_size_request(-1, h)
 
        
 
    def setupControls(self, controls, name, curve, slider):
 
        box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
 
        controls.add(box)
 

	
 
        curve_name_label = Gtk.LinkButton()
 
@@ -1126,12 +1173,13 @@ class Curvesetview(object):
 
    def __init__(self, graph, curvesVBox, zoomControlBox, curveset):
 
        self.graph = graph
 
        self.live = True
 
        self.curvesVBox = curvesVBox
 
        self.curveset = curveset
 
        self.allCurveRows = set()
 
        self.visibleHeight = 1000
 

	
 
        self.zoomControl = self.initZoomControl(zoomControlBox)
 
        self.zoomControl.redrawzoom()
 
        
 
        for c in curveset.curveNamesInOrder():
 
            self.add_curve(c) 
 
@@ -1144,12 +1192,14 @@ class Curvesetview(object):
 
        self.newcurvename = Gtk.EntryBuffer.new("", 0)
 

	
 
        eventBox = self.curvesVBox.get_parent()
 
        eventBox.connect("key-press-event", self.onKeyPress)
 
        eventBox.connect("button-press-event", self.takeFocus)
 

	
 
        self.watchCurveAreaHeight()
 

	
 
    def __del__(self):
 
        print "del curvesetview", id(self) 
 

	
 
    def initZoomControl(self, zoomControlBox):
 
        import light9.curvecalc.zoomcontrol
 
        reload(light9.curvecalc.zoomcontrol)
 
@@ -1215,14 +1265,43 @@ class Curvesetview(object):
 
        curve = self.curveset.curves[name]
 
        f = CurveRow(self.graph, name, curve, self.curveset.markers,
 
                     slider, knobEnabled, self.zoomControl)
 
        self.curvesVBox.pack_start(f.box, expand=True, fill=True, padding=0)
 
        f.box.show_all()
 
        self.allCurveRows.add(f)
 
        self.setRowHeights()
 
        f.curveView.goLive()
 

	
 
    def watchCurveAreaHeight(self):
 
        def sizeEvent(w, size):
 
            # this is firing really often
 
            if self.visibleHeight == size.height:
 
                return
 
            print "size.height is new", size.height
 
            self.visibleHeight = size.height
 
            self.setRowHeights()
 

	
 
        visibleArea = self.curvesVBox.get_parent().get_parent()
 
        visibleArea.connect('size-allocate', sizeEvent)
 

	
 
        dispatcher.connect(self.setRowHeights, "curve row focus change")
 
        
 
    def setRowHeights(self):
 
        focusHeight = 100
 
        nRows = len(self.allCurveRows)
 
        if not nRows:
 
            return
 
        anyFocus = any(r.isFocus() for r in self.allCurveRows)
 

	
 
        if anyFocus:
 
            h = max(14, (self.visibleHeight - focusHeight) // (nRows - 1)) - 3
 
        else:
 
            h = max(14, self.visibleHeight // nRows) - 3
 
        for row in self.allCurveRows:
 
            row.setHeight(100 if row.isFocus() else h)
 
            
 
    def row(self, name):
 
        if isinstance(name, Literal):
 
            name = str(name)
 
        matches = [r for r in self.allCurveRows if r.name == name]
 
        if not matches:
 
            raise ValueError("no curveRow named %r. only %s" %
0 comments (0 inline, 0 general)