Ejemplo n.º 1
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     self.load_xml_elements(elm)
     if not self.closed:
         elm.attrib["closed"] = "0"
     point_indices_elm = XmlElement("pi")
     point_indices_elm.text = ",".join(str(p) for p in self.point_indices)
     elm.append(point_indices_elm)
     return elm
Ejemplo n.º 2
0
 def add_linked_clone_elements(self, multi_shape, root):
     for shape in multi_shape.shapes:
         if shape.linked_clones:
             linked = XmlElement("linked")
             linked.attrib["source"] = ".".join(get_hierarchy_names(shape))
             for linked_clone_shape in shape.linked_clones:
                 linked_clone = XmlElement("dest")
                 linked_clone.text = ".".join(
                     get_hierarchy_names(linked_clone_shape))
                 linked.append(linked_clone)
             root.append(linked)
         if isinstance(shape, MultiShape):
             self.add_linked_clone_elements(shape, root)
Ejemplo n.º 3
0
    def save(self, filename=None):
        result = False
        root = XmlElement("root")

        app = XmlElement("app")
        app.attrib["name"] = "{0}".format(Settings.APP_NAME)
        app.attrib["version"] = "{0}".format(Settings.APP_VERSION)
        root.append(app)

        doc = XmlElement("doc")
        doc.attrib["width"] = "{0}".format(self.width)
        doc.attrib["height"] = "{0}".format(self.height)
        if not self.fixed_border:
            doc.attrib["fixed_border"] = "False"
        root.append(doc)

        for guide in self.guides:
            root.append(guide.get_xml_element())

        tree = XmlTree(root)
        root.append(self.main_multi_shape.get_xml_element())
        self.add_linked_clone_elements(self.main_multi_shape, root)

        backup_file = None
        if filename is None:
            filename = self.filename

        if filename is not None:
            self.filename = filename
            if os.path.isfile(filename):
                backup_file = filename + ".bk"
                os.rename(filename, backup_file)

        #tree.write(self.filename)
        try:
            tree.write(self.filename, encoding="utf-8", xml_declaration=True)
            result = True
        except TypeError as e:
            print("{0}".format(e))
        except UnicodeDecodeError as e:
            print("{0}".format(e))

        if not result:
            if backup_file:
                os.rename(backup_file, filename)
                backup_file = None
                sys.exit("Unable to save file")

        if backup_file:
            os.remove(backup_file)
        return True
Ejemplo n.º 4
0
    def get_xml_element(self):
        elm = XmlElement(self.TAG_NAME)
        self.load_xml_elements(elm)

        point_values = []
        for point in self.points:
            point_values.append(point.to_text())
        points_elm = XmlElement("points")
        points_elm.text = ",".join(point_values)
        elm.append(points_elm)

        for polygon in self.polygons:
            elm.append(polygon.get_xml_element())
        return elm
Ejemplo n.º 5
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["text"] = self.text
     elm.attrib["at"] = "{0}".format(self.at)
     if not self.fixed:
         elm.attrib["fixed"] = "0"
     return elm
Ejemplo n.º 6
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["origin"] = self.origin.to_text()
     elm.attrib["closed"] = "{0}".format(self.closed)
     for bezier_point in self.bezier_points:
         elm.append(bezier_point.get_xml_element())
     return elm
Ejemplo n.º 7
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["ci"] = "{0}".format(self.curve_index)
     elm.attrib["pi"] = "{0}".format(self.point_index)
     elm.attrib["pt"] = "{0}".format(self.point_type)
     elm.attrib["ps"] = self.position.to_text()
     return elm
Ejemplo n.º 8
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["type"] = self.TYPE_NAME
     elm.attrib["name"] = self.get_name()
     if not self.visible:
         elm.attrib["visible"] = "0"
     elm.attrib["mimic_like"] = u"{0}".format(self.mimic_like)
     return elm
Ejemplo n.º 9
0
 def get_xml_elements(self):
     elms = []
     for i in range(len(self.names)):
         elm = XmlElement(self.TAG_NAME)
         elm.attrib["name"] = self.names[i]
         elm.attrib["path"] = self.paths[i]
         elms.append(elm)
     return elms
Ejemplo n.º 10
0
 def get_xml_element(self):
     form_elm = XmlElement(self.TAG_NAME)
     if self.name:
         form_elm.attrib["name"] = self.name
     form_elm.attrib["width"] = "{0}".format(self.width)
     form_elm.attrib["height"] = "{0}".format(self.height)
     for polygon in self.polygons:
         form_elm.append(polygon.get_xml_element())
     return form_elm
Ejemplo n.º 11
0
 def get_xml_element(self, exclude_border_fill=False):
     elm = XmlElement(self.TAG_NAME)
     self.load_xml_elements(elm, exclude_border_fill=exclude_border_fill)
     for i in range(len(self.items)):
         item = self.items[i]
         item_elm = item.get_xml_element()
         item_elm.attrib["name"] = self.item_names[i]
         elm.append(item_elm)
     return elm
