From 06c639db6b98affab4abf07e57a90e2fcb5402ef Mon Sep 17 00:00:00 2001 From: rcoh Date: Sat, 5 Feb 2011 22:34:34 -0500 Subject: Early stages of param-binding in xml. Functional. RCOH --- util/ColorOps.py | 4 ++++ util/Config.py | 10 ++++++++++ util/Geo.py | 7 +++++++ 3 files changed, 21 insertions(+) (limited to 'util') diff --git a/util/ColorOps.py b/util/ColorOps.py index 4b1162a..796a902 100644 --- a/util/ColorOps.py +++ b/util/ColorOps.py @@ -40,3 +40,7 @@ def randomBrightColor(): hue, sat, val = colorsys.hsv_to_rgb(hue, sat, val) ret = [hue, sat, val] return floatToIntColor(ret) + +class Color(object): + def __init__(self, r,g,b): + self.rep = [r,g,b] diff --git a/util/Config.py b/util/Config.py index 6fdb0d4..4153313 100644 --- a/util/Config.py +++ b/util/Config.py @@ -1,4 +1,5 @@ from xml.etree.ElementTree import * +import re import sys import xml import pdb @@ -113,6 +114,15 @@ def pullArgsFromItem(parentNode): def attemptEval(val): try: + if '${' in val and '}$' in val: #TODO: this could be a little cleaner + dictVal = re.sub("'\$\{(.+)\}\$'", "b['\\1']", val) #replace all expressions like {blah} with a['blah'] + dictVal = re.sub("\$\{(.+)\}\$", "a['\\1']", dictVal) #replace all expressions like {blah} with a['blah'] + if "'${" and "}$'" in val: #nested lambda madness + lambdaVal = eval('lambda a: lambda b: ' + dictVal) + else: + lambdaVal = eval('lambda a:'+dictVal) #TODO: nested lambdas + return lambdaVal #convert referential objects to lambda expressions which resolve + #dynamically val = eval(val) except (NameError, SyntaxError): val = str(val) diff --git a/util/Geo.py b/util/Geo.py index 0dde80b..43817ad 100644 --- a/util/Geo.py +++ b/util/Geo.py @@ -32,3 +32,10 @@ def windtrail(x,y,height,center,width): b=center c=width return a*((math.exp(-((x-b))/(c)))**2)*(math.exp(-((y))/(0.2*c)))**2 + +class Location(object): + def __init__(self,x=0,y=0): + self.x = x + self.y = y + def __add__(self, b): + return Location(self.x+b.x, self.y+b.y) -- cgit v1.2.3