Preferences/ConfigurationPages/EditorHighlightingStylesPage.py

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

eric ide

mercurial