eric6/E5XML/HighlightingStylesWriter.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7780
41420f82c0ac
child 7960
e8fc383322f7
permissions
-rw-r--r--

Updated copyright for 2021.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2008 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
7 Module implementing the writer class for writing a highlighting styles XML
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
8 file.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import time
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
13 from .XMLStreamWriterBase import XMLStreamWriterBase
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
14 from .Config import highlightingStylesFileFormatVersion
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
18
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
19 class HighlightingStylesWriter(XMLStreamWriterBase):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
21 Class implementing the writer class for writing a highlighting styles XML
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
22 file.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
24 def __init__(self, device, lexers):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
28 @param device reference to the I/O device to write to (QIODevice)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param lexers list of lexer objects for which to export the styles
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
31 XMLStreamWriterBase.__init__(self, device)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.lexers = lexers
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.email = Preferences.getUser("Email")
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
35
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 def writeXML(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Public method to write the XML to the file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
40 XMLStreamWriterBase.writeXML(self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
42 self.writeDTD(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
43 '<!DOCTYPE HighlightingStyles SYSTEM'
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
44 ' "HighlightingStyles-{0}.dtd">'.format(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
45 highlightingStylesFileFormatVersion))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 # add some generation comments
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
48 self.writeComment(" Eric6 highlighting styles ")
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
49 self.writeComment(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
50 " Saved: {0}".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
51 self.writeComment(" Author: {0} ".format(self.email))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 # add the main tag
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
54 self.writeStartElement("HighlightingStyles")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
55 self.writeAttribute("version", highlightingStylesFileFormatVersion)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 for lexer in self.lexers:
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
58 self.writeStartElement("Lexer")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
59 self.writeAttribute("name", lexer.language())
6863
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
60 for description, style, substyle in lexer.getStyles():
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
61 self.writeStartElement("Style")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
62 self.writeAttribute("style", str(style))
6863
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
63 self.writeAttribute("substyle", str(substyle))
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
64 self.writeAttribute("color",
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
65 lexer.color(style, substyle).name())
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
66 self.writeAttribute("paper",
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
67 lexer.paper(style, substyle).name())
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
68 self.writeAttribute("font",
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
69 lexer.font(style, substyle).toString())
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
70 self.writeAttribute("eolfill",
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
71 str(lexer.eolFill(style, substyle)))
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
72 self.writeStartElement("Description")
6867
97e86d2426a9 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6863
diff changeset
73 self.writeCharacters(description)
6863
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
74 self.writeEndElement() # Description
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
75 if substyle >= 0:
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
76 self.writeStartElement("Words")
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
77 self.writeCharacters(lexer.words(style, substyle).strip())
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
78 self.writeEndElement() # Words
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
79 self.writeEndElement() # Style
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
80 self.writeEndElement() # Lexer
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81
6863
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
82 self.writeEndElement() # HighlightingStyles
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
83 self.writeEndDocument()

eric ide

mercurial