Changeset - f2dbb0b1fb35
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 16 years ago 2009-06-29 04:40:34
drewp@bigasterisk.com
optimize the number of curve redraws at curvecalc's startup
Ignore-this: 4498afcf51bfdba37a7c0cfe12596958
2 files changed with 33 insertions and 7 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -463,15 +463,15 @@ def main():
 
    if 'panes':
 
        panes = tk.PanedWindow(root, height=1)
 
        panes.add('curvesetView')
 
        panes.add('subterms')
 
        panes.pack(side='top', fill='both', expand=True)
 

	
 
        csv = Curvesetview(panes.subwidget('curvesetView'), curveset,
 
        curvesetView = Curvesetview(panes.subwidget('curvesetView'), curveset,
 
                           height=400)
 
        csv.pack(fill='both', expand=True)
 
        curvesetView.pack(fill='both', expand=True)
 

	
 
        subtermArea = tk.Frame(panes.subwidget('subterms'), height=100)
 
        subtermArea.pack(fill='both', expand=True)
 

	
 
        subtermScroll = tk.ScrolledWindow(subtermArea)
 
        subtermScroll.pack(fill='both')
 
@@ -495,11 +495,16 @@ def main():
 
                                        showconfig.songFilenameFromURI(song)),
 
                  skipMusic=opts.skip_music)
 
    
 
    dispatcher.send("max time",maxtime=maxtime)
 
    dispatcher.send("show all")
 

	
 
    # 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.
 
    reactor.callLater(.1, curvesetView.goLive)
 

	
 
    tksupport.install(root, ms=10)
 
    log.debug("run")
 
    prof.run(reactor.run, profile=False)
 

	
 
main()
light9/curve.py
Show inline comments
 
@@ -161,21 +161,21 @@ class Sketch:
 

	
 

	
 
class Curveview(tk.Canvas):
 
    def __init__(self, master, curve, knobEnabled=False, **kw):
 
        """knobEnabled=True highlights the previous key and ties it to a
 
        hardware knob"""
 
        self.redrawsEnabled = False
 
        self.curve = curve
 
        self.knobEnabled = knobEnabled
 
        self._time = 0
 
        self.last_mouse_world = None
 
        tk.Canvas.__init__(self,master,width=10,height=10,
 
                           relief='sunken',bd=1,
 
                           closeenough=5,takefocus=1, **kw)
 
        self.selected_points=[] # idx of points being dragged
 
        self.update_curve()
 
        # self.bind("<Enter>",self.focus)
 
        dispatcher.connect(self.input_time, "input time")
 
        dispatcher.connect(self.update_curve, "zoom changed")
 
        dispatcher.connect(self.update_curve, "points changed",
 
                           sender=self.curve)
 
        dispatcher.connect(self.update_curve, "mute changed", 
 
@@ -190,17 +190,21 @@ class Curveview(tk.Canvas):
 
                self.add_point((self.current_time(), (x - 1) / 4.0))
 

	
 
            self.bind("<Key-%s>" % x, add_kb_marker_point)
 

	
 

	
 
        for butnum,factor in (5, 1.5),(4, 1/1.5):
 
            self.bind("<ButtonPress-%s>"%butnum,
 
                      lambda ev,factor=factor:
 
            def onMouseWheel(ev,factor=factor):
 
                      dispatcher.send("zoom about mouse",
 
                                      t=self.world_from_screen(ev.x,0)[0],
 
                                      factor=factor))
 
                                factor=factor)
 
                # this is supposed to make the canvases redraw more
 
                # visibly, so we don't waste line redraws that never
 
                # get seen. I'm not sure if it works.
 
                self.update()
 
            self.bind("<ButtonPress-%s>" % butnum, onMouseWheel)
 
        self.bind("<Key-Escape>", lambda ev:
 
                  dispatcher.send("see time",
 
                                  t=self.current_time()))
 
        self.bind("<Shift-Escape>", lambda ev:
 
                  dispatcher.send("see time until end",
 
                                  t=self.current_time()))
 
@@ -236,12 +240,18 @@ class Curveview(tk.Canvas):
 
        self.bind("<ButtonPress-1>", self.check_deselect, add=True)
 

	
 
        self.bind("<Key-m>", lambda *args: self.curve.toggleMute())
 
        self.bind("<Key-c>", lambda *args: dispatcher.send('toggle collapse',
 
                                                           sender=self.curve))
 

	
 
    def goLive(self):
 
        """this is for startup performance only, since the curves were
 
        getting redrawn many times. """
 
        self.redrawsEnabled = True
 
        self.update_curve()
 

	
 
    def knob_in(self, curve, value):
 
        """user turned a hardware knob, which edits the point to the
 
        left of the current time"""
 
        if curve != self.curve:
 
            return
 
        idx = self.curve.index_before(self.current_time())
 
@@ -350,12 +360,14 @@ class Curveview(tk.Canvas):
 
                                 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 self.redrawsEnabled:
 
            return
 
        self.width, self.height = self.winfo_width(), self.winfo_height()
 
        
 
        self.zoom = dispatcher.send("zoom area")[0][1]
 
        cp = self.curve.points
 

	
 
        visible_x = (self.world_from_screen(0,0)[0],
 
@@ -424,12 +436,13 @@ class Curveview(tk.Canvas):
 

	
 

	
 
    def _draw_line(self,visible_points):
 
        linepts=[]
 
        step=1
 
        linewidth=2
 
        # 800? maybe this should be related to self.width
 
        if len(visible_points)>800:
 
            step = int(len(visible_points)/800)
 
            linewidth=1
 
        for p in visible_points[::step]:
 
            linepts.extend(self.screen_from_world(p))
 
        if len(linepts)<4:
 
@@ -826,14 +839,14 @@ class CurveRow(tk.Frame):
 
        self.muted.set(self.curveView.curve.muted)
 
        self.update_mute_look()
 

	
 

	
 
class Curvesetview(tk.ScrolledWindow):
 
    def __init__(self, master, curveset, **kw):
 
        self.curves = {} # curvename : Curveview
 
        self.curveset = curveset
 
        self.allCurveRows = set()
 
        tk.ScrolledWindow.__init__(self,master,**kw)
 
        
 
        f = tk.Frame(self.window,relief='raised',bd=1)
 
        f.pack(side='top',fill='x')
 
        tk.Label(f, text="new curve named: (C-N)").pack(side='left')
 
        
 
@@ -854,7 +867,15 @@ class Curvesetview(tk.ScrolledWindow):
 
        self.newcurvename.set('')
 
        
 
    def add_curve(self, name, slider=None, knobEnabled=False):
 
        curve = self.curveset.curves[name]
 
        f = CurveRow(self.window, name, curve, slider, knobEnabled)
 
        f.pack(side='top', fill='both')
 
        self.allCurveRows.add(f)
 

	
 
    def goLive(self):
 
        """for startup performance, none of the curves redraw
 
        themselves until this is called once (and then they're normal)"""
 
        
 
        for cr in self.allCurveRows:
 
            cr.curveView.goLive()
 

	
0 comments (0 inline, 0 general)