コード例 #1
0
ファイル: StyleChooser.py プロジェクト: rokuz/kothic
    def updateStyles(self, sl, ftype, tags, zoom, xscale, zscale, filter_by_runtime_conditions):
        # Are any of the ruleChains fulfilled?
        if self.selzooms:
            if zoom < self.selzooms[0] or zoom > self.selzooms[1]:
                return sl

        #if ftype not in self.compatible_types:
            #return sl

        rule_and_object_id = self.testChain(self.ruleChains, ftype, tags, zoom)

        if not rule_and_object_id:
            return sl

        rule = rule_and_object_id[0]
        object_id = rule_and_object_id[1]

        if not self.isCorrespondingRule(filter_by_runtime_conditions, rule):
            return sl

        for r in self.styles:
            if self.has_evals:
                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, xscale, zscale)
                    ra[a] = b
                ra = make_nice_style(ra)
            else:
                ra = r.copy()

            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
                else:
                    if x.get("object-id") == ra["object-id"]:
                        x.update(ra)
                        break
            else:
                if not hasall:
                    allinit.update(ra)
                    sl.append(allinit)

        return sl
コード例 #2
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

        #if ftype not in self.compatible_types:
#            return sl

        object_id = self.testChain(self.ruleChains, ftype, tags, zoom)

        if not object_id:
            return sl

        w = 0

        for r in self.styles:
            if self.has_evals:
                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 = make_nice_style(ra)
            else:
                ra = r.copy()

            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
コード例 #3
0
ファイル: StyleChooser.py プロジェクト: progserega/kothic
 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
コード例 #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