src/eric7/Preferences/ConfigurationPages/EditorHighlightingStylesSelectionDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2021 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to select the styles to be imported/exported.
8 """
9
10 from PyQt6.QtCore import pyqtSlot, Qt
11 from PyQt6.QtWidgets import (
12 QDialog, QDialogButtonBox, QListWidgetItem, QAbstractButton
13 )
14
15 from .Ui_EditorHighlightingStylesSelectionDialog import (
16 Ui_EditorHighlightingStylesSelectionDialog
17 )
18
19
20 class EditorHighlightingStylesSelectionDialog(
21 QDialog, Ui_EditorHighlightingStylesSelectionDialog
22 ):
23 """
24 Class implementing a dialog to select the styles to be imported/exported.
25 """
26 def __init__(self, lexerNames, forImport, preselect=None, parent=None):
27 """
28 Constructor
29
30 @param lexerNames list of lexer names to select from
31 @type list of str
32 @param forImport flag indicating a dialog for importing styles
33 @type bool
34 @param preselect list of lexer names to be preselected
35 @type list of str
36 @param parent reference to the parent widget
37 @type QWidget
38 """
39 super().__init__(parent)
40 self.setupUi(self)
41
42 self.__selectAllButton = self.buttonBox.addButton(
43 self.tr("Select All"), QDialogButtonBox.ButtonRole.ActionRole)
44
45 if forImport:
46 self.setWindowTitle(self.tr("Import Highlighting Styles"))
47 self.infoLabel.setText(self.tr(
48 "Select the highlighting styles to be imported"))
49 else:
50 self.setWindowTitle(self.tr("Export Highlighting Styles"))
51 self.infoLabel.setText(self.tr(
52 "Select the highlighting styles to be exported"))
53
54 if preselect is None:
55 preselect = []
56
57 for name in lexerNames:
58 itm = QListWidgetItem(name, self.lexersList)
59 itm.setFlags(
60 Qt.ItemFlag.ItemIsUserCheckable | Qt.ItemFlag.ItemIsEnabled)
61 if name in preselect:
62 itm.setCheckState(Qt.CheckState.Checked)
63 else:
64 itm.setCheckState(Qt.CheckState.Unchecked)
65
66 self.__updateOkButton()
67
68 @pyqtSlot()
69 def __updateOkButton(self):
70 """
71 Private slot to update the state of the OK button.
72 """
73 for row in range(self.lexersList.count()):
74 itm = self.lexersList.item(row)
75 if itm.checkState() == Qt.CheckState.Checked:
76 enable = True
77 break
78 else:
79 enable = False
80 self.buttonBox.button(
81 QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
82
83 @pyqtSlot(QListWidgetItem)
84 def on_lexersList_itemChanged(self, item):
85 """
86 Private slot to react on changes in check state.
87
88 @param item reference to the changed item
89 @type QListWidgetItem
90 """
91 self.__updateOkButton()
92
93 @pyqtSlot(QAbstractButton)
94 def on_buttonBox_clicked(self, button):
95 """
96 Private slot to handle the user pressing a button.
97
98 @param button reference to the button pressed
99 @type QAbstractButton
100 """
101 if button is self.__selectAllButton:
102 for row in range(self.lexersList.count()):
103 itm = self.lexersList.item(row)
104 itm.setCheckState(Qt.CheckState.Checked)
105
106 def getLexerNames(self):
107 """
108 Public method to get the selected lexer names.
109
110 @return list of selected lexer names
111 @rtype list of str
112 """
113 lexerNames = []
114 for row in range(self.lexersList.count()):
115 itm = self.lexersList.item(row)
116 if itm.checkState() == Qt.CheckState.Checked:
117 lexerNames.append(itm.text())
118
119 return lexerNames

eric ide

mercurial