Preferences/ConfigurationPages/EditorHighlightingStylesPage.py

branch
sub_styles
changeset 6864
7837ab17f079
parent 6862
6f4237ccf576
child 6867
97e86d2426a9
equal deleted inserted replaced
6863:e900929889dd 6864:7837ab17f079
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice 12 from PyQt5.QtCore import pyqtSlot, Qt, QFileInfo, QFile, QIODevice
13 from PyQt5.QtGui import QPalette, QFont 13 from PyQt5.QtGui import QPalette, QFont
14 from PyQt5.QtWidgets import QColorDialog, QFontDialog, QInputDialog, QMenu, \ 14 from PyQt5.QtWidgets import QColorDialog, QFontDialog, QInputDialog, QMenu, \
15 QTreeWidgetItem 15 QTreeWidgetItem, QDialog
16 16
17 from .ConfigurationPageBase import ConfigurationPageBase 17 from .ConfigurationPageBase import ConfigurationPageBase
18 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage 18 from .Ui_EditorHighlightingStylesPage import Ui_EditorHighlightingStylesPage
19 from ..SubstyleDefinitionDialog import SubstyleDefinitionDialog
19 20
20 from E5Gui import E5MessageBox, E5FileDialog 21 from E5Gui import E5MessageBox, E5FileDialog
21 22
22 from Globals import qVersionTuple 23 from Globals import qVersionTuple
24
25 import UI.PixmapCache
23 26
24 try: 27 try:
25 MonospacedFontsOption = QFontDialog.MonospacedFonts 28 MonospacedFontsOption = QFontDialog.MonospacedFonts
26 except AttributeError: 29 except AttributeError:
27 MonospacedFontsOption = QFontDialog.FontDialogOptions(0x10) 30 MonospacedFontsOption = QFontDialog.FontDialogOptions(0x10)
48 @param lexers reference to the lexers dictionary 51 @param lexers reference to the lexers dictionary
49 """ 52 """
50 super(EditorHighlightingStylesPage, self).__init__() 53 super(EditorHighlightingStylesPage, self).__init__()
51 self.setupUi(self) 54 self.setupUi(self)
52 self.setObjectName("EditorHighlightingStylesPage") 55 self.setObjectName("EditorHighlightingStylesPage")
56
57 self.addSubstyleButton.setIcon(UI.PixmapCache.getIcon("plus"))
58 self.deleteSubstyleButton.setIcon(UI.PixmapCache.getIcon("minus"))
59 self.editSubstyleButton.setIcon(UI.PixmapCache.getIcon("edit"))
60 self.copySubstyleButton.setIcon(UI.PixmapCache.getIcon("editCopy"))
53 61
54 if qVersionTuple() < (5, 0, 0): 62 if qVersionTuple() < (5, 0, 0):
55 self.monospacedButton.setChecked(False) 63 self.monospacedButton.setChecked(False)
56 self.monospacedButton.hide() 64 self.monospacedButton.hide()
57 65
227 pl.setColor(QPalette.Text, colour) 235 pl.setColor(QPalette.Text, colour)
228 pl.setColor(QPalette.Base, paper) 236 pl.setColor(QPalette.Base, paper)
229 self.sampleText.setPalette(pl) 237 self.sampleText.setPalette(pl)
230 self.sampleText.repaint() 238 self.sampleText.repaint()
231 self.eolfillCheckBox.setChecked(eolfill) 239 self.eolfillCheckBox.setChecked(eolfill)
240
241 selectedOne = len(self.styleElementList.selectedItems()) == 1
242 self.addSubstyleButton.setEnabled(
243 selectedOne and substyle < 0 and self.lexer.isBaseStyle(style))
244 self.deleteSubstyleButton.setEnabled(selectedOne and substyle >= 0)
245 self.editSubstyleButton.setEnabled(selectedOne and substyle >= 0)
246 self.copySubstyleButton.setEnabled(selectedOne and substyle >= 0)
232 247
233 @pyqtSlot() 248 @pyqtSlot()
234 def on_foregroundButton_clicked(self): 249 def on_foregroundButton_clicked(self):
235 """ 250 """
236 Private method used to select the foreground colour of the selected 251 Private method used to select the foreground colour of the selected
631 itm = self.styleElementList.topLevelItem(index) 646 itm = self.styleElementList.topLevelItem(index)
632 else: 647 else:
633 parent = self.styleElementList.topLevelItem(parentIndex) 648 parent = self.styleElementList.topLevelItem(parentIndex)
634 itm = parent.child(index) 649 itm = parent.child(index)
635 self.styleElementList.setCurrentItem(itm) 650 self.styleElementList.setCurrentItem(itm)
651
652 #######################################################################
653 ## Methods to add, delete and edit sub-styles and their definitions
654 #######################################################################
655
656 @pyqtSlot()
657 def on_addSubstyleButton_clicked(self):
658 """
659 Private slot to add a new sub-style.
660 """
661 style, substyle = self.__currentStyles()
662 dlg = SubstyleDefinitionDialog(
663 self.lexer, style, substyle, parent=self)
664 if dlg.exec_() == QDialog.Accepted:
665 description, words = dlg.getData()
666 substyle = self.lexer.addSubstyle(style)
667 self.lexer.setDescription(description, style, substyle)
668 self.lexer.setWords(words, style, substyle)
669
670 parent = self.styleElementList.findItems(
671 self.lexer.description(style), Qt.MatchExactly)[0]
672 parent.setExpanded(True)
673 itm = QTreeWidgetItem(parent, [description])
674 itm.setData(0, self.StyleRole, style)
675 itm.setData(0, self.SubstyleRole, substyle)
676 self.__styleOneItem(itm, style, substyle)
677
678 @pyqtSlot()
679 def on_deleteSubstyleButton_clicked(self):
680 """
681 Private slot to delete the selected sub-style.
682 """
683 style, substyle = self.__currentStyles()
684 ok = E5MessageBox.yesNo(
685 self,
686 self.tr("Delete Sub-Style"),
687 self.tr("""<p>Shall the sub-style <b>{0}</b> really be"""
688 """ deleted?</p>""").format(
689 self.lexer.description(style, substyle))
690 )
691 if ok:
692 self.lexer.delSubstyle(style, substyle)
693
694 itm = self.styleElementList.currentItem()
695 parent = itm.parent()
696 index = parent.indexOfChild(itm)
697 parent.takeChild(index)
698 del itm
699
700 @pyqtSlot()
701 def on_editSubstyleButton_clicked(self):
702 """
703 Private slot to edit the selected sub-style entry.
704 """
705 style, substyle = self.__currentStyles()
706 dlg = SubstyleDefinitionDialog(
707 self.lexer, style, substyle, parent=self)
708 if dlg.exec_() == QDialog.Accepted:
709 description, words = dlg.getData()
710 self.lexer.setDescription(description, style, substyle)
711 self.lexer.setWords(words, style, substyle)
712
713 itm = self.styleElementList.currentItem()
714 itm.setText(0, description)
715
716 @pyqtSlot()
717 def on_copySubstyleButton_clicked(self):
718 """
719 Private slot to copy the selected sub-style.
720 """
721 style, substyle = self.__currentStyles()
722 newSubstyle = self.lexer.addSubstyle(style)
723
724 description = self.tr("{0} - Copy").format(
725 self.lexer.description(style, substyle))
726 self.lexer.setDescription(description, style, newSubstyle)
727 self.lexer.setWords(self.lexer.words(style, substyle),
728 style, newSubstyle)
729 self.lexer.setColor(self.lexer.color(style, substyle),
730 style, newSubstyle)
731 self.lexer.setPaper(self.lexer.paper(style, substyle),
732 style, newSubstyle)
733 self.lexer.setFont(self.lexer.font(style, substyle),
734 style, newSubstyle)
735 self.lexer.setEolFill(self.lexer.eolFill(style, substyle),
736 style, newSubstyle)
737
738 parent = self.styleElementList.findItems(
739 self.lexer.description(style), Qt.MatchExactly)[0]
740 parent.setExpanded(True)
741 itm = QTreeWidgetItem(parent, [description])
742 itm.setData(0, self.StyleRole, style)
743 itm.setData(0, self.SubstyleRole, newSubstyle)
744 self.__styleOneItem(itm, style, newSubstyle)
636 745
637 746
638 def create(dlg): 747 def create(dlg):
639 """ 748 """
640 Module function to create the configuration page. 749 Module function to create the configuration page.

eric ide

mercurial