Exemplo n.º 1
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        del root.attrib["version"]

        for attr in [
            "name",
            "filename",
            "resourceGroup",
            "type",
            "size",
            "nativeHorzRes",
            "nativeVertRes",
            "autoScaled",
            "antiAlias",
            "lineScaling",
        ]:
            self.transformAttribute(root, attr)

        if root.get("AutoScaled") is not None:
            root.set(
                "AutoScaled", imageset_cegui_compat.CEGUI2ToCEGUI1Layer.autoScaledToBoolean(root.get("AutoScaled"))
            )

        for mapping in root.findall("Mapping"):
            for attr in ["codepoint", "image", "horzAdvance"]:
                self.transformAttribute(mapping, attr)

        return ceguihelpers.prettyPrintXMLElement(root)
Exemplo n.º 2
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        del root.attrib["version"] # imageset version 1 has no version attribute!

        root.set("Imagefile", root.get("imagefile", ""))
        del root.attrib["imagefile"]

        if root.get("resourceGroup") is not None:
            root.set("ResourceGroup", root.get("resourceGroup", ""))
            del root.attrib["resourceGroup"]

        root.set("Name", root.get("name", ""))
        del root.attrib["name"]

        if root.get("nativeHorzRes") is not None:
            root.set("NativeHorzRes", root.get("nativeHorzRes", "640"))
            del root.attrib["nativeHorzRes"]

        if root.get("nativeVertRes") is not None:
            root.set("NativeVertRes", root.get("nativeVertRes", "480"))
            del root.attrib["nativeVertRes"]

        if root.get("autoScaled") is not None:
            root.set("AutoScaled", CEGUI2ToCEGUI1Layer.autoScaledToBoolean(root.get("autoScaled", "false")))
            del root.attrib["autoScaled"]

        for image in root.findall("Image"):
            image.set("Name", image.get("name", ""))
            del image.attrib["name"]

            if image.get("type", "BasicImage") != "BasicImage":
                raise NotImplementedError("Can't convert non-BasicImage in imageset version 2 (CEGUI 0.8+) to older version, such stuff wasn't supported in imagesets version 1 (everything up to CEGUI 0.7)")

            # TODO: We only deal with basic image here
            if image.get("Type", "BasicImage") == "BasicImage":
                if image.get("xPos") is not None:
                    image.set("XPos", image.get("xPos", "0"))
                    del image.attrib["xPos"]

                if image.get("yPos") is not None:
                    image.set("YPos", image.get("yPos", "0"))
                    del image.attrib["yPos"]

                if image.get("width") is not None:
                    image.set("Width", image.get("width", "1"))
                    del image.attrib["width"]

                if image.get("height") is not None:
                    image.set("Height", image.get("height", "1"))
                    del image.attrib["height"]

                if image.get("xOffset") is not None:
                    image.set("XOffset", image.get("xOffset", "0"))
                    del image.attrib["XOffset"]

                if image.get("yOffset") is not None:
                    image.set("YOffset", image.get("yOffset", "0"))
                    del image.attrib["YOffset"]

        return ceguihelpers.prettyPrintXMLElement(root);
Exemplo n.º 3
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        del root.attrib["version"]

        self.transformAttribute(root, "name")

        for imageset in root.findall("Imageset"):
            self.transformNamedType(imageset)
        for imagesetFromFile in root.findall("ImagesetFromFile"):
            self.transformNamedType(imagesetFromFile)
        for font in root.findall("Font"):
            self.transformNamedType(font)
        for looknfeel in root.findall("LookNFeel"):
            self.transformNamedType(looknfeel)

        for windowSet in root.findall("WindowSet"):
            self.transformAttribute(windowSet, "filename")

            for windowFactory in windowSet.findall("WindowFactory"):
                self.transformAttribute(windowFactory, "name")

        for windowRendererSet in root.findall("WindowRendererSet"):
            self.transformAttribute(windowRendererSet, "filename")

            # this particular window renderer set got renamed
            if windowRendererSet.get("Filename",
                                     "") == "CEGUICoreWindowRendererSet":
                windowRendererSet.set("Filename", "CEGUIFalagardWRBase")

            for windowRendererFactory in windowRendererSet.findall(
                    "WindowRendererFactory"):
                self.transformAttribute(windowRendererFactory, "name")

        for windowAlias in root.findall("WindowAlias"):
            self.transformAttribute(windowAlias, "alias")
            self.transformAttribute(windowAlias, "target")

            if windowAlias.get("Target", "") == "CEGUI/ToggleButton":
                windowAlias.set("Target", "CEGUI/Checkbox")

        for falagardMapping in root.findall("FalagardMapping"):
            for attr in [
                    "windowType", "targetType", "renderer", "lookNFeel",
                    "renderEffect"
            ]:
                self.transformAttribute(falagardMapping, attr)

            if falagardMapping.get("TargetType", "") == "CEGUI/ToggleButton":
                falagardMapping.set("TargetType", "CEGUI/Checkbox")

            if falagardMapping.get("Renderer") is not None:
                rendererValue = falagardMapping.get("Renderer")
                if rendererValue.startswith("Core/"):
                    falagardMapping.set("Renderer",
                                        "Falagard/%s" % (rendererValue[5:]))

        return ceguihelpers.prettyPrintXMLElement(root)
Exemplo n.º 4
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        root.set("version", "2")

        root.set("imagefile", root.get("Imagefile", ""))
        del root.attrib["Imagefile"]

        if root.get("ResourceGroup") is not None:
            root.set("resourceGroup", root.get("ResourceGroup", ""))
            del root.attrib["ResourceGroup"]

        root.set("name", root.get("Name", ""))
        del root.attrib["Name"]

        if root.get("NativeHorzRes") is not None:
            root.set("nativeHorzRes", root.get("NativeHorzRes", "640"))
            del root.attrib["NativeHorzRes"]

        if root.get("NativeVertRes") is not None:
            root.set("nativeVertRes", root.get("NativeVertRes", "480"))
            del root.attrib["NativeVertRes"]

        if root.get("AutoScaled") is not None:
            root.set("autoScaled", root.get("AutoScaled", "false"))
            del root.attrib["AutoScaled"]

        for image in root.findall("Image"):
            image.set("name", image.get("Name", ""))
            del image.attrib["Name"]

            # TODO: We only deal with basic image here
            if image.get("type", "BasicImage") == "BasicImage":
                if image.get("XPos") is not None:
                    image.set("xPos", image.get("XPos", "0"))
                    del image.attrib["XPos"]

                if image.get("YPos") is not None:
                    image.set("yPos", image.get("YPos", "0"))
                    del image.attrib["YPos"]

                if image.get("Width") is not None:
                    image.set("width", image.get("Width", "1"))
                    del image.attrib["Width"]

                if image.get("Height") is not None:
                    image.set("height", image.get("Height", "1"))
                    del image.attrib["Height"]

                if image.get("XOffset") is not None:
                    image.set("xOffset", image.get("XOffset", "0"))
                    del image.attrib["xOffset"]

                if image.get("YOffset") is not None:
                    image.set("yOffset", image.get("YOffset", "0"))
                    del image.attrib["yOffset"]

        return ceguihelpers.prettyPrintXMLElement(root);
Exemplo n.º 5
0
    def transform(self, data):
        fontElement = ElementTree.fromstring(data)
        del fontElement.attrib["version"]

        root = ElementTree.Element("Fonts")
        root.set("version", "4")
        root.append(fontElement)

        return ceguihelpers.prettyPrintXMLElement(root)
Exemplo n.º 6
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        root.set("version", "5")

        self.transformAttribute(root, "name")

        for imageset in root.findall("Imageset"):
            self.transformNamedType(imageset)
        for imagesetFromFile in root.findall("ImagesetFromFile"):
            self.transformNamedType(imagesetFromFile)
        for font in root.findall("Font"):
            self.transformNamedType(font)
        for looknfeel in root.findall("LookNFeel"):
            self.transformNamedType(looknfeel)

        for windowSet in root.findall("WindowSet"):
            self.transformAttribute(windowSet, "filename")

            for windowFactory in windowSet.findall("WindowFactory"):
                self.transformAttribute(windowFactory, "name")

        for windowRendererSet in root.findall("WindowRendererSet"):
            self.transformAttribute(windowRendererSet, "filename")

            # this particular window renderer set got renamed
            if windowRendererSet.get("filename", "") == "CEGUIFalagardWRBase":
                windowRendererSet.set("filename", "CEGUICoreWindowRendererSet")

            for windowRendererFactory in windowRendererSet.findall("WindowRendererFactory"):
                self.transformAttribute(windowRendererFactory, "name")

        for windowAlias in root.findall("WindowAlias"):
            self.transformAttribute(windowAlias, "alias")
            self.transformAttribute(windowAlias, "target")

            if windowAlias.get("target", "") == "CEGUI/Checkbox":
                windowAlias.set("target", "CEGUI/ToggleButton")

        for falagardMapping in root.findall("FalagardMapping"):
            for attr in ["windowType", "targetType", "renderer", "lookNFeel", "renderEffect"]:
                self.transformAttribute(falagardMapping, attr)

            if falagardMapping.get("targetType", "") == "CEGUI/Checkbox":
                falagardMapping.set("targetType", "CEGUI/ToggleButton")

            if falagardMapping.get("renderer") is not None:
                rendererValue = falagardMapping.get("renderer")
                # system button got removed in CEGUI 0.8
                # no need for reverse action in the backwards layer
                if rendererValue == "Falagard/SystemButton":
                    rendererValue = "Falagard/Button"

                if rendererValue.startswith("Falagard/"):
                    falagardMapping.set("renderer", "Core/%s" % (rendererValue[9:]))

        return ceguihelpers.prettyPrintXMLElement(root)
