22 from E5Gui import E5MessageBox, E5FileDialog |
22 from E5Gui import E5MessageBox, E5FileDialog |
23 |
23 |
24 import UI.PixmapCache |
24 import UI.PixmapCache |
25 |
25 |
26 try: |
26 try: |
27 MonospacedFontsOption = QFontDialog.MonospacedFonts |
27 MonospacedFontsOption = QFontDialog.FontDialogOption.MonospacedFonts |
28 except AttributeError: |
28 except AttributeError: |
29 MonospacedFontsOption = QFontDialog.FontDialogOptions(0x10) |
29 MonospacedFontsOption = QFontDialog.FontDialogOptions(0x10) |
30 NoFontsOption = QFontDialog.FontDialogOptions(0) |
30 NoFontsOption = QFontDialog.FontDialogOptions(0) |
31 |
31 |
32 |
32 |
128 |
128 |
129 self.styleGroup.setEnabled(True) |
129 self.styleGroup.setEnabled(True) |
130 for description, styleNo, subStyleNo in self.lexer.getStyles(): |
130 for description, styleNo, subStyleNo in self.lexer.getStyles(): |
131 if subStyleNo >= 0: |
131 if subStyleNo >= 0: |
132 parent = self.styleElementList.findItems( |
132 parent = self.styleElementList.findItems( |
133 self.lexer.description(styleNo), Qt.MatchExactly)[0] |
133 self.lexer.description(styleNo), |
|
134 Qt.MatchFlag.MatchExactly)[0] |
134 parent.setExpanded(True) |
135 parent.setExpanded(True) |
135 else: |
136 else: |
136 parent = self.styleElementList |
137 parent = self.styleElementList |
137 itm = QTreeWidgetItem(parent, [description]) |
138 itm = QTreeWidgetItem(parent, [description]) |
138 itm.setData(0, self.StyleRole, styleNo) |
139 itm.setData(0, self.StyleRole, styleNo) |
188 |
189 |
189 item.setFont(0, font) |
190 item.setFont(0, font) |
190 item.setBackground(0, paper) |
191 item.setBackground(0, paper) |
191 item.setForeground(0, colour) |
192 item.setForeground(0, colour) |
192 if eolfill: |
193 if eolfill: |
193 item.setCheckState(0, Qt.Checked) |
194 item.setCheckState(0, Qt.CheckState.Checked) |
194 else: |
195 else: |
195 item.setCheckState(0, Qt.Unchecked) |
196 item.setCheckState(0, Qt.CheckState.Unchecked) |
196 |
197 |
197 def __styleAllItems(self): |
198 def __styleAllItems(self): |
198 """ |
199 """ |
199 Private method to style all items of the style element list. |
200 Private method to style all items of the style element list. |
200 """ |
201 """ |
223 eolfill = self.lexer.eolFill(style, substyle) |
224 eolfill = self.lexer.eolFill(style, substyle) |
224 font = self.lexer.font(style, substyle) |
225 font = self.lexer.font(style, substyle) |
225 |
226 |
226 self.sampleText.setFont(font) |
227 self.sampleText.setFont(font) |
227 pl = self.sampleText.palette() |
228 pl = self.sampleText.palette() |
228 pl.setColor(QPalette.Text, colour) |
229 pl.setColor(QPalette.ColorRole.Text, colour) |
229 pl.setColor(QPalette.Base, paper) |
230 pl.setColor(QPalette.ColorRole.Base, paper) |
230 self.sampleText.setPalette(pl) |
231 self.sampleText.setPalette(pl) |
231 self.sampleText.repaint() |
232 self.sampleText.repaint() |
232 self.eolfillCheckBox.setChecked(eolfill) |
233 self.eolfillCheckBox.setChecked(eolfill) |
233 |
234 |
234 selectedOne = len(self.styleElementList.selectedItems()) == 1 |
235 selectedOne = len(self.styleElementList.selectedItems()) == 1 |
248 """ |
249 """ |
249 style, substyle = self.__currentStyles() |
250 style, substyle = self.__currentStyles() |
250 colour = QColorDialog.getColor(self.lexer.color(style, substyle)) |
251 colour = QColorDialog.getColor(self.lexer.color(style, substyle)) |
251 if colour.isValid(): |
252 if colour.isValid(): |
252 pl = self.sampleText.palette() |
253 pl = self.sampleText.palette() |
253 pl.setColor(QPalette.Text, colour) |
254 pl.setColor(QPalette.ColorRole.Text, colour) |
254 self.sampleText.setPalette(pl) |
255 self.sampleText.setPalette(pl) |
255 self.sampleText.repaint() |
256 self.sampleText.repaint() |
256 for selItem in self.styleElementList.selectedItems(): |
257 for selItem in self.styleElementList.selectedItems(): |
257 style, substyle = self.__stylesForItem(selItem) |
258 style, substyle = self.__stylesForItem(selItem) |
258 self.lexer.setColor(colour, style, substyle) |
259 self.lexer.setColor(colour, style, substyle) |
266 """ |
267 """ |
267 style, substyle = self.__currentStyles() |
268 style, substyle = self.__currentStyles() |
268 colour = QColorDialog.getColor(self.lexer.paper(style, substyle)) |
269 colour = QColorDialog.getColor(self.lexer.paper(style, substyle)) |
269 if colour.isValid(): |
270 if colour.isValid(): |
270 pl = self.sampleText.palette() |
271 pl = self.sampleText.palette() |
271 pl.setColor(QPalette.Base, colour) |
272 pl.setColor(QPalette.ColorRole.Base, colour) |
272 self.sampleText.setPalette(pl) |
273 self.sampleText.setPalette(pl) |
273 self.sampleText.repaint() |
274 self.sampleText.repaint() |
274 for selItem in self.styleElementList.selectedItems(): |
275 for selItem in self.styleElementList.selectedItems(): |
275 style, substyle = self.__stylesForItem(selItem) |
276 style, substyle = self.__stylesForItem(selItem) |
276 self.lexer.setPaper(colour, style, substyle) |
277 self.lexer.setPaper(colour, style, substyle) |
284 """ |
285 """ |
285 style, substyle = self.__currentStyles() |
286 style, substyle = self.__currentStyles() |
286 colour = QColorDialog.getColor(self.lexer.paper(style, substyle)) |
287 colour = QColorDialog.getColor(self.lexer.paper(style, substyle)) |
287 if colour.isValid(): |
288 if colour.isValid(): |
288 pl = self.sampleText.palette() |
289 pl = self.sampleText.palette() |
289 pl.setColor(QPalette.Base, colour) |
290 pl.setColor(QPalette.ColorRole.Base, colour) |
290 self.sampleText.setPalette(pl) |
291 self.sampleText.setPalette(pl) |
291 self.sampleText.repaint() |
292 self.sampleText.repaint() |
292 |
293 |
293 itm = self.styleElementList.topLevelItem(0) |
294 itm = self.styleElementList.topLevelItem(0) |
294 while itm is not None: |
295 while itm is not None: |
407 lexer. |
408 lexer. |
408 |
409 |
409 @param on flag indicating enabled or disabled state (boolean) |
410 @param on flag indicating enabled or disabled state (boolean) |
410 """ |
411 """ |
411 style, substyle = self.__currentStyles() |
412 style, substyle = self.__currentStyles() |
412 checkState = Qt.Checked if on else Qt.Unchecked |
413 checkState = Qt.CheckState.Checked if on else Qt.CheckState.Unchecked |
413 for selItem in self.styleElementList.selectedItems(): |
414 for selItem in self.styleElementList.selectedItems(): |
414 style, substyle = self.__stylesForItem(selItem) |
415 style, substyle = self.__stylesForItem(selItem) |
415 self.lexer.setEolFill(on, style, substyle) |
416 self.lexer.setEolFill(on, style, substyle) |
416 selItem.setCheckState(0, checkState) |
417 selItem.setCheckState(0, checkState) |
417 |
418 |
535 preselect = [] |
536 preselect = [] |
536 from .EditorHighlightingStylesSelectionDialog import ( |
537 from .EditorHighlightingStylesSelectionDialog import ( |
537 EditorHighlightingStylesSelectionDialog) |
538 EditorHighlightingStylesSelectionDialog) |
538 dlg = EditorHighlightingStylesSelectionDialog( |
539 dlg = EditorHighlightingStylesSelectionDialog( |
539 lexerNames, forImport=False, preselect=preselect) |
540 lexerNames, forImport=False, preselect=preselect) |
540 if dlg.exec() == QDialog.Accepted: |
541 if dlg.exec() == QDialog.DialogCode.Accepted: |
541 lexerNames = dlg.getLexerNames() |
542 lexerNames = dlg.getLexerNames() |
542 else: |
543 else: |
543 # Cancelled by user |
544 # Cancelled by user |
544 return |
545 return |
545 |
546 |
579 ) |
580 ) |
580 highlightingStylesFile = HighlightingStylesFile() |
581 highlightingStylesFile = HighlightingStylesFile() |
581 highlightingStylesFile.writeFile(fn, lexers) |
582 highlightingStylesFile.writeFile(fn, lexers) |
582 else: |
583 else: |
583 f = QFile(fn) |
584 f = QFile(fn) |
584 if f.open(QIODevice.WriteOnly): |
585 if f.open(QIODevice.OpenModeFlag.WriteOnly): |
585 from E5XML.HighlightingStylesWriter import ( |
586 from E5XML.HighlightingStylesWriter import ( |
586 HighlightingStylesWriter |
587 HighlightingStylesWriter |
587 ) |
588 ) |
588 HighlightingStylesWriter(f, lexers).writeXML() |
589 HighlightingStylesWriter(f, lexers).writeXML() |
589 f.close() |
590 f.close() |
627 if not styles: |
628 if not styles: |
628 return |
629 return |
629 else: |
630 else: |
630 # old XML based file |
631 # old XML based file |
631 f = QFile(fn) |
632 f = QFile(fn) |
632 if f.open(QIODevice.ReadOnly): |
633 if f.open(QIODevice.OpenModeFlag.ReadOnly): |
633 from E5XML.HighlightingStylesReader import ( |
634 from E5XML.HighlightingStylesReader import ( |
634 HighlightingStylesReader |
635 HighlightingStylesReader |
635 ) |
636 ) |
636 reader = HighlightingStylesReader(f, self.lexers) |
637 reader = HighlightingStylesReader(f, self.lexers) |
637 styles = reader.readXML() |
638 styles = reader.readXML() |
670 if not importAll: |
671 if not importAll: |
671 from .EditorHighlightingStylesSelectionDialog import ( |
672 from .EditorHighlightingStylesSelectionDialog import ( |
672 EditorHighlightingStylesSelectionDialog) |
673 EditorHighlightingStylesSelectionDialog) |
673 dlg = EditorHighlightingStylesSelectionDialog( |
674 dlg = EditorHighlightingStylesSelectionDialog( |
674 lexerNames, forImport=True) |
675 lexerNames, forImport=True) |
675 if dlg.exec() == QDialog.Accepted: |
676 if dlg.exec() == QDialog.DialogCode.Accepted: |
676 lexerNames = dlg.getLexerNames() |
677 lexerNames = dlg.getLexerNames() |
677 else: |
678 else: |
678 # Cancelled by user |
679 # Cancelled by user |
679 return |
680 return |
680 |
681 |
758 Private slot to add a new sub-style. |
759 Private slot to add a new sub-style. |
759 """ |
760 """ |
760 style, substyle = self.__currentStyles() |
761 style, substyle = self.__currentStyles() |
761 dlg = SubstyleDefinitionDialog( |
762 dlg = SubstyleDefinitionDialog( |
762 self.lexer, style, substyle, parent=self) |
763 self.lexer, style, substyle, parent=self) |
763 if dlg.exec() == QDialog.Accepted: |
764 if dlg.exec() == QDialog.DialogCode.Accepted: |
764 description, words = dlg.getData() |
765 description, words = dlg.getData() |
765 substyle = self.lexer.addSubstyle(style) |
766 substyle = self.lexer.addSubstyle(style) |
766 self.lexer.setDescription(description, style, substyle) |
767 self.lexer.setDescription(description, style, substyle) |
767 self.lexer.setWords(words, style, substyle) |
768 self.lexer.setWords(words, style, substyle) |
768 |
769 |
769 parent = self.styleElementList.findItems( |
770 parent = self.styleElementList.findItems( |
770 self.lexer.description(style), Qt.MatchExactly)[0] |
771 self.lexer.description(style), Qt.MatchFlag.MatchExactly)[0] |
771 parent.setExpanded(True) |
772 parent.setExpanded(True) |
772 itm = QTreeWidgetItem(parent, [description]) |
773 itm = QTreeWidgetItem(parent, [description]) |
773 itm.setData(0, self.StyleRole, style) |
774 itm.setData(0, self.StyleRole, style) |
774 itm.setData(0, self.SubstyleRole, substyle) |
775 itm.setData(0, self.SubstyleRole, substyle) |
775 self.__styleOneItem(itm, style, substyle) |
776 self.__styleOneItem(itm, style, substyle) |
802 Private slot to edit the selected sub-style entry. |
803 Private slot to edit the selected sub-style entry. |
803 """ |
804 """ |
804 style, substyle = self.__currentStyles() |
805 style, substyle = self.__currentStyles() |
805 dlg = SubstyleDefinitionDialog( |
806 dlg = SubstyleDefinitionDialog( |
806 self.lexer, style, substyle, parent=self) |
807 self.lexer, style, substyle, parent=self) |
807 if dlg.exec() == QDialog.Accepted: |
808 if dlg.exec() == QDialog.DialogCode.Accepted: |
808 description, words = dlg.getData() |
809 description, words = dlg.getData() |
809 self.lexer.setDescription(description, style, substyle) |
810 self.lexer.setDescription(description, style, substyle) |
810 self.lexer.setWords(words, style, substyle) |
811 self.lexer.setWords(words, style, substyle) |
811 |
812 |
812 itm = self.styleElementList.currentItem() |
813 itm = self.styleElementList.currentItem() |
833 style, newSubstyle) |
834 style, newSubstyle) |
834 self.lexer.setEolFill(self.lexer.eolFill(style, substyle), |
835 self.lexer.setEolFill(self.lexer.eolFill(style, substyle), |
835 style, newSubstyle) |
836 style, newSubstyle) |
836 |
837 |
837 parent = self.styleElementList.findItems( |
838 parent = self.styleElementList.findItems( |
838 self.lexer.description(style), Qt.MatchExactly)[0] |
839 self.lexer.description(style), Qt.MatchFlag.MatchExactly)[0] |
839 parent.setExpanded(True) |
840 parent.setExpanded(True) |
840 itm = QTreeWidgetItem(parent, [description]) |
841 itm = QTreeWidgetItem(parent, [description]) |
841 itm.setData(0, self.StyleRole, style) |
842 itm.setData(0, self.StyleRole, style) |
842 itm.setData(0, self.SubstyleRole, newSubstyle) |
843 itm.setData(0, self.SubstyleRole, newSubstyle) |
843 self.__styleOneItem(itm, style, newSubstyle) |
844 self.__styleOneItem(itm, style, newSubstyle) |