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