Exemplo n.º 7
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        root.set("version", "3")

        for attr in [
                "name", "filename", "resourceGroup", "type", "size",
                "nativeHorzRes", "nativeVertRes", "autoScaled", "antiAlias",
                "lineScaling"
        ]:
            self.transformAttribute(root, attr)

        for mapping in root.findall("Mapping"):
            for attr in ["codepoint", "image", "horzAdvance"]:
                self.transformAttribute(mapping, attr)

        return ceguihelpers.prettyPrintXMLElement(root)
Exemplo n.º 8
0
    def transform(self, data):
        log = ""

        root = ElementTree.fromstring(data.encode("utf-8"))

        # version 3 must not have a version attribute
        del root.attrib["version"]

        for window in root.findall("Window"):
            # should be only one window

            # first make the names relative to parent
            log += self.convertToAbsoluteNames(window)

            # apply other changes
            log += self.applyChangesRecursively(window)

        return unicode(ceguihelpers.prettyPrintXMLElement(root), encoding = "utf-8")
Exemplo n.º 9
0
    def transform(self, data):
        root = ElementTree.fromstring(data)

        # version 6 must not have a version attribute
        del root.attrib["version"]

        # New image addressing: Imageset/Image
        def convertImageElementToImagesetImage(element):
            name = element.get("name")
            split = name.split("/", 1)
            assert(len(split) == 2)

            del element.attrib["name"]
            element.set("imageset", split[0])
            element.set("image", split[1])

        for element in root.iter("Image"):
            convertImageElementToImagesetImage(element)

            componentAttr = element.get("component")
            if componentAttr is not None:
                element.set("type", componentAttr)
                del element.attrib["component"]

        # TODO: Convert OperatorDims to DimOperators

        for element in root.iter("ImageDim"):
            convertImageElementToImagesetImage(element)

        # Carat was rightfully renamed to Caret
        for element in root.iter("ImagerySection"):
            if element.get("name") == "Caret":
                # TODO: We should check that parent is Editbox or MultilineEditbox, however that would be very complicated with all the mappings
                element.set("name", "Carat")

        # transform properties
        for element in root.iter("WidgetLook"):
            compatibility_layout.cegui.Layout4To3Layer.transformPropertiesOf(element, nameAttribute = "name", valueAttribute = "value", windowType = element.get("name"))

            for childElement in element.iter("Child"):
                compatibility_layout.cegui.Layout4To3Layer.transformPropertiesOf(childElement, nameAttribute = "name", valueAttribute = "value", windowType = childElement.get("type"))

        return ceguihelpers.prettyPrintXMLElement(root)
Exemplo n.º 10
0
    def transform(self, data):
        log = ""

        root = ElementTree.fromstring(data.encode("utf-8"))

        # version 3 must not have a version attribute
        del root.attrib["version"]

        for window in root.findall("Window"):
            # should be only one window

            # first make the names relative to parent
            log += self.convertToAbsoluteNames(window)

            # apply other changes
            log += self.applyChangesRecursively(window)

        return unicode(ceguihelpers.prettyPrintXMLElement(root),
                       encoding="utf-8")
Exemplo n.º 11
0
    def transform(self, data):
        log = ""

        root = ElementTree.fromstring(data.encode("utf-8"))

        # version 4 has a version attribute
        root.set("version", "4")

        # no parent attribute in layout version 4 (CEGUI 0.8+)
        if root.get("Parent") is not None:
            del root.attrib["Parent"]

        for window in root.findall("Window"):
            # should be only one window

            # first make the names relative to parent
            log += self.convertToRelativeNames(window)

            # apply other changes
            log += self.applyChangesRecursively(window)

        return unicode(ceguihelpers.prettyPrintXMLElement(root), encoding = "utf-8")
