12 from PyQt6.QtCore import pyqtSlot, Qt |
12 from PyQt6.QtCore import pyqtSlot, Qt |
13 from PyQt6.QtWidgets import QTreeWidgetItem, QInputDialog, QLineEdit, QDialog |
13 from PyQt6.QtWidgets import QTreeWidgetItem, QInputDialog, QLineEdit, QDialog |
14 |
14 |
15 from EricWidgets.EricApplication import ericApp |
15 from EricWidgets.EricApplication import ericApp |
16 |
16 |
17 from Preferences.ConfigurationPages.ConfigurationPageBase import ( |
17 from Preferences.ConfigurationPages.ConfigurationPageBase import ConfigurationPageBase |
18 ConfigurationPageBase |
|
19 ) |
|
20 from .Ui_SelectionEncloserPage import Ui_SelectionEncloserPage |
18 from .Ui_SelectionEncloserPage import Ui_SelectionEncloserPage |
21 |
19 |
22 import UI.PixmapCache |
20 import UI.PixmapCache |
23 |
21 |
24 |
22 |
25 class SelectionEncloserPage(ConfigurationPageBase, Ui_SelectionEncloserPage): |
23 class SelectionEncloserPage(ConfigurationPageBase, Ui_SelectionEncloserPage): |
26 """ |
24 """ |
27 Class implementing Selection Encloser configuration page. |
25 Class implementing Selection Encloser configuration page. |
28 """ |
26 """ |
|
27 |
29 def __init__(self, plugin): |
28 def __init__(self, plugin): |
30 """ |
29 """ |
31 Constructor |
30 Constructor |
32 |
31 |
33 @param plugin reference to the plugin object |
32 @param plugin reference to the plugin object |
34 @type SelectionEncloserPlugin |
33 @type SelectionEncloserPlugin |
35 """ |
34 """ |
36 super().__init__() |
35 super().__init__() |
37 self.setupUi(self) |
36 self.setupUi(self) |
38 self.setObjectName("SelectionEncloserPage") |
37 self.setObjectName("SelectionEncloserPage") |
39 |
38 |
40 usesDarkPalette = ericApp().usesDarkPalette() |
39 usesDarkPalette = ericApp().usesDarkPalette() |
41 iconSuffix = "dark" if usesDarkPalette else "light" |
40 iconSuffix = "dark" if usesDarkPalette else "light" |
42 |
41 |
43 self.editButton.setIcon(UI.PixmapCache.getIcon( |
42 self.editButton.setIcon( |
44 os.path.join("SelectionEncloser", "icons", |
43 UI.PixmapCache.getIcon( |
45 "edit-{0}".format(iconSuffix)))) |
44 os.path.join( |
|
45 "SelectionEncloser", "icons", "edit-{0}".format(iconSuffix) |
|
46 ) |
|
47 ) |
|
48 ) |
46 self.addButton.setIcon(UI.PixmapCache.getIcon("plus")) |
49 self.addButton.setIcon(UI.PixmapCache.getIcon("plus")) |
47 self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus")) |
50 self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus")) |
48 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
51 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
49 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
52 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
50 self.addMenuButton.setIcon(UI.PixmapCache.getIcon( |
53 self.addMenuButton.setIcon( |
51 os.path.join("SelectionEncloser", "icons", |
54 UI.PixmapCache.getIcon( |
52 "topAdd-{0}".format(iconSuffix)))) |
55 os.path.join( |
53 self.addSeparatorButton.setIcon(UI.PixmapCache.getIcon( |
56 "SelectionEncloser", "icons", "topAdd-{0}".format(iconSuffix) |
54 os.path.join("SelectionEncloser", "icons", |
57 ) |
55 "separatorAdd-{0}".format(iconSuffix)))) |
58 ) |
56 |
59 ) |
|
60 self.addSeparatorButton.setIcon( |
|
61 UI.PixmapCache.getIcon( |
|
62 os.path.join( |
|
63 "SelectionEncloser", "icons", "separatorAdd-{0}".format(iconSuffix) |
|
64 ) |
|
65 ) |
|
66 ) |
|
67 |
57 self.editButton.setEnabled(False) |
68 self.editButton.setEnabled(False) |
58 self.addButton.setEnabled(False) |
69 self.addButton.setEnabled(False) |
59 self.addSeparatorButton.setEnabled(False) |
70 self.addSeparatorButton.setEnabled(False) |
60 self.deleteButton.setEnabled(False) |
71 self.deleteButton.setEnabled(False) |
61 self.upButton.setEnabled(False) |
72 self.upButton.setEnabled(False) |
62 self.downButton.setEnabled(False) |
73 self.downButton.setEnabled(False) |
63 |
74 |
64 self.__plugin = plugin |
75 self.__plugin = plugin |
65 |
76 |
66 # set initial values |
77 # set initial values |
67 hierarchy = self.__plugin.getPreferences("MenuHierarchy") |
78 hierarchy = self.__plugin.getPreferences("MenuHierarchy") |
68 for menuTitle, entries in hierarchy: |
79 for menuTitle, entries in hierarchy: |
69 if menuTitle == '--Separator--': |
80 if menuTitle == "--Separator--": |
70 menuTitle = self.tr('--Separator--') |
81 menuTitle = self.tr("--Separator--") |
71 top = QTreeWidgetItem(self.menuTree, [menuTitle]) |
82 top = QTreeWidgetItem(self.menuTree, [menuTitle]) |
72 for title, encString in entries: |
83 for title, encString in entries: |
73 if title == '--Separator--': |
84 if title == "--Separator--": |
74 title = self.tr('--Separator--') |
85 title = self.tr("--Separator--") |
75 itm = QTreeWidgetItem(top, [title]) |
86 itm = QTreeWidgetItem(top, [title]) |
76 itm.setData(0, Qt.ItemDataRole.UserRole, encString) |
87 itm.setData(0, Qt.ItemDataRole.UserRole, encString) |
77 top.setExpanded(True) |
88 top.setExpanded(True) |
78 |
89 |
79 def save(self): |
90 def save(self): |
80 """ |
91 """ |
81 Public slot to save the Selection Encloser configuration. |
92 Public slot to save the Selection Encloser configuration. |
82 """ |
93 """ |
83 hierarchy = [] |
94 hierarchy = [] |
84 for topIndex in range(self.menuTree.topLevelItemCount()): |
95 for topIndex in range(self.menuTree.topLevelItemCount()): |
85 topItem = self.menuTree.topLevelItem(topIndex) |
96 topItem = self.menuTree.topLevelItem(topIndex) |
86 menuTitle = topItem.text(0) |
97 menuTitle = topItem.text(0) |
87 if menuTitle == self.tr('--Separator--'): |
98 if menuTitle == self.tr("--Separator--"): |
88 menuTitle = '--Separator--' |
99 menuTitle = "--Separator--" |
89 topEntry = [menuTitle, []] |
100 topEntry = [menuTitle, []] |
90 for index in range(topItem.childCount()): |
101 for index in range(topItem.childCount()): |
91 itm = topItem.child(index) |
102 itm = topItem.child(index) |
92 title = itm.text(0) |
103 title = itm.text(0) |
93 if title == self.tr('--Separator--'): |
104 if title == self.tr("--Separator--"): |
94 title = '--Separator--' |
105 title = "--Separator--" |
95 topEntry[1].append( |
106 topEntry[1].append([title, itm.data(0, Qt.ItemDataRole.UserRole)]) |
96 [title, itm.data(0, Qt.ItemDataRole.UserRole)] |
|
97 ) |
|
98 hierarchy.append(topEntry) |
107 hierarchy.append(topEntry) |
99 self.__plugin.setPreferences("MenuHierarchy", hierarchy) |
108 self.__plugin.setPreferences("MenuHierarchy", hierarchy) |
100 |
109 |
101 @pyqtSlot() |
110 @pyqtSlot() |
102 def on_addMenuButton_clicked(self): |
111 def on_addMenuButton_clicked(self): |
103 """ |
112 """ |
104 Private slot to add a top level menu item. |
113 Private slot to add a top level menu item. |
105 """ |
114 """ |
106 menuTitle, ok = QInputDialog.getText( |
115 menuTitle, ok = QInputDialog.getText( |
107 self, |
116 self, |
108 self.tr("Menu Title"), |
117 self.tr("Menu Title"), |
109 self.tr("Enter menu title:"), |
118 self.tr("Enter menu title:"), |
110 QLineEdit.EchoMode.Normal) |
119 QLineEdit.EchoMode.Normal, |
|
120 ) |
111 if ok and menuTitle: |
121 if ok and menuTitle: |
112 top = QTreeWidgetItem(self.menuTree, [menuTitle]) |
122 top = QTreeWidgetItem(self.menuTree, [menuTitle]) |
113 top.setExpanded(True) |
123 top.setExpanded(True) |
114 |
124 |
115 @pyqtSlot() |
125 @pyqtSlot() |
116 def on_addButton_clicked(self): |
126 def on_addButton_clicked(self): |
117 """ |
127 """ |
118 Private slot to add a menu entry. |
128 Private slot to add a menu entry. |
119 """ |
129 """ |
120 from .SelectionEncloserEditDialog import SelectionEncloserEditDialog |
130 from .SelectionEncloserEditDialog import SelectionEncloserEditDialog |
|
131 |
121 dlg = SelectionEncloserEditDialog(parent=self) |
132 dlg = SelectionEncloserEditDialog(parent=self) |
122 if dlg.exec() == QDialog.DialogCode.Accepted: |
133 if dlg.exec() == QDialog.DialogCode.Accepted: |
123 title, encString = dlg.getData() |
134 title, encString = dlg.getData() |
124 itm = QTreeWidgetItem(self.menuTree.selectedItems()[0], [title]) |
135 itm = QTreeWidgetItem(self.menuTree.selectedItems()[0], [title]) |
125 itm.setData(0, Qt.ItemDataRole.UserRole, encString) |
136 itm.setData(0, Qt.ItemDataRole.UserRole, encString) |
126 |
137 |
127 @pyqtSlot() |
138 @pyqtSlot() |
128 def on_addSeparatorButton_clicked(self): |
139 def on_addSeparatorButton_clicked(self): |
129 """ |
140 """ |
130 Private slot to add a separator entry below the selected entry. |
141 Private slot to add a separator entry below the selected entry. |
131 """ |
142 """ |
132 selItm = self.menuTree.selectedItems()[0] |
143 selItm = self.menuTree.selectedItems()[0] |
133 parent = selItm.parent() |
144 parent = selItm.parent() |
134 itm = QTreeWidgetItem([self.tr('--Separator--')]) |
145 itm = QTreeWidgetItem([self.tr("--Separator--")]) |
135 if parent is None: |
146 if parent is None: |
136 # top level item |
147 # top level item |
137 index = self.menuTree.indexOfTopLevelItem(selItm) + 1 |
148 index = self.menuTree.indexOfTopLevelItem(selItm) + 1 |
138 self.menuTree.insertTopLevelItem(index, itm) |
149 self.menuTree.insertTopLevelItem(index, itm) |
139 else: |
150 else: |
140 # sub item |
151 # sub item |
141 index = parent.indexOfChild(selItm) + 1 |
152 index = parent.indexOfChild(selItm) + 1 |
142 parent.insertChild(index, itm) |
153 parent.insertChild(index, itm) |
143 |
154 |
144 @pyqtSlot() |
155 @pyqtSlot() |
145 def on_deleteButton_clicked(self): |
156 def on_deleteButton_clicked(self): |
146 """ |
157 """ |
147 Private slot to delete the selected entry. |
158 Private slot to delete the selected entry. |
148 """ |
159 """ |