def from_element(self, element): self.gradient = Palette.from_flame_element(element) for xform in element.findall('xform'): self.xform.append(Xform.from_element(self, xform)) self.final = None for final in element.findall('finalxform'): if self.final is not None: raise ParsingError("More than one final xform found") self.final = Xform.from_element(self, final) # Record the header data. This is done after loading xforms so the # soloxform fiasco can be safely defused. for name, val in element.items(): # Convert value to the appropriate type try: if " " in val: val = tuple(float(i) for i in val.split()) else: val = float(val) except ValueError: pass # Keep as string setattr(self,name,val) self.name = str(self.name) if hasattr(self, 'name') else None # Scale needs to be converted. This is reversed in to_string. self.scale = self.scale * 100 / self.size[0] sym = element.find('symmetry') if sym is not None: self.add_symmetry(int(sym.get('kind'))) if self.version != VERSION: compatibilize(self, VERSION) return self
def from_element(self, element): self.gradient.from_flame_element(element) xml_xforms = element.findall('xform') self.xform = [Xform(self) for i in xml_xforms] for xform, xform_element in zip(self.xform, xml_xforms): xform.from_element(xform_element) for final in element.findall('finalxform'): if self.final is not None: raise ParsingError("More than one final xform found") self.final = Xform(self) self.final.from_element(final) self.final.animate = 0 # Record the header data. for name, val in element.items(): try: if " " in val: setattr(self, name, map(float, val.split())) else: setattr(self, name, float(val)) except ValueError: setattr(self, name, val) self.name = str(self.name) # Scale needs to be converted. This is reversed in _iter_attributes. self.scale = self.scale * 100 / self.size[0] sym = element.find('symmetry') if sym is not None: self.add_symmetry(int(sym.get('kind'))) compatibilize(self, VERSION) return self