eric6/E5XML/HighlightingStylesWriter.py

Sun, 02 Feb 2020 11:04:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2020 11:04:32 +0100
changeset 7380
c99320e859ca
parent 7360
9190402e4505
child 7780
41420f82c0ac
permissions
-rw-r--r--

Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.

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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
3 # Copyright (c) 2008 - 2020 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
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import time
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
14 from .XMLStreamWriterBase import XMLStreamWriterBase
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
15 from .Config import highlightingStylesFileFormatVersion
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
19
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
20 class HighlightingStylesWriter(XMLStreamWriterBase):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
22 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
23 file.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
25 def __init__(self, device, lexers):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
29 @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
30 @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
31 """
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
32 XMLStreamWriterBase.__init__(self, device)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.lexers = lexers
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 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
36
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 def writeXML(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 Public method to write the XML to the file.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
41 XMLStreamWriterBase.writeXML(self)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
2992
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
43 self.writeDTD(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
44 '<!DOCTYPE HighlightingStyles SYSTEM'
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
45 ' "HighlightingStyles-{0}.dtd">'.format(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2992
diff changeset
46 highlightingStylesFileFormatVersion))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 # add some generation comments
3670
f0cb7579c0b4 Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
49 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
50 self.writeComment(
dbdf27746da5 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
51 " 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
52 self.writeComment(" Author: {0} ".format(self.email))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 # 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
55 self.writeStartElement("HighlightingStyles")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
56 self.writeAttribute("version", highlightingStylesFileFormatVersion)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 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
59 self.writeStartElement("Lexer")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
60 self.writeAttribute("name", lexer.language())
6863
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
61 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
62 self.writeStartElement("Style")
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
63 self.writeAttribute("style", str(style))
6863
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
64 self.writeAttribute("substyle", str(substyle))
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
65 self.writeAttribute("color",
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
66 lexer.color(style, substyle).name())
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
67 self.writeAttribute("paper",
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
68 lexer.paper(style, substyle).name())
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
69 self.writeAttribute("font",
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
70 lexer.font(style, substyle).toString())
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
71 self.writeAttribute("eolfill",
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
72 str(lexer.eolFill(style, substyle)))
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
73 self.writeStartElement("Description")
6867
97e86d2426a9 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6863
diff changeset
74 self.writeCharacters(description)
6863
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
75 self.writeEndElement() # Description
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
76 if substyle >= 0:
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
77 self.writeStartElement("Words")
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
78 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
79 self.writeEndElement() # Words
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
80 self.writeEndElement() # Style
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
81 self.writeEndElement() # Lexer
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
6863
e900929889dd HighlightingStylesReader, -Writer: added support for sub-styles.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6857
diff changeset
83 self.writeEndElement() # HighlightingStyles
593
32c9b36eec53 Migrated the highlighting styles handler to highlighting styles reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 411
diff changeset
84 self.writeEndDocument()

eric ide

mercurial