43 |
43 |
44 self.__fontButtonMenu = QMenu() |
44 self.__fontButtonMenu = QMenu() |
45 act = self.__fontButtonMenu.addAction(self.trUtf8("Font")) |
45 act = self.__fontButtonMenu.addAction(self.trUtf8("Font")) |
46 act.setData(self.FONT) |
46 act.setData(self.FONT) |
47 self.__fontButtonMenu.addSeparator() |
47 self.__fontButtonMenu.addSeparator() |
48 act = self.__fontButtonMenu.addAction(self.trUtf8("Family and Size only")) |
48 act = self.__fontButtonMenu.addAction( |
|
49 self.trUtf8("Family and Size only")) |
49 act.setData(self.FAMILYANDSIZE) |
50 act.setData(self.FAMILYANDSIZE) |
50 act = self.__fontButtonMenu.addAction(self.trUtf8("Family only")) |
51 act = self.__fontButtonMenu.addAction(self.trUtf8("Family only")) |
51 act.setData(self.FAMILYONLY) |
52 act.setData(self.FAMILYONLY) |
52 act = self.__fontButtonMenu.addAction(self.trUtf8("Size only")) |
53 act = self.__fontButtonMenu.addAction(self.trUtf8("Size only")) |
53 act.setData(self.SIZEONLY) |
54 act.setData(self.SIZEONLY) |
56 |
57 |
57 self.__allFontsButtonMenu = QMenu() |
58 self.__allFontsButtonMenu = QMenu() |
58 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Font")) |
59 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Font")) |
59 act.setData(self.FONT) |
60 act.setData(self.FONT) |
60 self.__allFontsButtonMenu.addSeparator() |
61 self.__allFontsButtonMenu.addSeparator() |
61 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Family and Size only")) |
62 act = self.__allFontsButtonMenu.addAction( |
|
63 self.trUtf8("Family and Size only")) |
62 act.setData(self.FAMILYANDSIZE) |
64 act.setData(self.FAMILYANDSIZE) |
63 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Family only")) |
65 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Family only")) |
64 act.setData(self.FAMILYONLY) |
66 act.setData(self.FAMILYONLY) |
65 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Size only")) |
67 act = self.__allFontsButtonMenu.addAction(self.trUtf8("Size only")) |
66 act.setData(self.SIZEONLY) |
68 act.setData(self.SIZEONLY) |
67 self.__allFontsButtonMenu.triggered.connect(self.__allFontsButtonMenuTriggered) |
69 self.__allFontsButtonMenu.triggered.connect( |
|
70 self.__allFontsButtonMenuTriggered) |
68 self.allFontsButton.setMenu(self.__allFontsButtonMenu) |
71 self.allFontsButton.setMenu(self.__allFontsButtonMenu) |
69 |
72 |
70 self.lexer = None |
73 self.lexer = None |
71 self.lexers = lexers |
74 self.lexers = lexers |
72 |
75 |
133 self.eolfillCheckBox.setChecked(eolfill) |
136 self.eolfillCheckBox.setChecked(eolfill) |
134 |
137 |
135 @pyqtSlot() |
138 @pyqtSlot() |
136 def on_foregroundButton_clicked(self): |
139 def on_foregroundButton_clicked(self): |
137 """ |
140 """ |
138 Private method used to select the foreground colour of the selected style |
141 Private method used to select the foreground colour of the selected |
139 and lexer. |
142 style and lexer. |
140 """ |
143 """ |
141 colour = QColorDialog.getColor(self.lexer.color(self.style)) |
144 colour = QColorDialog.getColor(self.lexer.color(self.style)) |
142 if colour.isValid(): |
145 if colour.isValid(): |
143 pl = self.sampleText.palette() |
146 pl = self.sampleText.palette() |
144 pl.setColor(QPalette.Text, colour) |
147 pl.setColor(QPalette.Text, colour) |
145 self.sampleText.setPalette(pl) |
148 self.sampleText.setPalette(pl) |
146 self.sampleText.repaint() |
149 self.sampleText.repaint() |
147 if len(self.styleElementList.selectedItems()) > 1: |
150 if len(self.styleElementList.selectedItems()) > 1: |
148 for selItem in self.styleElementList.selectedItems(): |
151 for selItem in self.styleElementList.selectedItems(): |
149 style = self.lexer.ind2style[self.styleElementList.row(selItem)] |
152 style = self.lexer.ind2style[ |
|
153 self.styleElementList.row(selItem)] |
150 self.lexer.setColor(colour, style) |
154 self.lexer.setColor(colour, style) |
151 else: |
155 else: |
152 self.lexer.setColor(colour, self.style) |
156 self.lexer.setColor(colour, self.style) |
153 |
157 |
154 @pyqtSlot() |
158 @pyqtSlot() |
155 def on_backgroundButton_clicked(self): |
159 def on_backgroundButton_clicked(self): |
156 """ |
160 """ |
157 Private method used to select the background colour of the selected style |
161 Private method used to select the background colour of the selected |
158 and lexer. |
162 style and lexer. |
159 """ |
163 """ |
160 colour = QColorDialog.getColor(self.lexer.paper(self.style)) |
164 colour = QColorDialog.getColor(self.lexer.paper(self.style)) |
161 if colour.isValid(): |
165 if colour.isValid(): |
162 pl = self.sampleText.palette() |
166 pl = self.sampleText.palette() |
163 pl.setColor(QPalette.Base, colour) |
167 pl.setColor(QPalette.Base, colour) |
164 self.sampleText.setPalette(pl) |
168 self.sampleText.setPalette(pl) |
165 self.sampleText.repaint() |
169 self.sampleText.repaint() |
166 if len(self.styleElementList.selectedItems()) > 1: |
170 if len(self.styleElementList.selectedItems()) > 1: |
167 for selItem in self.styleElementList.selectedItems(): |
171 for selItem in self.styleElementList.selectedItems(): |
168 style = self.lexer.ind2style[self.styleElementList.row(selItem)] |
172 style = self.lexer.ind2style[ |
|
173 self.styleElementList.row(selItem)] |
169 self.lexer.setPaper(colour, style) |
174 self.lexer.setPaper(colour, style) |
170 else: |
175 else: |
171 self.lexer.setPaper(colour, self.style) |
176 self.lexer.setPaper(colour, self.style) |
172 |
177 |
173 @pyqtSlot() |
178 @pyqtSlot() |
187 |
192 |
188 def __changeFont(self, doAll, familyOnly, sizeOnly): |
193 def __changeFont(self, doAll, familyOnly, sizeOnly): |
189 """ |
194 """ |
190 Private slot to change the highlighter font. |
195 Private slot to change the highlighter font. |
191 |
196 |
192 @param doAll flag indicating to change the font for all styles (boolean) |
197 @param doAll flag indicating to change the font for all styles |
|
198 (boolean) |
193 @param familyOnly flag indicating to set the font family only (boolean) |
199 @param familyOnly flag indicating to set the font family only (boolean) |
194 @param sizeOnly flag indicating to set the font size only (boolean |
200 @param sizeOnly flag indicating to set the font size only (boolean |
195 """ |
201 """ |
196 def setFont(font, style, familyOnly, sizeOnly): |
202 def setFont(font, style, familyOnly, sizeOnly): |
197 """ |
203 """ |
198 Local function to set the font. |
204 Local function to set the font. |
199 |
205 |
200 @param font font to be set (QFont) |
206 @param font font to be set (QFont) |
201 @param style style to set the font for (integer) |
207 @param style style to set the font for (integer) |
202 @param familyOnly flag indicating to set the font family only (boolean) |
208 @param familyOnly flag indicating to set the font family only |
|
209 (boolean) |
203 @param sizeOnly flag indicating to set the font size only (boolean |
210 @param sizeOnly flag indicating to set the font size only (boolean |
204 """ |
211 """ |
205 if familyOnly or sizeOnly: |
212 if familyOnly or sizeOnly: |
206 newFont = QFont(self.lexer.font(style)) |
213 newFont = QFont(self.lexer.font(style)) |
207 if familyOnly: |
214 if familyOnly: |
215 def setSampleFont(font, familyOnly, sizeOnly): |
222 def setSampleFont(font, familyOnly, sizeOnly): |
216 """ |
223 """ |
217 Local function to set the font of the sample text. |
224 Local function to set the font of the sample text. |
218 |
225 |
219 @param font font to be set (QFont) |
226 @param font font to be set (QFont) |
220 @param familyOnly flag indicating to set the font family only (boolean) |
227 @param familyOnly flag indicating to set the font family only |
|
228 (boolean) |
221 @param sizeOnly flag indicating to set the font size only (boolean |
229 @param sizeOnly flag indicating to set the font size only (boolean |
222 """ |
230 """ |
223 if familyOnly or sizeOnly: |
231 if familyOnly or sizeOnly: |
224 newFont = QFont(self.lexer.font(self.style)) |
232 newFont = QFont(self.lexer.font(self.style)) |
225 if familyOnly: |
233 if familyOnly: |
236 if doAll: |
244 if doAll: |
237 for style in list(self.lexer.ind2style.values()): |
245 for style in list(self.lexer.ind2style.values()): |
238 setFont(font, style, familyOnly, sizeOnly) |
246 setFont(font, style, familyOnly, sizeOnly) |
239 elif len(self.styleElementList.selectedItems()) > 1: |
247 elif len(self.styleElementList.selectedItems()) > 1: |
240 for selItem in self.styleElementList.selectedItems(): |
248 for selItem in self.styleElementList.selectedItems(): |
241 style = self.lexer.ind2style[self.styleElementList.row(selItem)] |
249 style = self.lexer.ind2style[ |
|
250 self.styleElementList.row(selItem)] |
242 setFont(font, style, familyOnly, sizeOnly) |
251 setFont(font, style, familyOnly, sizeOnly) |
243 else: |
252 else: |
244 setFont(font, self.style, familyOnly, sizeOnly) |
253 setFont(font, self.style, familyOnly, sizeOnly) |
245 |
254 |
246 def __fontButtonMenuTriggered(self, act): |
255 def __fontButtonMenuTriggered(self, act): |
269 sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] |
278 sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] |
270 self.__changeFont(True, familyOnly, sizeOnly) |
279 self.__changeFont(True, familyOnly, sizeOnly) |
271 |
280 |
272 def on_eolfillCheckBox_toggled(self, b): |
281 def on_eolfillCheckBox_toggled(self, b): |
273 """ |
282 """ |
274 Private method used to set the eolfill for the selected style and lexer. |
283 Private method used to set the eolfill for the selected style and |
|
284 lexer. |
275 |
285 |
276 @param b Flag indicating enabled or disabled state. |
286 @param b Flag indicating enabled or disabled state. |
277 """ |
287 """ |
278 self.lexer.setEolFill(b, self.style) |
288 self.lexer.setEolFill(b, self.style) |
279 |
289 |
280 @pyqtSlot() |
290 @pyqtSlot() |
281 def on_allEolFillButton_clicked(self): |
291 def on_allEolFillButton_clicked(self): |
282 """ |
292 """ |
283 Private method used to set the eolfill for all styles of a selected lexer. |
293 Private method used to set the eolfill for all styles of a selected |
|
294 lexer. |
284 """ |
295 """ |
285 on = self.trUtf8("Enabled") |
296 on = self.trUtf8("Enabled") |
286 off = self.trUtf8("Disabled") |
297 off = self.trUtf8("Disabled") |
287 selection, ok = QInputDialog.getItem( |
298 selection, ok = QInputDialog.getItem( |
288 self, |
299 self, |
301 """ |
312 """ |
302 Private method to set the current style to its default values. |
313 Private method to set the current style to its default values. |
303 """ |
314 """ |
304 if len(self.styleElementList.selectedItems()) > 1: |
315 if len(self.styleElementList.selectedItems()) > 1: |
305 for selItem in self.styleElementList.selectedItems(): |
316 for selItem in self.styleElementList.selectedItems(): |
306 style = self.lexer.ind2style[self.styleElementList.row(selItem)] |
317 style = self.lexer.ind2style[ |
|
318 self.styleElementList.row(selItem)] |
307 self.__setToDefault(style) |
319 self.__setToDefault(style) |
308 else: |
320 else: |
309 self.__setToDefault(self.style) |
321 self.__setToDefault(self.style) |
310 self.on_styleElementList_currentRowChanged(self.styleElementList.currentRow()) |
322 self.on_styleElementList_currentRowChanged( |
|
323 self.styleElementList.currentRow()) |
311 |
324 |
312 @pyqtSlot() |
325 @pyqtSlot() |
313 def on_allDefaultButton_clicked(self): |
326 def on_allDefaultButton_clicked(self): |
314 """ |
327 """ |
315 Private method to set all styles to their default values. |
328 Private method to set all styles to their default values. |
316 """ |
329 """ |
317 for style in list(self.lexer.ind2style.values()): |
330 for style in list(self.lexer.ind2style.values()): |
318 self.__setToDefault(style) |
331 self.__setToDefault(style) |
319 self.on_styleElementList_currentRowChanged(self.styleElementList.currentRow()) |
332 self.on_styleElementList_currentRowChanged( |
|
333 self.styleElementList.currentRow()) |
320 |
334 |
321 def __setToDefault(self, style): |
335 def __setToDefault(self, style): |
322 """ |
336 """ |
323 Private method to set a specific style to its default values. |
337 Private method to set a specific style to its default values. |
324 |
338 |
386 HighlightingStylesWriter(f, lexers).writeXML() |
400 HighlightingStylesWriter(f, lexers).writeXML() |
387 f.close() |
401 f.close() |
388 else: |
402 else: |
389 E5MessageBox.critical(self, |
403 E5MessageBox.critical(self, |
390 self.trUtf8("Export Highlighting Styles"), |
404 self.trUtf8("Export Highlighting Styles"), |
391 self.trUtf8("""<p>The highlighting styles could not be exported""" |
405 self.trUtf8( |
392 """ to file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
406 """<p>The highlighting styles could not be exported""" |
|
407 """ to file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
393 .format(fn, f.errorString()) |
408 .format(fn, f.errorString()) |
394 ) |
409 ) |
395 |
410 |
396 def __importStyles(self, lexers): |
411 def __importStyles(self, lexers): |
397 """ |
412 """ |
398 Private method to import the styles of the given lexers. |
413 Private method to import the styles of the given lexers. |
399 |
414 |
400 @param lexers dictionary of lexer objects for which to import the styles |
415 @param lexers dictionary of lexer objects for which to import the |
|
416 styles |
401 """ |
417 """ |
402 fn = E5FileDialog.getOpenFileName( |
418 fn = E5FileDialog.getOpenFileName( |
403 self, |
419 self, |
404 self.trUtf8("Import Highlighting Styles"), |
420 self.trUtf8("Import Highlighting Styles"), |
405 "", |
421 "", |
415 reader.readXML() |
431 reader.readXML() |
416 f.close() |
432 f.close() |
417 else: |
433 else: |
418 E5MessageBox.critical(self, |
434 E5MessageBox.critical(self, |
419 self.trUtf8("Import Highlighting Styles"), |
435 self.trUtf8("Import Highlighting Styles"), |
420 self.trUtf8("""<p>The highlighting styles could not be read""" |
436 self.trUtf8( |
421 """ from file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
437 """<p>The highlighting styles could not be read""" |
|
438 """ from file <b>{0}</b>.</p><p>Reason: {1}</p>""")\ |
422 .format(fn, f.errorString()) |
439 .format(fn, f.errorString()) |
423 ) |
440 ) |
424 return |
441 return |
425 |
442 |
426 if self.lexer: |
443 if self.lexer: |
439 |
456 |
440 def saveState(self): |
457 def saveState(self): |
441 """ |
458 """ |
442 Public method to save the current state of the widget. |
459 Public method to save the current state of the widget. |
443 |
460 |
444 @return array containing the index of the selected lexer language (integer) |
461 @return array containing the index of the selected lexer language |
445 and the index of the selected lexer entry (integer) |
462 (integer) and the index of the selected lexer entry (integer) |
446 """ |
463 """ |
447 savedState = [ |
464 savedState = [ |
448 self.lexerLanguageComboBox.currentIndex(), |
465 self.lexerLanguageComboBox.currentIndex(), |
449 self.styleElementList.currentRow(), |
466 self.styleElementList.currentRow(), |
450 ] |
467 ] |
455 Public method to set the state of the widget. |
472 Public method to set the state of the widget. |
456 |
473 |
457 @param state state data generated by saveState |
474 @param state state data generated by saveState |
458 """ |
475 """ |
459 self.lexerLanguageComboBox.setCurrentIndex(state[0]) |
476 self.lexerLanguageComboBox.setCurrentIndex(state[0]) |
460 self.on_lexerLanguageComboBox_activated(self.lexerLanguageComboBox.currentText()) |
477 self.on_lexerLanguageComboBox_activated( |
|
478 self.lexerLanguageComboBox.currentText()) |
461 self.styleElementList.setCurrentRow(state[1]) |
479 self.styleElementList.setCurrentRow(state[1]) |
462 |
480 |
463 |
481 |
464 def create(dlg): |
482 def create(dlg): |
465 """ |
483 """ |
466 Module function to create the configuration page. |
484 Module function to create the configuration page. |
467 |
485 |
468 @param dlg reference to the configuration dialog |
486 @param dlg reference to the configuration dialog |
|
487 @return reference to the instantiated page (ConfigurationPageBase) |
469 """ |
488 """ |
470 page = EditorHighlightingStylesPage(dlg.getLexers()) |
489 page = EditorHighlightingStylesPage(dlg.getLexers()) |
471 return page |
490 return page |