Mercurial > code > home > repos > light9
changeset 780:94f85500b995
Add getsub function for expressions
Ignore-this: 6e6adc831107bbf7876bff1e670e34a0
author | drewp@bigasterisk.com |
---|---|
date | Sun, 17 Jun 2012 00:17:10 +0000 |
parents | d3f6830f55a2 |
children | 3277584aa545 |
files | light9/Submaster.py light9/curvecalc/subterm.py light9/curvecalc/subtermview.py |
diffstat | 3 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/Submaster.py Sat Jun 16 23:46:21 2012 +0000 +++ b/light9/Submaster.py Sun Jun 17 00:17:10 2012 +0000 @@ -271,11 +271,11 @@ # a global instance of Submasters, created on demand _submasters = None -def get_global_submasters(): - """Get (and make on demand) the global instance of Submasters""" +def get_global_submasters(graph): + """Get (and make on demand) the global instance of Submasters.""" global _submasters if _submasters is None: - _submasters = Submasters() + _submasters = Submasters(graph) return _submasters def get_sub_by_name(name, submasters=None):
--- a/light9/curvecalc/subterm.py Sat Jun 16 23:46:21 2012 +0000 +++ b/light9/curvecalc/subterm.py Sun Jun 17 00:17:10 2012 +0000 @@ -71,11 +71,14 @@ class Subexpr: curveset = None - def __init__(self,curveset,expr=""): + def __init__(self,curveset,expr="",graph=None): self.curveset = curveset self.lasteval = None - self.expr=expr + self.expr = expr + self.graph = graph self._smooth_random_items = [random.random() for x in range(100)] + self.submasters = Submaster.get_global_submasters(self.graph) + def eval(self,t): if self.expr=="": dispatcher.send("expr_error",sender=self,exc="no expr, using 0") @@ -84,6 +87,7 @@ glo['t'] = t glo = exprglo.exprGlobals(glo, t) + glo['getsub'] = lambda name: self.submasters.get_sub_by_name(name) try: self.lasteval = eval(self.expr,glo)
--- a/light9/curvecalc/subtermview.py Sat Jun 16 23:46:21 2012 +0000 +++ b/light9/curvecalc/subtermview.py Sun Jun 17 00:17:10 2012 +0000 @@ -68,7 +68,7 @@ expr = '%s(t)' % subname term = Subterm(Submaster.Submaster(graph=graph, name=subname, sub=subUri), - Subexpr(curveset, expr)) + Subexpr(curveset, expr, graph)) subterms.append(term) stv = Subtermview(graph, term)