E4XML/HighlightingStylesWriter.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2008 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the writer class for writing a highlighting styles XML file.
8 """
9
10 import os
11 import time
12
13 from E4Gui.E4Application import e4App
14
15 from XMLWriterBase import XMLWriterBase
16 from Config import highlightingStylesFileFormatVersion
17
18 import Preferences
19
20 class HighlightingStylesWriter(XMLWriterBase):
21 """
22 Class implementing the writer class for writing a highlighting styles XML file.
23 """
24 def __init__(self, file, lexers):
25 """
26 Constructor
27
28 @param file open file (like) object for writing
29 @param lexers list of lexer objects for which to export the styles
30 """
31 XMLWriterBase.__init__(self, file)
32
33 self.lexers = lexers
34 self.email = Preferences.getUser("Email")
35
36 def writeXML(self):
37 """
38 Public method to write the XML to the file.
39 """
40 XMLWriterBase.writeXML(self)
41
42 self._write('<!DOCTYPE HighlightingStyles SYSTEM "HighlightingStyles-%s.dtd">' % \
43 highlightingStylesFileFormatVersion)
44
45 # add some generation comments
46 self._write("<!-- Eric4 highlighting styles -->")
47 self._write("<!-- Saved: %s -->" % time.strftime('%Y-%m-%d, %H:%M:%S'))
48 self._write("<!-- Author: %s -->" % self.escape("%s" % self.email))
49
50 # add the main tag
51 self._write('<HighlightingStyles version="%s">' % \
52 highlightingStylesFileFormatVersion)
53
54 for lexer in self.lexers:
55 self._write(' <Lexer name="%s">' % lexer.language())
56 for style in lexer.descriptions:
57 self._write(' <Style style="%d" '
58 'color="%s" paper="%s" font="%s" eolfill="%d">%s</Style>' % \
59 (style, lexer.color(style).name(), lexer.paper(style).name(),
60 lexer.font(style).toString(), lexer.eolFill(style),
61 self.escape(lexer.description(style)))
62 )
63 self._write(' </Lexer>')
64
65 self._write("</HighlightingStyles>", newline = False)

eric ide

mercurial