diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/Preferences/HighlightingStylesFile.py --- a/src/eric7/Preferences/HighlightingStylesFile.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Preferences/HighlightingStylesFile.py Wed Jul 13 14:55:47 2022 +0200 @@ -22,25 +22,26 @@ """ Class representing the highlighting styles JSON file. """ + def __init__(self, parent: QObject = None): """ Constructor - + @param parent reference to the parent object (defaults to None) @type QObject (optional) """ super().__init__(parent) - + self.__lexerAliases = { "PO": "Gettext", "POV": "Povray", } - + def writeFile(self, filename: str, lexers: list) -> bool: """ Public method to write the highlighting styles data to a highlighting styles JSON file. - + @param filename name of the highlighting styles file @type str @param lexers list of lexers for which to export the styles @@ -52,10 +53,10 @@ # step 0: header stylesDict["header"] = { "comment": "eric highlighting styles file", - "saved": time.strftime('%Y-%m-%d, %H:%M:%S'), + "saved": time.strftime("%Y-%m-%d, %H:%M:%S"), "author": Preferences.getUser("Email"), } - + # step 1: add the lexer style data stylesDict["lexers"] = [] for lexer in lexers: @@ -67,18 +68,20 @@ "styles": [], } for description, style, substyle in lexer.getStyles(): - lexerDict["styles"].append({ - "description": description, - "style": style, - "substyle": substyle, - "color": lexer.color(style, substyle).name(), - "paper": lexer.paper(style, substyle).name(), - "font": lexer.font(style, substyle).toString(), - "eolfill": lexer.eolFill(style, substyle), - "words": lexer.words(style, substyle).strip(), - }) + lexerDict["styles"].append( + { + "description": description, + "style": style, + "substyle": substyle, + "color": lexer.color(style, substyle).name(), + "paper": lexer.paper(style, substyle).name(), + "font": lexer.font(style, substyle).toString(), + "eolfill": lexer.eolFill(style, substyle), + "words": lexer.words(style, substyle).strip(), + } + ) stylesDict["lexers"].append(lexerDict) - + try: jsonString = json.dumps(stylesDict, indent=2) with open(filename, "w") as f: @@ -91,17 +94,17 @@ self.tr( "<p>The highlighting styles file <b>{0}</b> could not" " be written.</p><p>Reason: {1}</p>" - ).format(filename, str(err)) + ).format(filename, str(err)), ) return False - + return True - + def readFile(self, filename: str) -> list: """ Public method to read the highlighting styles data from a highlighting styles JSON file. - + @param filename name of the highlighting styles file @type str @return list of read lexer style definitions @@ -118,8 +121,8 @@ self.tr( "<p>The highlighting styles file <b>{0}</b> could not be" " read.</p><p>Reason: {1}</p>" - ).format(filename, str(err)) + ).format(filename, str(err)), ) return [] - + return stylesDict["lexers"]