Exemplo n.º 12
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        del root.attrib["version"]

        for attr in [
                "name", "filename", "resourceGroup", "type", "size",
                "nativeHorzRes", "nativeVertRes", "autoScaled", "antiAlias",
                "lineScaling"
        ]:
            self.transformAttribute(root, attr)

        if root.get("AutoScaled") is not None:
            root.set(
                "AutoScaled",
                imageset_cegui_compat.CEGUI2ToCEGUI1Layer.autoScaledToBoolean(
                    root.get("AutoScaled")))

        for mapping in root.findall("Mapping"):
            for attr in ["codepoint", "image", "horzAdvance"]:
                self.transformAttribute(mapping, attr)

        return ceguihelpers.prettyPrintXMLElement(root)
Exemplo n.º 13
0
    def transform(self, data):
        log = ""

        root = ElementTree.fromstring(data.encode("utf-8"))

        # version 4 has a version attribute
        root.set("version", "4")

        # no parent attribute in layout version 4 (CEGUI 0.8+)
        if root.get("Parent") is not None:
            del root.attrib["Parent"]

        for window in root.findall("Window"):
            # should be only one window

            # first make the names relative to parent
            log += self.convertToRelativeNames(window)

            # apply other changes
            log += self.applyChangesRecursively(window)

        return unicode(ceguihelpers.prettyPrintXMLElement(root),
                       encoding="utf-8")
Exemplo n.º 14
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        root.set("version", "3")

        for attr in [
            "name",
            "filename",
            "resourceGroup",
            "type",
            "size",
            "nativeHorzRes",
            "nativeVertRes",
            "autoScaled",
            "antiAlias",
            "lineScaling",
        ]:
            self.transformAttribute(root, attr)

        for mapping in root.findall("Mapping"):
            for attr in ["codepoint", "image", "horzAdvance"]:
                self.transformAttribute(mapping, attr)

        return ceguihelpers.prettyPrintXMLElement(root)
Exemplo n.º 15
0
    def transform(self, data):
        root = ElementTree.fromstring(data)
        # Fix for Python < 2.7.
        if not hasattr(root, "iter"):
            root.iter = root.getiterator

        # version 7 has a version attribute
        root.set("version", "7")

        # New image addressing: Imageset/Image
        def convertImageElementToName(element):
            imageset = element.get("imageset")
            image = element.get("image")

            assert(imageset is not None and image is not None)

            del element.attrib["imageset"]
            del element.attrib["image"]

            element.set("name", "%s/%s" % (imageset, image))

        for element in root.iter("Image"):
            convertImageElementToName(element)

            typeAttr = element.get("type")
            if typeAttr is not None:
                element.set("component", typeAttr)
                del element.attrib["type"]

        for element in root.iter("ImageDim"):
            convertImageElementToName(element)

        parentMap = dict((c, p) for p in root.iter() for c in p)

        # Lets convert DimOperators to OperatorDims
        dimopIter = root.iter("DimOperator")
        while True:
            try:
                dimop = dimopIter.next()

            except StopIteration:
                break

            try:
                tailTree = parentMap[dimop]

            except KeyError:
                raise RuntimeError("Failed to find parent of '%s'. This is most "
                                   "likely caused by invalid data, please validate "
                                   "them using XSD to check.\n"
                                   "In case they are valid, this is a bug in the "
                                   "compatibility layer, please report it!", dimop)

            tailTreeCopy = copy.deepcopy(tailTree)

            newTree = LookNFeel6To7Layer.convertToOperatorDim(tailTreeCopy)

            # a trick that replaces tailTree with newTree "in place"
            tailTree.clear()
            tailTree.text = None #newTree.text
            tailTree.tail = newTree.tail
            tailTree.tag = newTree.tag
            tailTree.attrib = newTree.attrib
            tailTree[:] = newTree[:]
            # end of trick

            dimopIter = root.iter("DimOperator")

        # Carat was rightfully renamed to Caret
        for element in root.iter("ImagerySection"):
            if element.get("name") == "Carat":
                # TODO: We should check that parent is Editbox or MultilineEditbox, however that would be very complicated with all the mappings
                element.set("name", "Caret")

        # transform properties
        for element in root.iter("WidgetLook"):
            compatibility_layout.cegui.Layout3To4Layer.transformPropertiesOf(element, nameAttribute = "name", valueAttribute = "value", windowType = element.get("name"))

            for childElement in element.iter("Child"):
                compatibility_layout.cegui.Layout3To4Layer.transformPropertiesOf(childElement, nameAttribute = "name", valueAttribute = "value", windowType = childElement.get("type"))

        return ceguihelpers.prettyPrintXMLElement(root)