def process_src(nm, code): try: f = Tl(nm) except: f = vcs.elements["line"][nm] atts = {} for a in ["ltyp", "lwsf", "lci", "vp", "wc", "x", "y"]: i = code.find(a + "(") v = genutil.get_parenthesis_content(code[i:]) # print nm,a,v if v != "": vals = [] for V in v.split(","): try: vals.append(int(V)) except: vals.append(float(V)) atts[a] = vals f.color = atts.get("lci", f.color) f.width = atts.get("lwsf", f.width) f.type = atts.get("ltyp", f.type) f.viewport = atts.get("vp", f.viewport) f.worldcoordinate = atts.get("wc", f.worldcoordinate) f.x = atts.get('x', f.x) f.y = atts.get('y', f.y) i = code.find("projection=") if i > -1: j = code[i:].find(",") + i f.projection = code[i + 11:j]
def process_src(nm, code): try: f = Tf(nm) except: f = vcs.elements["fillarea"][nm] atts = {} for a in ["faci", "fasi", "fais", "faoi", "vp", "wc", "x", "y"]: i = code.find(a + "(") v = genutil.get_parenthesis_content(code[i:]) # print nm,a,v if v != "": vals = [] for V in v.split(","): try: vals.append(int(V)) except: vals.append(float(V)) atts[a] = vals f.style = atts.get("fais", f.style) I = atts.get("fasi", f.index) for i, v in enumerate(I): if v == 0: I[i] = 1 f.index = I f.color = atts.get("faci", f.color) f.opacity = atts.get("faoi", f.opacity) f.viewport = atts.get("vp", f.viewport) f.worldcoordinate = atts.get("wc", f.worldcoordinate) f.x = atts.get('x', f.x) f.y = atts.get('y', f.y) i = code.find("projection=") if i > -1: j = code[i:].find(",") + i f.projection = code[i + 11:j] for b in vcs.elements["boxfill"].values( ) + vcs.elements["isofill"].values() + vcs.elements["meshfill"].values(): if b.fillareaindices is not None: for i, v in enumerate(b.fillareaindices): if isinstance(v, str) and v == nm: b._fillareaindices[i] = f.index b._fillareacolor[i] = f.color b._fillareastyle = f.style b._fillareaopacity = f.opacity
def process_src(nm, code): try: f = Tf(nm) except: f = vcs.elements["fillarea"][nm] atts = {} for a in ["faci", "fasi", "fais", "vp", "wc", "x", "y"]: i = code.find(a + "(") v = genutil.get_parenthesis_content(code[i:]) # print nm,a,v if v != "": vals = [] for V in v.split(","): try: vals.append(int(V)) except: vals.append(float(V)) atts[a] = vals f.style = atts.get("fais", f.style) I = atts.get("fasi", f.index) for i, v in enumerate(I): if v == 0: I[i] = 1 f.index = I f.color = atts.get("faci", f.color) f.viewport = atts.get("vp", f.viewport) f.worldcoordinate = atts.get("wc", f.worldcoordinate) f.x = atts.get('x', f.x) f.y = atts.get('y', f.y) i = code.find("projection=") if i > -1: j = code[i:].find(",") + i f.projection = code[i + 11:j] for b in vcs.elements["boxfill"].values() + vcs.elements[ "isofill"].values() + vcs.elements["meshfill"].values(): if b.fillareaindices is not None: for i, v in enumerate(b.fillareaindices): if isinstance(v, str) and v == nm: b._fillareaindices[i] = f.index b._fillareacolor[i] = f.color b._fillareastyle = f.style
def process_src(nm, code): try: f = Tl(nm) except Exception: f = vcs.elements["line"][nm] atts = {} # ltyp: line type # lwsf: line width # lci: line color index # vp: viewport # wc: world coordinates # x: x coordinates # y: y coordinates for a in ["ltyp", "lwsf", "lci", "vp", "wc", "x", "y"]: i = code.find(a + "(") v = genutil.get_parenthesis_content(code[i:]) if v != "": vals = [] for V in v.split(","): try: vals.append(int(V)) except Exception: vals.append(float(V)) atts[a] = vals if "lci" not in list(atts.keys()): sp = code.split(",") atts["lci"] = int(sp[2]) atts["ltyp"] = abs(int(sp[0]) - 1) atts["lwsf"] = float(sp[1]) f.type = atts.get("ltyp", f.type) f.color = atts.get("lci", f.color) f.width = atts.get("lwsf", f.width) f.viewport = atts.get("vp", f.viewport) f.worldcoordinate = atts.get("wc", f.worldcoordinate) f.x = atts.get('x', f.x) f.y = atts.get('y', f.y) i = code.find("projection=") if i > -1: j = code[i:].find(",") + i f.projection = code[i + 11:j]
def process_src(nm, code): try: f = Tl(nm) except: f = vcs.elements["line"][nm] atts = {} # ltyp: line type # lwsf: line width # lci: line color index # vp: viewport # wc: world coordinates # x: x coordinates # y: y coordinates for a in ["ltyp", "lwsf", "lci", "vp", "wc", "x", "y"]: i = code.find(a + "(") v = genutil.get_parenthesis_content(code[i:]) if v != "": vals = [] for V in v.split(","): try: vals.append(int(V)) except: vals.append(float(V)) atts[a] = vals if "lci" not in atts.keys(): sp = code.split(",") atts["lci"] = int(sp[2]) atts["ltyp"] = abs(int(sp[0])-1) atts["lwsf"] = float(sp[1]) f.type = atts.get("ltyp", f.type) f.color = atts.get("lci", f.color) f.width = atts.get("lwsf", f.width) f.viewport = atts.get("vp", f.viewport) f.worldcoordinate = atts.get("wc", f.worldcoordinate) f.x = atts.get('x', f.x) f.y = atts.get('y', f.y) i = code.find("projection=") if i > -1: j = code[i:].find(",") + i f.projection = code[i + 11:j]
def process_src(nm, code): # Takes VCS script code (string) as input and generates boxfill gm from it try: tt = Tt(nm) except: tt = vcs.elements["texttable"][nm] # process attributes with = as assignement atts = {} for a in ["string", "vp", "wc", "x", "y"]: i = code.find(a + "(") v = genutil.get_parenthesis_content(code[i:]) # print nm,a,v if v != "": vals = [] for V in v.split(","): try: vals.append(int(V)) except: vals.append(float(V)) atts[a] = vals tt.viewport = atts.get("vp", tt.viewport) tt.worldcoordinate = atts.get("wc", tt.worldcoordinate) tt.string = atts.get("string", tt.string) tt.x = atts.get("x", tt.x) tt.y = atts.get("y", tt.y) i = code.find("projection=") if i > -1: j = code[i:].find(",") + i tt.projection = code[i + 11:j] # rest of attributes sp = code.split(",") tt.priority = int(sp[0]) tt.font = int(sp[1]) tt.expansion = int(float(sp[2]) * 100.) tt.spacing = int(float(sp[3]) * 10.) tt.color = int(sp[4]) if len(sp) > 5: tt.fillincolor = int(sp[5])
def process_src(nm, code): """Takes VCS script code (string) as input and generates boxfill gm from it""" try: tt = Tt(nm) except: tt = vcs.elements["texttable"][nm] # process attributes with = as assignement atts = {} for a in ["string", "vp", "wc", "x", "y"]: i = code.find(a + "(") v = genutil.get_parenthesis_content(code[i:]) # print nm,a,v if v != "": vals = [] for V in v.split(","): try: vals.append(int(V)) except: vals.append(float(V)) atts[a] = vals tt.viewport = atts.get("vp", tt.viewport) tt.worldcoordinate = atts.get("wc", tt.worldcoordinate) tt.string = atts.get("string", tt.string) tt.x = atts.get("x", tt.x) tt.y = atts.get("y", tt.y) i = code.find("projection=") if i > -1: j = code[i:].find(",") + i tt.projection = code[i + 11:j] # rest of attributes sp = code.split(",") tt.priority = int(sp[0]) tt.font = int(sp[1]) tt.expansion = int(float(sp[2]) * 100.) tt.spacing = int(float(sp[3]) * 10.) tt.color = int(sp[4]) if len(sp) > 5: tt.fillincolor = int(sp[5])
import Canvas import VCS_validation_functions import vcs import genutil def process_src(nm,code): """Takes VCS script code (string) as input and generates boxfill gm from it""" try: tt = Tt(nm) except Exception,err: tt = vcs.elements["texttable"][nm] ## process attributes with = as assignement atts={} for a in ["string","vp","wc","x","y"]: i = code.find(a+"(") v=genutil.get_parenthesis_content(code[i:]) #print nm,a,v if v!="": vals = [] for V in v.split(","): try: vals.append(int(V)) except: vals.append(float(V)) atts[a]=vals tt.viewport = atts.get("vp",tt.viewport) tt.worldcoordinate = atts.get("wc",tt.worldcoordinate) tt.string = atts.get("string",tt.string) tt.x = atts.get("x",tt.x) tt.y = atts.get("y",tt.y) i = code.find("projection=")
def process_src(nm, code): """Takes VCS script code (string) as input and generates isoline gm from it""" try: g = Gi(nm) except: g = vcs.elements["isoline"][nm] # process attributes with = as assignement for att in ["projection", "xticlabels#1", "xticlabels#2", "xmtics#1", "xmtics#2", "yticlabels#1", "yticlabels#2", "ymtics#1", "ymtics#2", "xaxisconvert", "yaxisconvert", "datawc_tunits", "boxfill_type", "legend", "ext_1", "ext_2", "missing", "datawc_calendar", "make_labels"]: i = code.find(att) if i == -1: continue j = code[i:].find(",") + i if j - i == -1: # last one no comma j = None scode = code[i:j] sp = scode.split("=") nm = sp[0].strip() nm = nm.replace("#", "") if nm == "make_labels": nm = "label" elif nm == "datawc_tunits": nm = "datawc_timeunits" try: # int will be converted setattr(g, nm, int(sp[1])) except: try: # int and floats will be converted setattr(g, nm, eval(sp[1])) except: # strings try: setattr(g, nm, sp[1]) except: pass # oh well we stick to default value # Datawc idwc = code.find(" datawc(") if idwc > -1: jdwc = code[idwc:].find(")") + idwc cd = code[idwc + 8:jdwc] vals = cd.split(",") g.datawc_x1 = float(vals[0]) g.datawc_y1 = float(vals[1]) g.datawc_x2 = float(vals[2]) g.datawc_y2 = float(vals[3]) # idatawc idwc = code.find("idatawc(") if idwc > -1: jdwc = code[idwc:].find(")") + idwc cd = code[idwc + 8:jdwc] vals = cd.split(",") if int(vals[0]) == 1: g.datawc_x1 = cdtime.reltime( g.datawc_x1, g.datawc_timeunits).tocomp( g.datawc_calendar) if int(vals[1]) == 1: g.datawc_y1 = cdtime.reltime( g.datawc_x2, g.datawc_timeunits).tocomp( g.datawc_calendar) if int(vals[2]) == 1: g.datawc_x2 = cdtime.reltime( g.datawc_y1, g.datawc_timeunits).tocomp( g.datawc_calendar) if int(vals[3]) == 1: g.datawc_y2 = cdtime.reltime( g.datawc_y2, g.datawc_timeunits).tocomp( g.datawc_calendar) irg = code.find("lines") if irg > -1: scode = code[irg:] tl = [] tt = [] to = [] clock = [] scales = [] angles = [] spacing = [] levs = [] while scode.find("id=") > -1: sub = genutil.get_parenthesis_content(code[irg:]) if get_att_from_sub(sub, "label") not in ["*", None]: g.label = 'y' levs.append(get_att_from_sub(sub, "level")) tl.append(get_att_from_sub(sub, "Tl")) to.append(get_att_from_sub(sub, "To")) tt.append(get_att_from_sub(sub, "Tt")) clock.append(get_att_from_sub(sub, "clockwise")) scales.append(get_att_from_sub(sub, "length")) angles.append(get_att_from_sub(sub, "angle")) spacing.append(get_att_from_sub(sub, "spacing")) scode = scode[scode.find(sub) + len(sub):] g.level = levs try: g.line = tl except: g._line = tl try: g.text = to except: g._text = to try: g.textcolors = tt except: g._textcolors = tt gd = vcs.elements["isoline"]["default"] try: g.scale = scales except: g.scale = gd.scale try: g.angle = angles except: g.angle = gd.angle try: g.clockwise = clock except: g.clockwise = gd.clockwise
g.datawc_y2 = cdtime.reltime( gm.datawc_y2, g.datawc_timeunits).tocomp(g.datawc_calendar) irg = code.find("lines") if irg > -1: scode = code[irg:] label = 'n' tl = [] tt = [] to = [] clock = [] scales = [] angles = [] spacing = [] levs = [] while scode.find("id=") > -1: sub = genutil.get_parenthesis_content(code[irg:]) if get_att_from_sub(sub, "label") not in ["*", None]: g.label = 'y' levs.append(get_att_from_sub(sub, "level")) tl.append(get_att_from_sub(sub, "Tl")) to.append(get_att_from_sub(sub, "To")) tt.append(get_att_from_sub(sub, "Tt")) clock.append(get_att_from_sub(sub, "clockwise")) scales.append(get_att_from_sub(sub, "length")) angles.append(get_att_from_sub(sub, "angle")) spacing.append(get_att_from_sub(sub, "spacing")) scode = scode[scode.find(sub) + len(sub):] g.level = levs try: g.line = tl except:
def process_src(nm, code): # Takes VCS script code (string) as input and generates oneD gm from it try: gm = Tm(nm) except Exception: gm = vcs.elements["marker"][nm] # process attributes with = as assignement for att in [ "projection", ]: i = code.find(att) if i == -1: continue j = code[i:].find(",") + i if j - i == -1: # last one no comma j = None scode = code[i:j] sp = scode.split("=") nm = sp[0].strip() nm = nm.replace("#", "") try: # int will be converted setattr(gm, nm, int(sp[1])) except Exception: try: # int and floats will be converted setattr(gm, nm, eval(sp[1])) except Exception: # strings try: setattr(gm, nm, sp[1]) except Exception: pass # oh well we stick to default value # Datawc for att in ["mtyp", "msize", "mci", "vp", "wc"]: i = code.find(" %s(" % att) if i > -1: j = code[i:].find(")") + i cd = code[i + len(att) + 2:j] vals = cd.split(",") values = [] # print "ATT:",att,vals for v in vals: try: # int first values.append(int(v)) except Exception: try: values.append(float(v)) except Exception: values.append(v) try: if att == "mtyp": gm.type = values elif att == "msize": gm.size = values elif att == "mci": gm.color = values elif att == "vp": gm.viewport = values elif att == "wc": gm.worldcoordinate = values else: raise Exception("Unkwnow marker attribute: %s" % att) except Exception: pass for att in ["x", "y"]: i = code.find(" %s(" % att) if i == -1: i = code.find(",%s(" % att) if i > -1: v = genutil.get_parenthesis_content(code[i:]) setattr(gm, att, eval(v))
def process_src(nm, code): try: f = Tf(nm) except: f = vcs.elements["fillarea"][nm] atts = {} if code.find("(") > -1: # ok with have the keywords spelled out # faci: fillarea color index # fasi: fillarea style index # fais: fillarea index style (hatching/pattern/solid) # faoi: ??? # vp: viewport # wc: worldcoordinates # x: x coordinates # y: y coordinates for a in ["faci", "fasi", "fais", "faoi", "vp", "wc", "x", "y"]: i = code.find(a + "(") v = genutil.get_parenthesis_content(code[i:]) if v != "": vals = [] for V in v.split(","): try: vals.append(int(V)) except: vals.append(float(V)) if a in ["fais"]: vals[-1] = vals[-1]-1 atts[a] = vals else: sp = code.split(",") atts["fais"] = int(sp[0]) - 1 atts["faci"] = int(sp[2]) atts["fasi"] = int(sp[1]) atts["vp"] = [10. * float(sp[-4]), 10. * float(sp[-3]), 10. * float(sp[-2]), 10. * float(sp[-1])] f.style = atts.get("fais", f.style) try: # in case these are strings? I = atts.get("fasi", f.index) for i, v in enumerate(I): if v == 0: I[i] = 1 except: pass f.index = I f.color = atts.get("faci", f.color) f.viewport = atts.get("vp", f.viewport) f.worldcoordinate = atts.get("wc", f.worldcoordinate) f.x = atts.get('x', f.x) f.y = atts.get('y', f.y) i = code.find("projection=") if i > -1: j = code[i:].find(",") + i f.projection = code[i + 11:j] for b in vcs.elements["boxfill"].values( ) + vcs.elements["isofill"].values() + vcs.elements["meshfill"].values(): if b.fillareaindices is not None: for i, v in enumerate(b.fillareaindices): if isinstance(v, str) and v == nm: b._fillareaindices[i] = f.index b._fillareacolor[i] = f.color b._fillareastyle = f.style b._fillareaopacity = f.opacity
def process_src(nm, code): """Takes VCS script code (string) as input and generates oneD gm from it""" try: gm = Tm(nm) except: gm = vcs.elements["marker"][nm] # process attributes with = as assignement for att in ["projection", ]: i = code.find(att) if i == -1: continue j = code[i:].find(",") + i if j - i == -1: # last one no comma j = None scode = code[i:j] sp = scode.split("=") nm = sp[0].strip() nm = nm.replace("#", "") try: # int will be converted setattr(gm, nm, int(sp[1])) except: try: # int and floats will be converted setattr(gm, nm, eval(sp[1])) except: # strings try: setattr(gm, nm, sp[1]) except: pass # oh well we stick to default value # Datawc for att in ["mtyp", "msize", "mci", "vp", "wc"]: i = code.find(" %s(" % att) if i > -1: j = code[i:].find(")") + i cd = code[i + len(att) + 2:j] vals = cd.split(",") values = [] # print "ATT:",att,vals for v in vals: try: # int first values.append(int(v)) except: try: values.append(float(v)) except: values.append(v) try: if att == "mtyp": gm.type = values elif att == "msize": gm.size = values elif att == "mci": gm.color = values elif att == "vp": gm.viewport = values elif att == "wc": gm.worldcoordinate = values else: raise Exception("Unkwnow marker attribute: %s" % att) except: pass for att in ["x", "y"]: i = code.find(" %s(" % att) if i == -1: i = code.find(",%s(" % att) if i > -1: v = genutil.get_parenthesis_content(code[i:]) setattr(gm, att, eval(v))
if int(vals[3])==1: g.datawc_y2 = cdtime.reltime(gm.datawc_y2,g.datawc_timeunits).tocomp(g.datawc_calendar) irg=code.find("lines") if irg>-1: scode = code[irg:] label = 'n' tl=[] tt=[] to=[] clock = [] scales = [] angles =[] spacing = [] levs=[] while scode.find("id=")>-1: sub = genutil.get_parenthesis_content(code[irg:]) if get_att_from_sub(sub,"label") not in ["*",None]: g.label='y' levs.append(get_att_from_sub(sub,"level")) tl.append(get_att_from_sub(sub,"Tl")) to.append(get_att_from_sub(sub,"To")) tt.append(get_att_from_sub(sub,"Tt")) clock.append(get_att_from_sub(sub,"clockwise")) scales.append(get_att_from_sub(sub,"length")) angles.append(get_att_from_sub(sub,"angle")) spacing.append(get_att_from_sub(sub,"spacing")) scode = scode[scode.find(sub)+len(sub):] g.level = levs try: g.line = tl except:
def process_src(nm, code): # Takes VCS script code (string) as input and generates isoline gm from it try: g = Gi(nm) except: g = vcs.elements["isoline"][nm] # process attributes with = as assignement for att in ["projection", "xticlabels#1", "xticlabels#2", "xmtics#1", "xmtics#2", "yticlabels#1", "yticlabels#2", "ymtics#1", "ymtics#2", "xaxisconvert", "yaxisconvert", "datawc_tunits", "boxfill_type", "legend", "ext_1", "ext_2", "missing", "datawc_calendar", "make_labels"]: i = code.find(att) if i == -1: continue j = code[i:].find(",") + i if j - i == -1: # last one no comma j = None scode = code[i:j] sp = scode.split("=") nm = sp[0].strip() nm = nm.replace("#", "") if nm == "make_labels": nm = "label" elif nm == "datawc_tunits": nm = "datawc_timeunits" try: # int will be converted setattr(g, nm, int(sp[1])) except: try: # int and floats will be converted setattr(g, nm, eval(sp[1])) except: # strings try: setattr(g, nm, sp[1]) except: pass # oh well we stick to default value # Datawc idwc = code.find(" datawc(") if idwc > -1: jdwc = code[idwc:].find(")") + idwc cd = code[idwc + 8:jdwc] vals = cd.split(",") g.datawc_x1 = float(vals[0]) g.datawc_y1 = float(vals[1]) g.datawc_x2 = float(vals[2]) g.datawc_y2 = float(vals[3]) # idatawc idwc = code.find("idatawc(") if idwc > -1: jdwc = code[idwc:].find(")") + idwc cd = code[idwc + 8:jdwc] vals = cd.split(",") if int(vals[0]) == 1: g.datawc_x1 = cdtime.reltime( g.datawc_x1, g.datawc_timeunits).tocomp( g.datawc_calendar) if int(vals[1]) == 1: g.datawc_y1 = cdtime.reltime( g.datawc_x2, g.datawc_timeunits).tocomp( g.datawc_calendar) if int(vals[2]) == 1: g.datawc_x2 = cdtime.reltime( g.datawc_y1, g.datawc_timeunits).tocomp( g.datawc_calendar) if int(vals[3]) == 1: g.datawc_y2 = cdtime.reltime( g.datawc_y2, g.datawc_timeunits).tocomp( g.datawc_calendar) irg = code.find("lines") if irg > -1: scode = code[irg:] tl = [] tt = [] to = [] clock = [] scales = [] angles = [] spacing = [] levs = [] # print code[irg:] iid = scode.find("(id=") while iid > -1: sub = genutil.get_parenthesis_content(scode[iid:]) if get_att_from_sub(sub, "label") not in ["*", None]: g.label = 'y' levs.append(get_att_from_sub(sub, "level")) tl.append(get_att_from_sub(sub, "Tl")) to.append(get_att_from_sub(sub, "To")) tt.append(get_att_from_sub(sub, "Tt")) clock.append(get_att_from_sub(sub, "clockwise")) scales.append(get_att_from_sub(sub, "length")) angles.append(get_att_from_sub(sub, "angle")) spacing.append(get_att_from_sub(sub, "spacing")) iend = scode[iid:].find(")") + 1 scode = scode[iid + iend:] iid = scode.find("(id=") g.level = levs try: g.setLineAttributes(tl) except ValueError: pass try: g.text = to except: g._text = to try: g.textcolors = tt except: g._textcolors = tt gd = vcs.elements["isoline"]["default"] try: g.scale = scales except: g.scale = gd.scale try: g.angle = angles except: g.angle = gd.angle try: g.clockwise = clock except: g.clockwise = gd.clockwise