Ejemplo n.º 12
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib[self.START_VALUE_NAME] = "{0}".format(self.start_value)
     elm.attrib[self.END_VALUE_NAME] = "{0}".format(self.end_value)
     elm.attrib[self.DURATION_NAME] = "{0}".format(self.duration)
     elm.attrib[self.LINKED_TO_NEXT_NAME] = u"{0}".format(
         self.linked_to_next)
     if type(self.change_type) is not TimeChangeType:
         elm.append(self.change_type.get_xml_element())
     if self.prop_data:
         for key, value in self.prop_data.items():
             #if value is None: continue
             prop_data_elm = XmlElement(self.PROP_DATA_TAG_NAME)
             prop_data_elm.attrib["key"] = "{0}".format(key)
             prop_data_elm.attrib["value"] = u"{0}".format(value)
             prop_data_elm.attrib["type"] = value.__class__.__name__
             elm.append(prop_data_elm)
     if self.end_marker:
         elm.attrib["end_marker"] = u"{0}".format(self.end_marker)
     return elm
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["name"] = self.name
     for shape_time_line in self.shape_time_lines:
         shape_time_elm = shape_time_line.get_xml_element()
         if shape_time_line.shape == self.multi_shape:
             del shape_time_elm.attrib[ShapeTimeLine.SHAPE_NAME]
         elm.append(shape_time_elm)
     for time_marker in self.time_markers.values():
         elm.append(time_marker.get_xml_element())
     return elm
Ejemplo n.º 14
0
 def get_xml_element(self):
     form_elm = XmlElement(self.TAG_NAME)
     if self.name:
         form_elm.attrib["name"] = self.name
     form_elm.attrib["width"] = "{0}".format(self.width)
     form_elm.attrib["height"] = "{0}".format(self.height)
     for curve in self.curves:
         form_elm.append(curve.get_xml_element())
     if self.shapes_props:
         for shape_name, prop_dict in self.shapes_props.items():
             pose_shape_elm = Shape.get_pose_prop_xml_element(
                 shape_name, prop_dict)
             form_elm.append(pose_shape_elm)
     return form_elm
Ejemplo n.º 15
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["y"] = "{0}".format(self.y)
     elm.attrib["type"] = self.TYPE_NAME
     elm.attrib["name"] = "{0}".format(self.get_name())
     elm.attrib["loop"] = "{0}".format(self.loop)
     elm.attrib["duration"] = self.duration_time.to_text()
     elm.attrib["start"] = self.start_time.to_text()
     elm.attrib["auto_fit"] = "{0}".format(int(self.auto_fit_duration))
     elm.attrib["note"] = "{0}".format(self.music_note)
     if self.midi_channel is not None:
         elm.attrib["mchannel"] = "{0}".format(self.midi_channel)
         elm.attrib["mvelocity"] = "{0}".format(self.midi_velocity)
     if self.instru:
         elm.attrib["instru"] = self.instru.get_name()
     return elm
Ejemplo n.º 16
0
    def get_xml_element(self):
        elm = super(AudioFormulaInstru, self).get_xml_element()
        if self.formulator_path:
            elm.attrib["formulator_path"] = self.formulator_path
            for param_data in self.get_param_list():
                param_name = param_data[0]
                param_value = "{0}".format(self.get_param(param_name))

                param_elm = XmlElement(self.PARAM_TAG_NAME)
                param_elm.attrib["name"] = param_name
                param_elm.attrib["value"] = param_value
                elm.append(param_elm)
        else:
            elm.attrib["formulator"] = self.formulator.DISPLAY_NAME
        elm.attrib["autogen"] = "{0}".format(int(self.autogen_other_notes))
        elm.attrib["base_note"] = self.base_note.name
        return elm
Ejemplo n.º 17
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     for point in self.points.values():
         elm.append(point.get_xml_element())
     return elm
Ejemplo n.º 18
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["c1"] = self.control_1.to_text()
     elm.attrib["c2"] = self.control_2.to_text()
     elm.attrib["d"] = self.dest.to_text()
     return elm
Ejemplo n.º 19
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["type"] = self.TYPE_NAME
     return elm
Ejemplo n.º 20
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["p"] = self.to_text()
     return elm
Ejemplo n.º 21
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["type"] = self.TYPE_NAME
     elm.attrib["y"] = "{0}".format(self.y)
     return elm
Ejemplo n.º 22
0
 def get_xml_element(self, ):
     elm = XmlElement(self.TAG_NAME)
     return elm
Ejemplo n.º 23
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib[self.SHAPE_NAME] = self.shape.get_name()
     for prop_time_line in self.prop_time_lines:
         elm.append(prop_time_line.get_xml_element())
     return elm
Ejemplo n.º 24
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib[self.PROP_NAME] = self.prop_name
     for time_slice in self.time_slices:
         elm.append(time_slice.get_xml_element())
     return elm
Ejemplo n.º 25
0
 def get_xml_element(self):
     elm = XmlElement(self.TAG_NAME)
     elm.attrib["closed"] = "{0}".format(self.closed)
     for point in self.points:
         elm.append(point.get_xml_element())
     return elm