88 ) |
87 ) |
89 return False |
88 return False |
90 |
89 |
91 return True |
90 return True |
92 |
91 |
93 def readFile(self, filename: str, lexers: dict) -> bool: |
92 def readFile(self, filename: str, lexers: dict) -> list: |
94 """ |
93 """ |
95 Public method to read the highlighting styles data from a highlighting |
94 Public method to read the highlighting styles data from a highlighting |
96 styles JSON file. |
95 styles JSON file. |
97 |
96 |
98 @param filename name of the highlighting styles file |
97 @param filename name of the highlighting styles file |
99 @type str |
98 @type str |
100 @param lexers dictionary of lexer objects for which to import the |
99 @param lexers dictionary of lexer objects for which to import the |
101 styles |
100 styles |
102 @type dict of {str: PreferencesLexer} |
101 @type dict of {str: PreferencesLexer} |
103 @return flag indicating a successful read |
102 @return list of read lexer style definitions |
104 @rtype bool |
103 @rtype list of dict |
105 """ |
104 """ |
106 try: |
105 try: |
107 with open(filename, "r") as f: |
106 with open(filename, "r") as f: |
108 jsonString = f.read() |
107 jsonString = f.read() |
109 stylesDict = json.loads(jsonString) |
108 stylesDict = json.loads(jsonString) |
114 self.tr( |
113 self.tr( |
115 "<p>The highlighting styles file <b>{0}</b> could not be" |
114 "<p>The highlighting styles file <b>{0}</b> could not be" |
116 " read.</p><p>Reason: {1}</p>" |
115 " read.</p><p>Reason: {1}</p>" |
117 ).format(filename, str(err)) |
116 ).format(filename, str(err)) |
118 ) |
117 ) |
119 return False |
118 return [] |
120 |
119 |
121 for lexerDict in stylesDict["lexers"]: |
120 return stylesDict["lexers"] |
122 if lexerDict["name"] in lexers: |
|
123 lexer = lexers[lexerDict["name"]] |
|
124 for styleDict in lexerDict["styles"]: |
|
125 style = styleDict["style"] |
|
126 substyle = styleDict["substyle"] |
|
127 lexer.setColor(QColor(styleDict["color"]), style, substyle) |
|
128 lexer.setPaper(QColor(styleDict["paper"]), style, substyle) |
|
129 font = QFont() |
|
130 font.fromString(styleDict["font"]) |
|
131 lexer.setFont(font, style, substyle) |
|
132 lexer.setEolFill(styleDict["eolfill"], style, substyle) |
|
133 if substyle >= 0: |
|
134 # description and words can only be set for sub-styles |
|
135 lexer.setDescription(styleDict["description"], |
|
136 style, substyle) |
|
137 lexer.setWords(styleDict["words"], style, substyle) |
|
138 |
|
139 return True |
|