# HG changeset patch # User drewp@bigasterisk.com # Date 2009-06-29 04:40:34 # Node ID f2dbb0b1fb35e03697062a61c7e480f2ade6f914 # Parent c355735fe76c4972d8d5f7472f0d7d74fe24b2ab optimize the number of curve redraws at curvecalc's startup Ignore-this: 4498afcf51bfdba37a7c0cfe12596958 diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -466,9 +466,9 @@ def main(): panes.add('subterms') panes.pack(side='top', fill='both', expand=True) - csv = Curvesetview(panes.subwidget('curvesetView'), curveset, - height=400) - csv.pack(fill='both', expand=True) + curvesetView = Curvesetview(panes.subwidget('curvesetView'), curveset, + height=400) + curvesetView.pack(fill='both', expand=True) subtermArea = tk.Frame(panes.subwidget('subterms'), height=100) subtermArea.pack(fill='both', expand=True) @@ -497,6 +497,11 @@ def main(): 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") diff --git a/light9/curve.py b/light9/curve.py --- a/light9/curve.py +++ b/light9/curve.py @@ -164,6 +164,7 @@ 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 @@ -172,7 +173,6 @@ class Curveview(tk.Canvas): relief='sunken',bd=1, closeenough=5,takefocus=1, **kw) self.selected_points=[] # idx of points being dragged - self.update_curve() # self.bind("",self.focus) dispatcher.connect(self.input_time, "input time") dispatcher.connect(self.update_curve, "zoom changed") @@ -193,11 +193,15 @@ class Curveview(tk.Canvas): for butnum,factor in (5, 1.5),(4, 1/1.5): - self.bind(""%butnum, - lambda ev,factor=factor: - dispatcher.send("zoom about mouse", - t=self.world_from_screen(ev.x,0)[0], - factor=factor)) + def onMouseWheel(ev,factor=factor): + dispatcher.send("zoom about mouse", + t=self.world_from_screen(ev.x,0)[0], + 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("" % butnum, onMouseWheel) self.bind("", lambda ev: dispatcher.send("see time", t=self.current_time())) @@ -239,6 +243,12 @@ class Curveview(tk.Canvas): self.bind("", 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""" @@ -353,8 +363,10 @@ class Curveview(tk.Canvas): 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 @@ -427,6 +439,7 @@ class Curveview(tk.Canvas): 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 @@ -829,8 +842,8 @@ class CurveRow(tk.Frame): 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) @@ -857,4 +870,12 @@ class Curvesetview(tk.ScrolledWindow): 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() +