def _build_tree(self, scale_factor=1.0): stack = [] # build tree structure root = Tree() root.key = "root" root.sx = 1.0 / scale_factor root.sy = 1.0 / scale_factor for k, v in self.places.iteritems(): tree = Tree() tree.set_items(v.items()) tree.key = "-obj" + k + "-1-1" tree.parent = root root.children.append(tree) stack.append(tree) key_count = {} while len(stack) > 0: current = stack.pop() currentSprite = self._search_sprite(LUtil.objectID_from_key(current.key)) #currentSprite = self._search_sprite(current.key) if currentSprite is not None: f = currentSprite.frames[0] for p in f.places: for s in p['symbols']: if s in key_count.keys(): key_count[s] = key_count[s] + 1 else: key_count[s] = 1 tree = Tree() tree.set_items(p.items()) tree.key = s + "-" + str(key_count[s]) #tree.key = LUtil.objectID_from_key(s) tree.parent = current current.children.append(tree) stack.append(tree) self.tree = root
def _make_shape(self, tree, shape): shapes = [] if LUtil.objectID_from_key(tree.key) == shape.symbol: s = etree.Element("shape") s.set("key", tree.key) s.set("name", shape.name) s.set("x", str(shape.left)) s.set("y", str(shape.top)) s.set("width", str(shape.width)) s.set("height", str(shape.height)) shapes.append(s) for c in tree.children: c_shapes = self._make_shape(c, shape) shapes.extend(c_shapes) return shapes