Preferences/ConfigurationPages/EditorHighlightingStylesPage.py

branch
Py2 comp.
changeset 3142
55030c09e142
parent 3060
5883ce99ee12
parent 3107
5b496e690984
child 3145
a9de05d4a22f
equal deleted inserted replaced
3141:72f3bde98c58 3142:55030c09e142
7 Module implementing the Editor Highlighting Styles configuration page. 7 Module implementing the Editor Highlighting Styles configuration page.
8 """ 8 """
9 9
10 from __future__ import unicode_literals # __IGNORE_WARNING__ 10 from __future__ import unicode_literals # __IGNORE_WARNING__
11 11
12 from PyQt4.QtCore import pyqtSlot, QFileInfo, QFile, QIODevice 12 from PyQt4.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice
13 from PyQt4.QtGui import QPalette, QColorDialog, QFontDialog, \ 13 from PyQt4.QtGui import QPalette, QColorDialog, QFontDialog, \
14 QInputDialog, QFont, QMenu 14 QInputDialog, QFont, QMenu
15 15
16 from .ConfigurationPageBase import ConfigurationPageBase 16 from .ConfigurationPageBase import ConfigurationPageBase
17 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage 17 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage
107 except KeyError: 107 except KeyError:
108 return 108 return
109 109
110 self.styleGroup.setEnabled(True) 110 self.styleGroup.setEnabled(True)
111 self.styleElementList.addItems(self.lexer.styles) 111 self.styleElementList.addItems(self.lexer.styles)
112 self.__styleAllItems()
112 self.styleElementList.setCurrentRow(0) 113 self.styleElementList.setCurrentRow(0)
114
115 def __styleAllItems(self):
116 """
117 Private method to style all items of the style element list.
118 """
119 for row in range(self.styleElementList.count()):
120 style = self.lexer.ind2style[row]
121 colour = self.lexer.color(style)
122 paper = self.lexer.paper(style)
123 font = self.lexer.font(style)
124 eolfill = self.lexer.eolFill(style)
125
126 itm = self.styleElementList.item(row)
127 itm.setFont(font)
128 itm.setBackground(paper)
129 itm.setForeground(colour)
130 if eolfill:
131 itm.setCheckState(Qt.Checked)
132 else:
133 itm.setCheckState(Qt.Unchecked)
113 134
114 def on_styleElementList_currentRowChanged(self, index): 135 def on_styleElementList_currentRowChanged(self, index):
115 """ 136 """
116 Private method to set up the style element part of the source page. 137 Private method to set up the style element part of the source page.
117 138
150 if len(self.styleElementList.selectedItems()) > 1: 171 if len(self.styleElementList.selectedItems()) > 1:
151 for selItem in self.styleElementList.selectedItems(): 172 for selItem in self.styleElementList.selectedItems():
152 style = self.lexer.ind2style[ 173 style = self.lexer.ind2style[
153 self.styleElementList.row(selItem)] 174 self.styleElementList.row(selItem)]
154 self.lexer.setColor(colour, style) 175 self.lexer.setColor(colour, style)
176 selItem.setForeground(colour)
155 else: 177 else:
156 self.lexer.setColor(colour, self.style) 178 self.lexer.setColor(colour, self.style)
179 self.styleElementList.currentItem().setForeground(colour)
157 180
158 @pyqtSlot() 181 @pyqtSlot()
159 def on_backgroundButton_clicked(self): 182 def on_backgroundButton_clicked(self):
160 """ 183 """
161 Private method used to select the background colour of the selected 184 Private method used to select the background colour of the selected
170 if len(self.styleElementList.selectedItems()) > 1: 193 if len(self.styleElementList.selectedItems()) > 1:
171 for selItem in self.styleElementList.selectedItems(): 194 for selItem in self.styleElementList.selectedItems():
172 style = self.lexer.ind2style[ 195 style = self.lexer.ind2style[
173 self.styleElementList.row(selItem)] 196 self.styleElementList.row(selItem)]
174 self.lexer.setPaper(colour, style) 197 self.lexer.setPaper(colour, style)
198 selItem.setBackground(colour)
175 else: 199 else:
176 self.lexer.setPaper(colour, self.style) 200 self.lexer.setPaper(colour, self.style)
201 self.styleElementList.currentItem().setBackground(colour)
177 202
178 @pyqtSlot() 203 @pyqtSlot()
179 def on_allBackgroundColoursButton_clicked(self): 204 def on_allBackgroundColoursButton_clicked(self):
180 """ 205 """
181 Private method used to select the background colour of all styles of a 206 Private method used to select the background colour of all styles of a
187 pl.setColor(QPalette.Base, colour) 212 pl.setColor(QPalette.Base, colour)
188 self.sampleText.setPalette(pl) 213 self.sampleText.setPalette(pl)
189 self.sampleText.repaint() 214 self.sampleText.repaint()
190 for style in list(self.lexer.ind2style.values()): 215 for style in list(self.lexer.ind2style.values()):
191 self.lexer.setPaper(colour, style) 216 self.lexer.setPaper(colour, style)
217 self.__styleAllItems()
192 218
193 def __changeFont(self, doAll, familyOnly, sizeOnly): 219 def __changeFont(self, doAll, familyOnly, sizeOnly):
194 """ 220 """
195 Private slot to change the highlighter font. 221 Private slot to change the highlighter font.
196 222
242 if ok: 268 if ok:
243 setSampleFont(font, familyOnly, sizeOnly) 269 setSampleFont(font, familyOnly, sizeOnly)
244 if doAll: 270 if doAll:
245 for style in list(self.lexer.ind2style.values()): 271 for style in list(self.lexer.ind2style.values()):
246 setFont(font, style, familyOnly, sizeOnly) 272 setFont(font, style, familyOnly, sizeOnly)
273 self.__styleAllItems()
247 elif len(self.styleElementList.selectedItems()) > 1: 274 elif len(self.styleElementList.selectedItems()) > 1:
248 for selItem in self.styleElementList.selectedItems(): 275 for selItem in self.styleElementList.selectedItems():
249 style = self.lexer.ind2style[ 276 style = self.lexer.ind2style[
250 self.styleElementList.row(selItem)] 277 self.styleElementList.row(selItem)]
251 setFont(font, style, familyOnly, sizeOnly) 278 setFont(font, style, familyOnly, sizeOnly)
279 itmFont = self.lexer.font(style)
280 selItem.setFont(itmFont)
252 else: 281 else:
253 setFont(font, self.style, familyOnly, sizeOnly) 282 setFont(font, self.style, familyOnly, sizeOnly)
283 itmFont = self.lexer.font(self.style)
284 self.styleElementList.currentItem().setFont(itmFont)
254 285
255 def __fontButtonMenuTriggered(self, act): 286 def __fontButtonMenuTriggered(self, act):
256 """ 287 """
257 Private slot used to select the font of the selected style and lexer. 288 Private slot used to select the font of the selected style and lexer.
258 289
276 307
277 familyOnly = act.data() in [self.FAMILYANDSIZE, self.FAMILYONLY] 308 familyOnly = act.data() in [self.FAMILYANDSIZE, self.FAMILYONLY]
278 sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY] 309 sizeOnly = act.data() in [self.FAMILYANDSIZE, self.SIZEONLY]
279 self.__changeFont(True, familyOnly, sizeOnly) 310 self.__changeFont(True, familyOnly, sizeOnly)
280 311
281 def on_eolfillCheckBox_toggled(self, b): 312 def on_eolfillCheckBox_toggled(self, on):
282 """ 313 """
283 Private method used to set the eolfill for the selected style and 314 Private method used to set the eolfill for the selected style and
284 lexer. 315 lexer.
285 316
286 @param b Flag indicating enabled or disabled state. 317 @param on flag indicating enabled or disabled state (boolean)
287 """ 318 """
288 self.lexer.setEolFill(b, self.style) 319 self.lexer.setEolFill(on, self.style)
320 checkState = Qt.Checked if on else Qt.Unchecked
321 self.styleElementList.currentItem().setCheckState(checkState)
289 322
290 @pyqtSlot() 323 @pyqtSlot()
291 def on_allEolFillButton_clicked(self): 324 def on_allEolFillButton_clicked(self):
292 """ 325 """
293 Private method used to set the eolfill for all styles of a selected 326 Private method used to set the eolfill for all styles of a selected
304 if ok: 337 if ok:
305 enabled = selection == on 338 enabled = selection == on
306 self.eolfillCheckBox.setChecked(enabled) 339 self.eolfillCheckBox.setChecked(enabled)
307 for style in list(self.lexer.ind2style.values()): 340 for style in list(self.lexer.ind2style.values()):
308 self.lexer.setEolFill(enabled, style) 341 self.lexer.setEolFill(enabled, style)
342 self.__styleAllItems()
309 343
310 @pyqtSlot() 344 @pyqtSlot()
311 def on_defaultButton_clicked(self): 345 def on_defaultButton_clicked(self):
312 """ 346 """
313 Private method to set the current style to its default values. 347 Private method to set the current style to its default values.
319 self.__setToDefault(style) 353 self.__setToDefault(style)
320 else: 354 else:
321 self.__setToDefault(self.style) 355 self.__setToDefault(self.style)
322 self.on_styleElementList_currentRowChanged( 356 self.on_styleElementList_currentRowChanged(
323 self.styleElementList.currentRow()) 357 self.styleElementList.currentRow())
358 self.__styleAllItems()
324 359
325 @pyqtSlot() 360 @pyqtSlot()
326 def on_allDefaultButton_clicked(self): 361 def on_allDefaultButton_clicked(self):
327 """ 362 """
328 Private method to set all styles to their default values. 363 Private method to set all styles to their default values.
329 """ 364 """
330 for style in list(self.lexer.ind2style.values()): 365 for style in list(self.lexer.ind2style.values()):
331 self.__setToDefault(style) 366 self.__setToDefault(style)
332 self.on_styleElementList_currentRowChanged( 367 self.on_styleElementList_currentRowChanged(
333 self.styleElementList.currentRow()) 368 self.styleElementList.currentRow())
369 self.__styleAllItems()
334 370
335 def __setToDefault(self, style): 371 def __setToDefault(self, style):
336 """ 372 """
337 Private method to set a specific style to its default values. 373 Private method to set a specific style to its default values.
338 374
453 pl.setColor(QPalette.Text, colour) 489 pl.setColor(QPalette.Text, colour)
454 pl.setColor(QPalette.Base, paper) 490 pl.setColor(QPalette.Base, paper)
455 self.sampleText.setPalette(pl) 491 self.sampleText.setPalette(pl)
456 self.sampleText.repaint() 492 self.sampleText.repaint()
457 self.eolfillCheckBox.setChecked(eolfill) 493 self.eolfillCheckBox.setChecked(eolfill)
494
495 self.__styleAllItems()
458 496
459 def saveState(self): 497 def saveState(self):
460 """ 498 """
461 Public method to save the current state of the widget. 499 Public method to save the current state of the widget.
462 500

eric ide

mercurial