# HG changeset patch # User drewp@bigasterisk.com # Date 1371233287 0 # Node ID 8152b1dd8a2f7a1643d7948935ff44eca938f744 # Parent 891f2d75c686896611f3b6a51d3ae75707c4d904 focus on a subterm expression, and we'll bring any curves it mentions up to the top of the curvesetview Ignore-this: f1a6456ed67a46cfdc7e0b8ba3f6fce7 diff -r 891f2d75c686 -r 8152b1dd8a2f light9/curvecalc/curveview.py --- a/light9/curvecalc/curveview.py Fri Jun 14 05:30:45 2013 +0000 +++ b/light9/curvecalc/curveview.py Fri Jun 14 18:08:07 2013 +0000 @@ -1142,6 +1142,7 @@ self.add_curve(c) dispatcher.connect(self.add_curve, "add_curve", sender=self.curveset) + dispatcher.connect(self.set_featured_curves, "set_featured_curves") self.newcurvename = gtk.EntryBuffer("", 0) @@ -1158,6 +1159,18 @@ dispatcher.send("all curves lose selection") self.curvesVBox.get_parent().grab_focus() + def curveRow_from_name(self, name): + for cr in self.allCurveRows: + if cr.name == name: + return cr + raise ValueError("couldn't find curveRow named %r" % name) + + def set_featured_curves(self, curveNames): + """bring these curves to the top of the stack""" + for n in curveNames[::-1]: + self.curvesVBox.reorder_child(self.curveRow_from_name(n).box, + gtk.PACK_START) + def onKeyPress(self, widget, event): if not self.live: # workaround for old instances living past reload() return diff -r 891f2d75c686 -r 8152b1dd8a2f light9/curvecalc/subterm.py --- a/light9/curvecalc/subterm.py Fri Jun 14 05:30:45 2013 +0000 +++ b/light9/curvecalc/subterm.py Fri Jun 14 18:08:07 2013 +0000 @@ -110,6 +110,17 @@ dispatcher.send("expr_error", sender=self.uri, exc=repr(e)) return Submaster.Submaster(name='Error: %s' % str(e), levels={}) + def curves_used_by_expr(self): + """names of curves that are (maybe) used in this expression""" + + with self.graph.currentState(tripleFilter=(self.uri, None, None)) as current: + expr = current.value(self.uri, L9['expression']) + + used = [] + for name in self.curveset.curveNamesInOrder(): + if name in expr: + used.append(name) + return used def eval(self, current, t): """current graph is being passed as an optimization. It should be diff -r 891f2d75c686 -r 8152b1dd8a2f light9/curvecalc/subtermview.py --- a/light9/curvecalc/subtermview.py Fri Jun 14 05:30:45 2013 +0000 +++ b/light9/curvecalc/subtermview.py Fri Jun 14 18:08:07 2013 +0000 @@ -9,9 +9,10 @@ keep = [] class Subexprview(object): - def __init__(self, graph, ownerSubterm, saveContext): + def __init__(self, graph, ownerSubterm, saveContext, curveset): self.graph, self.ownerSubterm = graph, ownerSubterm self.saveContext = saveContext + self.curveset = curveset self.box = gtk.HBox() @@ -27,9 +28,20 @@ self.entryBuffer.connect("deleted-text", self.entry_changed) self.entryBuffer.connect("inserted-text", self.entry_changed) + self.entry.connect("focus-in-event", self.onFocus) + dispatcher.connect(self.exprError, "expr_error", sender=self.ownerSubterm) keep.append(self.__dict__) + def onFocus(self, *args): + curveNames = self.curveset.curveNamesInOrder() + currentExpr = self.entryBuffer.get_text() + + usedCurves = [n for n in curveNames if n in currentExpr] + usedCurves.sort() + + dispatcher.send("set_featured_curves", curveNames=usedCurves) + def exprError(self, exc): self.error.set_text(str(exc)) @@ -51,7 +63,7 @@ """ has .label and .exprView widgets for you to put in a table """ - def __init__(self, st): + def __init__(self, st, curveset): self.subterm = st self.graph = st.graph @@ -63,7 +75,7 @@ actions=gtk.gdk.ACTION_COPY) self.label.connect("drag-data-received", self.onDataReceivedOnLabel) - sev = Subexprview(self.graph, self.subterm.uri, self.subterm.saveContext) + sev = Subexprview(self.graph, self.subterm.uri, self.subterm.saveContext, curveset) self.exprView = sev.box def onDataReceivedOnLabel(self, widget, context, x, y, selection, @@ -87,7 +99,7 @@ self.label.set_text(label) def add_one_subterm(subterm, curveset, master, show=False): - stv = Subtermview(subterm) + stv = Subtermview(subterm, curveset) y = master.get_property('n-rows') master.attach(stv.label, 0, 1, y, y + 1, xoptions=0, yoptions=0)