PrintRemover/ConfigurationPage/PrintRemoverPage.py

branch
eric7
changeset 62
81f446717433
parent 59
79247c15c319
child 63
273252fd0d99
equal deleted inserted replaced
61:062648cf83d8 62:81f446717433
12 from PyQt6.QtCore import pyqtSlot 12 from PyQt6.QtCore import pyqtSlot
13 from PyQt6.QtWidgets import QListWidgetItem, QInputDialog, QLineEdit 13 from PyQt6.QtWidgets import QListWidgetItem, QInputDialog, QLineEdit
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_PrintRemoverPage import Ui_PrintRemoverPage 18 from .Ui_PrintRemoverPage import Ui_PrintRemoverPage
21 19
22 import UI.PixmapCache 20 import UI.PixmapCache
23 21
24 22
25 class PrintRemoverPage(ConfigurationPageBase, Ui_PrintRemoverPage): 23 class PrintRemoverPage(ConfigurationPageBase, Ui_PrintRemoverPage):
26 """ 24 """
27 Class implementing the Print Remover configuration page. 25 Class implementing the Print Remover 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 PrintRemoverPlugin 33 @type PrintRemoverPlugin
35 """ 34 """
36 super().__init__() 35 super().__init__()
37 self.setupUi(self) 36 self.setupUi(self)
38 self.setObjectName("PrintRemoverPage") 37 self.setObjectName("PrintRemoverPage")
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("PrintRemover", "icons", 43 UI.PixmapCache.getIcon(
45 "edit-{0}".format(iconSuffix)))) 44 os.path.join("PrintRemover", "icons", "edit-{0}".format(iconSuffix))
45 )
46 )
46 self.addButton.setIcon(UI.PixmapCache.getIcon("plus")) 47 self.addButton.setIcon(UI.PixmapCache.getIcon("plus"))
47 self.addSeparatorButton.setIcon(UI.PixmapCache.getIcon( 48 self.addSeparatorButton.setIcon(
48 os.path.join("PrintRemover", "icons", 49 UI.PixmapCache.getIcon(
49 "separatorAdd-{0}".format(iconSuffix)))) 50 os.path.join(
51 "PrintRemover", "icons", "separatorAdd-{0}".format(iconSuffix)
52 )
53 )
54 )
50 self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus")) 55 self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus"))
51 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) 56 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow"))
52 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) 57 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow"))
53 58
54 self.editButton.setEnabled(False) 59 self.editButton.setEnabled(False)
55 self.deleteButton.setEnabled(False) 60 self.deleteButton.setEnabled(False)
56 self.upButton.setEnabled(False) 61 self.upButton.setEnabled(False)
57 self.downButton.setEnabled(False) 62 self.downButton.setEnabled(False)
58 63
59 self.__plugin = plugin 64 self.__plugin = plugin
60 65
61 # set initial values 66 # set initial values
62 for pattern in self.__plugin.getPreferences("StartswithStrings"): 67 for pattern in self.__plugin.getPreferences("StartswithStrings"):
63 if pattern == "--Separator--": 68 if pattern == "--Separator--":
64 pattern = self.tr("--Separator--") 69 pattern = self.tr("--Separator--")
65 QListWidgetItem(pattern, self.patternList) 70 QListWidgetItem(pattern, self.patternList)
66 71
67 def save(self): 72 def save(self):
68 """ 73 """
69 Public slot to save the Print Remover configuration. 74 Public slot to save the Print Remover configuration.
70 """ 75 """
71 patterns = [] 76 patterns = []
74 pattern = itm.text() 79 pattern = itm.text()
75 if pattern == self.tr("--Separator--"): 80 if pattern == self.tr("--Separator--"):
76 pattern = "--Separator--" 81 pattern = "--Separator--"
77 patterns.append(pattern) 82 patterns.append(pattern)
78 self.__plugin.setPreferences("StartswithStrings", patterns) 83 self.__plugin.setPreferences("StartswithStrings", patterns)
79 84
80 @pyqtSlot() 85 @pyqtSlot()
81 def on_patternList_itemSelectionChanged(self): 86 def on_patternList_itemSelectionChanged(self):
82 """ 87 """
83 Private slot to handle the selection of patterns. 88 Private slot to handle the selection of patterns.
84 """ 89 """
91 itm = self.patternList.selectedItems()[0] 96 itm = self.patternList.selectedItems()[0]
92 self.editButton.setEnabled(itm.text() != self.tr("--Separator--")) 97 self.editButton.setEnabled(itm.text() != self.tr("--Separator--"))
93 self.deleteButton.setEnabled(True) 98 self.deleteButton.setEnabled(True)
94 self.upButton.setEnabled(self.patternList.row(itm) > 0) 99 self.upButton.setEnabled(self.patternList.row(itm) > 0)
95 self.downButton.setEnabled( 100 self.downButton.setEnabled(
96 self.patternList.row(itm) < self.patternList.count() - 1) 101 self.patternList.row(itm) < self.patternList.count() - 1
97 102 )
103
98 @pyqtSlot() 104 @pyqtSlot()
99 def on_editButton_clicked(self): 105 def on_editButton_clicked(self):
100 """ 106 """
101 Private slot to edit the selected entry. 107 Private slot to edit the selected entry.
102 """ 108 """
104 pattern, ok = QInputDialog.getText( 110 pattern, ok = QInputDialog.getText(
105 self, 111 self,
106 self.tr("Line Start Pattern"), 112 self.tr("Line Start Pattern"),
107 self.tr("Enter a line start pattern:"), 113 self.tr("Enter a line start pattern:"),
108 QLineEdit.EchoMode.Normal, 114 QLineEdit.EchoMode.Normal,
109 itm.text()) 115 itm.text(),
116 )
110 if ok and pattern: 117 if ok and pattern:
111 itm.setText(pattern) 118 itm.setText(pattern)
112 119
113 @pyqtSlot() 120 @pyqtSlot()
114 def on_addButton_clicked(self): 121 def on_addButton_clicked(self):
115 """ 122 """
116 Private slot add a pattern to the list. 123 Private slot add a pattern to the list.
117 """ 124 """
118 pattern, ok = QInputDialog.getText( 125 pattern, ok = QInputDialog.getText(
119 self, 126 self,
120 self.tr("Line Start Pattern"), 127 self.tr("Line Start Pattern"),
121 self.tr("Enter a line start pattern:"), 128 self.tr("Enter a line start pattern:"),
122 QLineEdit.EchoMode.Normal) 129 QLineEdit.EchoMode.Normal,
130 )
123 if ok and pattern: 131 if ok and pattern:
124 itm = QListWidgetItem(pattern) 132 itm = QListWidgetItem(pattern)
125 if len(self.patternList.selectedItems()): 133 if len(self.patternList.selectedItems()):
126 row = self.patternList.row( 134 row = self.patternList.row(self.patternList.selectedItems()[0]) + 1
127 self.patternList.selectedItems()[0]) + 1
128 self.patternList.insertItem(row, itm) 135 self.patternList.insertItem(row, itm)
129 for sitm in self.patternList.selectedItems(): 136 for sitm in self.patternList.selectedItems():
130 sitm.setSelected(False) 137 sitm.setSelected(False)
131 else: 138 else:
132 self.patternList.addItem(itm) 139 self.patternList.addItem(itm)
133 itm.setSelected(True) 140 itm.setSelected(True)
134 141
135 @pyqtSlot() 142 @pyqtSlot()
136 def on_addSeparatorButton_clicked(self): 143 def on_addSeparatorButton_clicked(self):
137 """ 144 """
138 Private slot add a separator to the list. 145 Private slot add a separator to the list.
139 """ 146 """
140 itm = QListWidgetItem(self.tr("--Separator--")) 147 itm = QListWidgetItem(self.tr("--Separator--"))
141 if len(self.patternList.selectedItems()): 148 if len(self.patternList.selectedItems()):
142 row = self.patternList.row( 149 row = self.patternList.row(self.patternList.selectedItems()[0]) + 1
143 self.patternList.selectedItems()[0]) + 1
144 self.patternList.insertItem(row, itm) 150 self.patternList.insertItem(row, itm)
145 for sitm in self.patternList.selectedItems(): 151 for sitm in self.patternList.selectedItems():
146 sitm.setSelected(False) 152 sitm.setSelected(False)
147 else: 153 else:
148 self.patternList.addItem(itm) 154 self.patternList.addItem(itm)
149 itm.setSelected(True) 155 itm.setSelected(True)
150 156
151 @pyqtSlot() 157 @pyqtSlot()
152 def on_deleteButton_clicked(self): 158 def on_deleteButton_clicked(self):
153 """ 159 """
154 Private slot to delete the selected entry. 160 Private slot to delete the selected entry.
155 """ 161 """
156 itm = self.patternList.selectedItems()[0] 162 itm = self.patternList.selectedItems()[0]
157 self.patternList.takeItem(self.patternList.row(itm)) 163 self.patternList.takeItem(self.patternList.row(itm))
158 del itm 164 del itm
159 165
160 @pyqtSlot() 166 @pyqtSlot()
161 def on_upButton_clicked(self): 167 def on_upButton_clicked(self):
162 """ 168 """
163 Private slot to move an entry up. 169 Private slot to move an entry up.
164 """ 170 """
165 self.__moveSelectedEntry(True) 171 self.__moveSelectedEntry(True)
166 172
167 @pyqtSlot() 173 @pyqtSlot()
168 def on_downButton_clicked(self): 174 def on_downButton_clicked(self):
169 """ 175 """
170 Private slot to move an entry down. 176 Private slot to move an entry down.
171 """ 177 """
172 self.__moveSelectedEntry(False) 178 self.__moveSelectedEntry(False)
173 179
174 def __moveSelectedEntry(self, moveUp): 180 def __moveSelectedEntry(self, moveUp):
175 """ 181 """
176 Private method to move the selected entry up or down. 182 Private method to move the selected entry up or down.
177 183
178 @param moveUp flag indicating to move the entry up 184 @param moveUp flag indicating to move the entry up
179 @type bool 185 @type bool
180 """ 186 """
181 itm = self.patternList.selectedItems()[0] 187 itm = self.patternList.selectedItems()[0]
182 row = self.patternList.row(itm) 188 row = self.patternList.row(itm)

eric ide

mercurial