Changeset - 94f85500b995
[Not reviewed]
default
0 3 0
drewp@bigasterisk.com - 13 years ago 2012-06-17 00:17:10
drewp@bigasterisk.com
Add getsub function for expressions
Ignore-this: 6e6adc831107bbf7876bff1e670e34a0
3 files changed with 10 insertions and 6 deletions:
0 comments (0 inline, 0 general)
light9/Submaster.py
Show inline comments
 
@@ -271,11 +271,11 @@ def fullsub(*chans):
 
# 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):
light9/curvecalc/subterm.py
Show inline comments
 
@@ -71,11 +71,14 @@ exprglo = Expr()
 
        
 
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 @@ class Subexpr:
 
        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)
light9/curvecalc/subtermview.py
Show inline comments
 
@@ -68,7 +68,7 @@ def add_one_subterm(graph, subUri, curve
 
        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)
0 comments (0 inline, 0 general)