def make_nice_style(r):
    ra = {}
    for a, b in r.iteritems():
        "checking and nicifying style table"
        if type(b) == TYPE_EVAL:
            ra[a] = b
        elif "color" in a:
            "parsing color value to 3-tuple"
            # print "res:", b
            if b and (type(b) != tuple):
                # if not b:
                #    print sl, ftype, tags, zoom, scale, zscale
                # else:
                ra[a] = colorparser(b)
            elif b:
                ra[a] = b
        elif any(x in a for x in ("width", "z-index", "opacity", "offset",
                                  "radius", "extrude")):
            "these things are float's or not in table at all"
            try:
                ra[a] = float(b)
            except ValueError:
                pass
        elif "dashes" in a and type(b) != list:
            "these things are arrays of float's or not in table at all"
            try:
                b = b.split(",")
                b = [float(x) for x in b]
                ra[a] = b
            except ValueError:
                ra[a] = []
        else:
            ra[a] = b
    return ra
Exemple #2
0
def make_nice_style(r):
    ra = {}
    for a, b in r.iteritems():
        "checking and nicifying style table"
        if type(b) == TYPE_EVAL:
            ra[a] = b
        elif "color" in a:
            "parsing color value to 3-tuple"
            # print "res:", b
            if b and (type(b) != tuple):
            # if not b:
            #    print sl, ftype, tags, zoom, scale, zscale
            # else:
                ra[a] = colorparser(b)
            elif b:
                ra[a] = b
        elif any(x in a for x in ("width", "z-index", "opacity", "offset", "radius", "extrude")):
            "these things are float's or not in table at all"
            try:
                ra[a] = float(b)
            except ValueError:
                pass
        elif "dashes" in a and type(b) != list:
            "these things are arrays of float's or not in table at all"
            try:
                b = b.split(",")
                b = [float(x) for x in b]
                ra[a] = b
            except ValueError:
                ra[a] = []
        else:
            ra[a] = b
    return ra
Exemple #3
0
 def updateStyles(self, sl, ftype, tags, zoom, scale, zscale):
     # Are any of the ruleChains fulfilled?
     if self.selzooms:
         if zoom < self.selzooms[0] or zoom > self.selzooms[1]:
             return sl
     object_id = self.testChain(self.ruleChains,ftype,tags,zoom)
     if not object_id:
         return sl
     w = 0
     for r in self.styles:
         ra = {}
         for a,b in r.iteritems():
             "calculating eval()'s"
             if type(b) == self.eval_type:
                 combined_style = {}
                 for t in sl:
                     combined_style.update(t)
                 for p,q in combined_style.iteritems():
                     if "color" in p:
                         combined_style[p] = cairo_to_hex(q)
                 b = b.compute(tags, combined_style, scale, zscale)
             ra[a] = b
         r = ra
         ra = {}
         for a, b in r.iteritems():
             "checking and nicifying style table"
             if "color" in a:
                 "parsing color value to 3-tuple"
                 #print "res:", b
                 if b:
                 #if not b:
                 #    print sl, ftype, tags, zoom, scale, zscale
                 #else:
                     ra[a] = colorparser(b)
             elif any(x in a for x in ("width", "z-index", "opacity", "offset", "radius", "extrude")):
                 "these things are float's or not in table at all"
                 try:
                     ra[a] = float(b)
                 except ValueError:
                     pass
             elif "dashes" in a:
                 "these things are arrays of float's or not in table at all"
                 try:
                     b = b.split(",")
                     b = [float(x) for x in b]
                     ra[a] = b
                 except ValueError:
                     ra[a] = []
             else:
                 ra[a]=b
         ra["layer"] = float(tags.get("layer",0))*2000+ra.get("z-index",1) # calculating z-index
         #for k,v in ra.items():  # if a value is empty, we don't need it - renderer will do as default.
         #    if not v:
         #        del ra[k]
         ra["object-id"] = str(object_id)
         hasall = False
         allinit = {}
         for x in sl:
             if x.get("object-id") == "::*":
                 allinit = x.copy()
             if ra["object-id"] == "::*":
                 oid = x.get("object-id")
                 x.update(ra)
                 x["object-id"] = oid
                 if oid == "::*":
                     hasall = True
             if x.get("object-id") == ra["object-id"]:
                 x.update(ra)
                 break
         else:
             if not hasall:
                 allinit.update(ra)
                 sl.append(allinit)
     return sl
Exemple #4
0
  def updateStyles(self,sl,type, tags, zoom, scale, zscale):
                  # Are any of the ruleChains fulfilled?
                  w = 0
                  for c in self.ruleChains:
                    if (self.testChain(c,type,tags,zoom)):
                      break
                  else:
                    return sl

                  ## Update StyleList
                  object_id = 1

                  for r in self.styles:
                    ra = {}
                    for a,b in r.iteritems():
                      "calculating eval()'s"
                      if __builtins__["type"](b) == self.eval_type:
                        combined_style = {}
                        for t in sl:
                          combined_style.update(t)
                        for p,q in combined_style.iteritems():
                          if "color" in p:
                            combined_style[p] = cairo_to_hex(q)
                        b = b.compute(tags,combined_style, scale, zscale)
                      ra[a] = b
                    r = ra
                    ra = {}
                    for a, b in r.iteritems():
                      "checking and nicifying style table"
                      if "color" in a:
                        "parsing color value to 3-tuple"
                        ra[a] = colorparser(b)
                      elif any(x in a for x in ("width", "z-index", "opacity", "offset", "radius", "extrude")):
                        "these things are float's or not in table at all"
                        try:
                          ra[a] = float(b)
                        except ValueError:
                          pass
                      elif "dashes" in a:
                        "these things are arrays of float's or not in table at all"
                        try:
                          b = b.split(",")
                          b = [float(x) for x in b]
                          ra[a]= b
                        except ValueError:
                          pass
                      else:
                        ra[a]=b
                    
                    ra["layer"] = float(tags.get("layer",0))*1000+ra.get("z-index",1) # calculating z-index
                    for k,v in ra.items():  # if a value is empty, we don't need it - renderer will do as default.
                      if not v:
                        del ra[k]
                    if "object-id" not in ra:
                      ra["object-id"] = str(object_id)
                    for x in sl:
                      if x.get("object-id","1") == ra["object-id"]:
                        x.update(ra)
                        break
                    else:
                      sl.append(ra)
                    object_id += 1
                  return sl