Пример #1
0
def prettyPrintXMLElement(rootElement):
    """Takes an ElementTree.Element and returns a pretty printed UTF-8 XML file as string
    based on it. This functions adds newlines and indents and adds the XML declaration
    on top, which would be otherwise missing.

    Returns a string containing the pretty printed XML file.
    """
    xmledit.indent(rootElement)
    
    tempFile = BytesIO()
    elementTree = ElementTree.ElementTree(rootElement)
    elementTree.write(tempFile, encoding='utf-8', xml_declaration=True) 
    return tempFile.getvalue()
Пример #2
0
def prettyPrintXMLElement(rootElement):
    """Takes an ElementTree.Element and returns a pretty printed UTF-8 XML file as string
    based on it. This functions adds newlines and indents and adds the XML declaration
    on top, which would be otherwise missing.

    Returns a string containing the pretty printed XML file.
    """
    xmledit.indent(rootElement)

    tempFile = BytesIO()
    elementTree = ElementTree.ElementTree(rootElement)
    elementTree.write(tempFile, encoding='utf-8', xml_declaration=True)
    return tempFile.getvalue()
Пример #3
0
    def saveAs(self, targetPath, updateCurrentPath = True):
        codeMode = self.currentWidget() is self.code

        # if user saved in code mode, we process the code by propagating it to visual
        # (allowing the change propagation to do the code validating and other work for us)

        if codeMode:
            self.code.propagateToVisual()

        rootElement = self.visual.imagesetEntry.saveToElement()
        # we indent to make the resulting files as readable as possible
        xmledit.indent(rootElement)

        self.nativeData = ElementTree.tostring(rootElement, "utf-8")

        return super(ImagesetTabbedEditor, self).saveAs(targetPath, updateCurrentPath)
Пример #4
0
    def saveAs(self, targetPath, updateCurrentPath=True):
        codeMode = self.currentWidget() is self.code

        # if user saved in code mode, we process the code by propagating it to visual
        # (allowing the change propagation to do the code validating and other work for us)

        if codeMode:
            self.code.propagateToVisual()

        rootElement = self.visual.imagesetEntry.saveToElement()
        # we indent to make the resulting files as readable as possible
        xmledit.indent(rootElement)

        self.nativeData = ElementTree.tostring(rootElement, "utf-8")

        return super(ImagesetTabbedEditor,
                     self).saveAs(targetPath, updateCurrentPath)
Пример #5
0
    def save(self, path = ""):
        if path == "":
            # "save" vs "save as"
            path = self.projectFilePath
            self.changed = False

        root = ElementTree.Element("Project")

        root.set("version", project_compatibility.manager.EditorNativeType)

        root.set("baseDirectory", convertToPortablePath(self.baseDirectory))

        root.set("CEGUIVersion", self.CEGUIVersion)
        root.set("CEGUIDefaultResolution", self.CEGUIDefaultResolution)

        root.set("imagesetsPath", convertToPortablePath(self.imagesetsPath))
        root.set("fontsPath", convertToPortablePath(self.fontsPath))
        root.set("looknfeelsPath", convertToPortablePath(self.looknfeelsPath))
        root.set("schemesPath", convertToPortablePath(self.schemesPath))
        root.set("layoutsPath", convertToPortablePath(self.layoutsPath))
        root.set("xmlSchemasPath", convertToPortablePath(self.xmlSchemasPath))

        items = ElementTree.SubElement(root, "Items")

        i = 0
        while i < self.rowCount():
            items.append(self.item(i).saveToElement())
            i = i + 1

        xmledit.indent(root)

        nativeData = ElementTree.tostring(root, encoding = "utf-8")
        outputFile = open(path, "w")
        outputFile.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
        outputFile.write(nativeData)
        outputFile.close()
Пример #6
0
    def getNativeCode(self):
        element = self.tabbedEditor.visual.imagesetEntry.saveToElement()
        xmledit.indent(element)

        return ElementTree.tostring(element, "utf-8")
Пример #7
0
    def generateNativeData(self):
        element = self.saveToElement()
        xmledit.indent(element)

        return ElementTree.tostring(element, "utf-8")
Пример #8
0
    def generateNativeData(self):
        element = self.saveToElement()
        xmledit.indent(element)

        return ElementTree.tostring(element, "utf-8")