7 Module implementing Selection Encloser configuration page. |
7 Module implementing Selection Encloser configuration page. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot, Qt |
12 from PyQt6.QtCore import pyqtSlot, Qt |
13 from PyQt5.QtWidgets import QTreeWidgetItem, QInputDialog, QLineEdit, QDialog |
13 from PyQt6.QtWidgets import QTreeWidgetItem, QInputDialog, QLineEdit, QDialog |
14 |
14 |
15 from E5Gui.E5Application import e5App |
15 from EricWidgets.EricApplication import ericApp |
16 |
16 |
17 from Preferences.ConfigurationPages.ConfigurationPageBase import ( |
17 from Preferences.ConfigurationPages.ConfigurationPageBase import ( |
18 ConfigurationPageBase |
18 ConfigurationPageBase |
19 ) |
19 ) |
20 from .Ui_SelectionEncloserPage import Ui_SelectionEncloserPage |
20 from .Ui_SelectionEncloserPage import Ui_SelectionEncloserPage |
29 def __init__(self, plugin): |
29 def __init__(self, plugin): |
30 """ |
30 """ |
31 Constructor |
31 Constructor |
32 |
32 |
33 @param plugin reference to the plugin object |
33 @param plugin reference to the plugin object |
|
34 @type SelectionEncloserPlugin |
34 """ |
35 """ |
35 super().__init__() |
36 super().__init__() |
36 self.setupUi(self) |
37 self.setupUi(self) |
37 self.setObjectName("SelectionEncloserPage") |
38 self.setObjectName("SelectionEncloserPage") |
38 |
39 |
39 try: |
40 usesDarkPalette = ericApp().usesDarkPalette() |
40 usesDarkPalette = e5App().usesDarkPalette() |
|
41 except AttributeError: |
|
42 # for eric6 < 20.4 |
|
43 from PyQt5.QtGui import QPalette |
|
44 palette = e5App().palette() |
|
45 lightness = palette.color(QPalette.Window).lightness() |
|
46 usesDarkPalette = lightness <= 128 |
|
47 iconSuffix = "dark" if usesDarkPalette else "light" |
41 iconSuffix = "dark" if usesDarkPalette else "light" |
48 |
42 |
49 self.editButton.setIcon(UI.PixmapCache.getIcon( |
43 self.editButton.setIcon(UI.PixmapCache.getIcon( |
50 os.path.join("SelectionEncloser", "icons", |
44 os.path.join("SelectionEncloser", "icons", |
51 "edit-{0}".format(iconSuffix)))) |
45 "edit-{0}".format(iconSuffix)))) |
77 top = QTreeWidgetItem(self.menuTree, [menuTitle]) |
71 top = QTreeWidgetItem(self.menuTree, [menuTitle]) |
78 for title, encString in entries: |
72 for title, encString in entries: |
79 if title == '--Separator--': |
73 if title == '--Separator--': |
80 title = self.tr('--Separator--') |
74 title = self.tr('--Separator--') |
81 itm = QTreeWidgetItem(top, [title]) |
75 itm = QTreeWidgetItem(top, [title]) |
82 itm.setData(0, Qt.UserRole, encString) |
76 itm.setData(0, Qt.ItemDataRole.UserRole, encString) |
83 top.setExpanded(True) |
77 top.setExpanded(True) |
84 |
78 |
85 def save(self): |
79 def save(self): |
86 """ |
80 """ |
87 Public slot to save the Selection Encloser configuration. |
81 Public slot to save the Selection Encloser configuration. |
96 for index in range(topItem.childCount()): |
90 for index in range(topItem.childCount()): |
97 itm = topItem.child(index) |
91 itm = topItem.child(index) |
98 title = itm.text(0) |
92 title = itm.text(0) |
99 if title == self.tr('--Separator--'): |
93 if title == self.tr('--Separator--'): |
100 title = '--Separator--' |
94 title = '--Separator--' |
101 topEntry[1].append([title, itm.data(0, Qt.UserRole)]) |
95 topEntry[1].append( |
|
96 [title, itm.data(0, Qt.ItemDataRole.UserRole)] |
|
97 ) |
102 hierarchy.append(topEntry) |
98 hierarchy.append(topEntry) |
103 self.__plugin.setPreferences("MenuHierarchy", hierarchy) |
99 self.__plugin.setPreferences("MenuHierarchy", hierarchy) |
104 |
100 |
105 @pyqtSlot() |
101 @pyqtSlot() |
106 def on_addMenuButton_clicked(self): |
102 def on_addMenuButton_clicked(self): |
109 """ |
105 """ |
110 menuTitle, ok = QInputDialog.getText( |
106 menuTitle, ok = QInputDialog.getText( |
111 self, |
107 self, |
112 self.tr("Menu Title"), |
108 self.tr("Menu Title"), |
113 self.tr("Enter menu title:"), |
109 self.tr("Enter menu title:"), |
114 QLineEdit.Normal) |
110 QLineEdit.EchoMode.Normal) |
115 if ok and menuTitle: |
111 if ok and menuTitle: |
116 top = QTreeWidgetItem(self.menuTree, [menuTitle]) |
112 top = QTreeWidgetItem(self.menuTree, [menuTitle]) |
117 top.setExpanded(True) |
113 top.setExpanded(True) |
118 |
114 |
119 @pyqtSlot() |
115 @pyqtSlot() |
121 """ |
117 """ |
122 Private slot to add a menu entry. |
118 Private slot to add a menu entry. |
123 """ |
119 """ |
124 from .SelectionEncloserEditDialog import SelectionEncloserEditDialog |
120 from .SelectionEncloserEditDialog import SelectionEncloserEditDialog |
125 dlg = SelectionEncloserEditDialog(parent=self) |
121 dlg = SelectionEncloserEditDialog(parent=self) |
126 if dlg.exec() == QDialog.Accepted: |
122 if dlg.exec() == QDialog.DialogCode.Accepted: |
127 title, encString = dlg.getData() |
123 title, encString = dlg.getData() |
128 itm = QTreeWidgetItem(self.menuTree.selectedItems()[0], [title]) |
124 itm = QTreeWidgetItem(self.menuTree.selectedItems()[0], [title]) |
129 itm.setData(0, Qt.UserRole, encString) |
125 itm.setData(0, Qt.ItemDataRole.UserRole, encString) |
130 |
126 |
131 @pyqtSlot() |
127 @pyqtSlot() |
132 def on_addSeparatorButton_clicked(self): |
128 def on_addSeparatorButton_clicked(self): |
133 """ |
129 """ |
134 Private slot to add a separator entry below the selected entry. |
130 Private slot to add a separator entry below the selected entry. |
176 |
172 |
177 def __moveSelectedEntry(self, moveUp): |
173 def __moveSelectedEntry(self, moveUp): |
178 """ |
174 """ |
179 Private method to move the selected entry up or down. |
175 Private method to move the selected entry up or down. |
180 |
176 |
181 @param moveUp flag indicating to move the entry up (boolean) |
177 @param moveUp flag indicating to move the entry up |
|
178 @type bool |
182 """ |
179 """ |
183 itm = self.menuTree.selectedItems()[0] |
180 itm = self.menuTree.selectedItems()[0] |
184 parent = itm.parent() |
181 parent = itm.parent() |
185 if parent is None: |
182 if parent is None: |
186 # top level item |
183 # top level item |
209 if parent is None: |
206 if parent is None: |
210 menuTitle, ok = QInputDialog.getText( |
207 menuTitle, ok = QInputDialog.getText( |
211 self, |
208 self, |
212 self.tr("Menu Entry"), |
209 self.tr("Menu Entry"), |
213 self.tr("Enter menu entry text:"), |
210 self.tr("Enter menu entry text:"), |
214 QLineEdit.Normal, |
211 QLineEdit.EchoMode.Normal, |
215 itm.text(0)) |
212 itm.text(0)) |
216 if ok and menuTitle: |
213 if ok and menuTitle: |
217 itm.setText(0, menuTitle) |
214 itm.setText(0, menuTitle) |
218 else: |
215 else: |
219 from .SelectionEncloserEditDialog import ( |
216 from .SelectionEncloserEditDialog import ( |
220 SelectionEncloserEditDialog |
217 SelectionEncloserEditDialog |
221 ) |
218 ) |
222 dlg = SelectionEncloserEditDialog( |
219 dlg = SelectionEncloserEditDialog( |
223 itm.text(0), itm.data(0, Qt.UserRole), self) |
220 itm.text(0), itm.data(0, Qt.ItemDataRole.UserRole), self) |
224 if dlg.exec() == QDialog.Accepted: |
221 if dlg.exec() == QDialog.DialogCode.Accepted: |
225 title, encString = dlg.getData() |
222 title, encString = dlg.getData() |
226 itm.setText(0, title) |
223 itm.setText(0, title) |
227 itm.setData(0, Qt.UserRole, encString) |
224 itm.setData(0, Qt.ItemDataRole.UserRole, encString) |
228 |
225 |
229 @pyqtSlot() |
226 @pyqtSlot() |
230 def on_menuTree_itemSelectionChanged(self): |
227 def on_menuTree_itemSelectionChanged(self): |
231 """ |
228 """ |
232 Private slot handling the selection of an item. |
229 Private slot handling the selection of an item. |