--- a/SelectionEncloser/ConfigurationPage/SelectionEncloserPage.py Thu Dec 30 12:58:58 2021 +0100 +++ b/SelectionEncloser/ConfigurationPage/SelectionEncloserPage.py Wed Sep 21 10:48:59 2022 +0200 @@ -14,9 +14,7 @@ from EricWidgets.EricApplication import ericApp -from Preferences.ConfigurationPages.ConfigurationPageBase import ( - ConfigurationPageBase -) +from Preferences.ConfigurationPages.ConfigurationPageBase import ConfigurationPageBase from .Ui_SelectionEncloserPage import Ui_SelectionEncloserPage import UI.PixmapCache @@ -26,56 +24,69 @@ """ Class implementing Selection Encloser configuration page. """ + def __init__(self, plugin): """ Constructor - + @param plugin reference to the plugin object @type SelectionEncloserPlugin """ super().__init__() self.setupUi(self) self.setObjectName("SelectionEncloserPage") - + usesDarkPalette = ericApp().usesDarkPalette() iconSuffix = "dark" if usesDarkPalette else "light" - - self.editButton.setIcon(UI.PixmapCache.getIcon( - os.path.join("SelectionEncloser", "icons", - "edit-{0}".format(iconSuffix)))) + + self.editButton.setIcon( + UI.PixmapCache.getIcon( + os.path.join( + "SelectionEncloser", "icons", "edit-{0}".format(iconSuffix) + ) + ) + ) self.addButton.setIcon(UI.PixmapCache.getIcon("plus")) self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus")) self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) - self.addMenuButton.setIcon(UI.PixmapCache.getIcon( - os.path.join("SelectionEncloser", "icons", - "topAdd-{0}".format(iconSuffix)))) - self.addSeparatorButton.setIcon(UI.PixmapCache.getIcon( - os.path.join("SelectionEncloser", "icons", - "separatorAdd-{0}".format(iconSuffix)))) - + self.addMenuButton.setIcon( + UI.PixmapCache.getIcon( + os.path.join( + "SelectionEncloser", "icons", "topAdd-{0}".format(iconSuffix) + ) + ) + ) + self.addSeparatorButton.setIcon( + UI.PixmapCache.getIcon( + os.path.join( + "SelectionEncloser", "icons", "separatorAdd-{0}".format(iconSuffix) + ) + ) + ) + self.editButton.setEnabled(False) self.addButton.setEnabled(False) self.addSeparatorButton.setEnabled(False) self.deleteButton.setEnabled(False) self.upButton.setEnabled(False) self.downButton.setEnabled(False) - + self.__plugin = plugin - + # set initial values hierarchy = self.__plugin.getPreferences("MenuHierarchy") for menuTitle, entries in hierarchy: - if menuTitle == '--Separator--': - menuTitle = self.tr('--Separator--') + if menuTitle == "--Separator--": + menuTitle = self.tr("--Separator--") top = QTreeWidgetItem(self.menuTree, [menuTitle]) for title, encString in entries: - if title == '--Separator--': - title = self.tr('--Separator--') + if title == "--Separator--": + title = self.tr("--Separator--") itm = QTreeWidgetItem(top, [title]) itm.setData(0, Qt.ItemDataRole.UserRole, encString) top.setExpanded(True) - + def save(self): """ Public slot to save the Selection Encloser configuration. @@ -84,20 +95,18 @@ for topIndex in range(self.menuTree.topLevelItemCount()): topItem = self.menuTree.topLevelItem(topIndex) menuTitle = topItem.text(0) - if menuTitle == self.tr('--Separator--'): - menuTitle = '--Separator--' + if menuTitle == self.tr("--Separator--"): + menuTitle = "--Separator--" topEntry = [menuTitle, []] for index in range(topItem.childCount()): itm = topItem.child(index) title = itm.text(0) - if title == self.tr('--Separator--'): - title = '--Separator--' - topEntry[1].append( - [title, itm.data(0, Qt.ItemDataRole.UserRole)] - ) + if title == self.tr("--Separator--"): + title = "--Separator--" + topEntry[1].append([title, itm.data(0, Qt.ItemDataRole.UserRole)]) hierarchy.append(topEntry) self.__plugin.setPreferences("MenuHierarchy", hierarchy) - + @pyqtSlot() def on_addMenuButton_clicked(self): """ @@ -107,23 +116,25 @@ self, self.tr("Menu Title"), self.tr("Enter menu title:"), - QLineEdit.EchoMode.Normal) + QLineEdit.EchoMode.Normal, + ) if ok and menuTitle: top = QTreeWidgetItem(self.menuTree, [menuTitle]) top.setExpanded(True) - + @pyqtSlot() def on_addButton_clicked(self): """ Private slot to add a menu entry. """ from .SelectionEncloserEditDialog import SelectionEncloserEditDialog + dlg = SelectionEncloserEditDialog(parent=self) if dlg.exec() == QDialog.DialogCode.Accepted: title, encString = dlg.getData() itm = QTreeWidgetItem(self.menuTree.selectedItems()[0], [title]) itm.setData(0, Qt.ItemDataRole.UserRole, encString) - + @pyqtSlot() def on_addSeparatorButton_clicked(self): """ @@ -131,7 +142,7 @@ """ selItm = self.menuTree.selectedItems()[0] parent = selItm.parent() - itm = QTreeWidgetItem([self.tr('--Separator--')]) + itm = QTreeWidgetItem([self.tr("--Separator--")]) if parent is None: # top level item index = self.menuTree.indexOfTopLevelItem(selItm) + 1 @@ -140,7 +151,7 @@ # sub item index = parent.indexOfChild(selItm) + 1 parent.insertChild(index, itm) - + @pyqtSlot() def on_deleteButton_clicked(self): """ @@ -155,25 +166,25 @@ index = parent.indexOfChild(itm) parent.takeChild(index) del itm - + @pyqtSlot() def on_upButton_clicked(self): """ Private slot to move an entry up. """ self.__moveSelectedEntry(True) - + @pyqtSlot() def on_downButton_clicked(self): """ Private slot to move an entry down. """ self.__moveSelectedEntry(False) - + def __moveSelectedEntry(self, moveUp): """ Private method to move the selected entry up or down. - + @param moveUp flag indicating to move the entry up @type bool """ @@ -195,7 +206,7 @@ for sitm in self.menuTree.selectedItems(): sitm.setSelected(False) itm.setSelected(True) - + @pyqtSlot() def on_editButton_clicked(self): """ @@ -209,20 +220,21 @@ self.tr("Menu Entry"), self.tr("Enter menu entry text:"), QLineEdit.EchoMode.Normal, - itm.text(0)) + itm.text(0), + ) if ok and menuTitle: itm.setText(0, menuTitle) else: - from .SelectionEncloserEditDialog import ( - SelectionEncloserEditDialog + from .SelectionEncloserEditDialog import SelectionEncloserEditDialog + + dlg = SelectionEncloserEditDialog( + itm.text(0), itm.data(0, Qt.ItemDataRole.UserRole), self ) - dlg = SelectionEncloserEditDialog( - itm.text(0), itm.data(0, Qt.ItemDataRole.UserRole), self) if dlg.exec() == QDialog.DialogCode.Accepted: title, encString = dlg.getData() itm.setText(0, title) itm.setData(0, Qt.ItemDataRole.UserRole, encString) - + @pyqtSlot() def on_menuTree_itemSelectionChanged(self): """ @@ -246,8 +258,8 @@ if self.menuTree.indexOfTopLevelItem(itm) == 0: upEnable = False if ( - self.menuTree.indexOfTopLevelItem(itm) == - self.menuTree.topLevelItemCount() - 1 + self.menuTree.indexOfTopLevelItem(itm) + == self.menuTree.topLevelItemCount() - 1 ): downEnable = False else: