E5XML/HighlightingStylesWriter.py

Sat, 13 Oct 2012 13:09:38 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 13 Oct 2012 13:09:38 +0200
branch
5_2_x
changeset 2135
0d6de739a82b
parent 1509
c0b5e693b0eb
child 2302
f29e9405c851
permissions
-rw-r--r--

Prepared new release 5.2.6.

# -*- coding: utf-8 -*-

# Copyright (c) 2008 - 2012 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the writer class for writing a highlighting styles XML file.
"""

import time

from .XMLStreamWriterBase import XMLStreamWriterBase
from .Config import highlightingStylesFileFormatVersion

import Preferences


class HighlightingStylesWriter(XMLStreamWriterBase):
    """
    Class implementing the writer class for writing a highlighting styles XML file.
    """
    def __init__(self, device, lexers):
        """
        Constructor
        
        @param device reference to the I/O device to write to (QIODevice)
        @param lexers list of lexer objects for which to export the styles
        """
        XMLStreamWriterBase.__init__(self, device)
        
        self.lexers = lexers
        self.email = Preferences.getUser("Email")
    
    def writeXML(self):
        """
        Public method to write the XML to the file.
        """
        XMLStreamWriterBase.writeXML(self)
        
        self.writeDTD('<!DOCTYPE HighlightingStyles SYSTEM "HighlightingStyles-{0}.dtd">'\
            .format(highlightingStylesFileFormatVersion))
        
        # add some generation comments
        self.writeComment(" Eric5 highlighting styles ")
        self.writeComment(" Saved: {0}".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
        self.writeComment(" Author: {0} ".format(self.email))
        
        # add the main tag
        self.writeStartElement("HighlightingStyles")
        self.writeAttribute("version", highlightingStylesFileFormatVersion)
        
        for lexer in self.lexers:
            self.writeStartElement("Lexer")
            self.writeAttribute("name", lexer.language())
            for style in lexer.descriptions:
                self.writeStartElement("Style")
                self.writeAttribute("style", str(style))
                self.writeAttribute("color", lexer.color(style).name())
                self.writeAttribute("paper", lexer.paper(style).name())
                self.writeAttribute("font", lexer.font(style).toString())
                self.writeAttribute("eolfill", str(lexer.eolFill(style)))
                self.writeCharacters(lexer.description(style))
                self.writeEndElement()
            self.writeEndElement()
        
        self.writeEndElement()
        self.writeEndDocument()

eric ide

mercurial