src/eric7/Preferences/ToolConfigurationDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
22 22
23 class ToolConfigurationDialog(QDialog, Ui_ToolConfigurationDialog): 23 class ToolConfigurationDialog(QDialog, Ui_ToolConfigurationDialog):
24 """ 24 """
25 Class implementing a configuration dialog for the tools menu. 25 Class implementing a configuration dialog for the tools menu.
26 """ 26 """
27
27 def __init__(self, toollist, parent=None): 28 def __init__(self, toollist, parent=None):
28 """ 29 """
29 Constructor 30 Constructor
30 31
31 @param toollist list of configured tools 32 @param toollist list of configured tools
32 @param parent parent widget (QWidget) 33 @param parent parent widget (QWidget)
33 """ 34 """
34 super().__init__(parent) 35 super().__init__(parent)
35 self.setupUi(self) 36 self.setupUi(self)
36 37
37 self.iconPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) 38 self.iconPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
38 self.iconPicker.setFilters(self.tr("Icon files (*.png)")) 39 self.iconPicker.setFilters(self.tr("Icon files (*.png)"))
39 self.executablePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) 40 self.executablePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
40 41
41 self.redirectionModes = [ 42 self.redirectionModes = [
42 ("no", self.tr("no redirection")), 43 ("no", self.tr("no redirection")),
43 ("show", self.tr("show output")), 44 ("show", self.tr("show output")),
44 ("insert", self.tr("insert into current editor")), 45 ("insert", self.tr("insert into current editor")),
45 ("replaceSelection", 46 ("replaceSelection", self.tr("replace selection of current editor")),
46 self.tr("replace selection of current editor")),
47 ] 47 ]
48 48
49 self.toollist = copy.deepcopy(toollist) 49 self.toollist = copy.deepcopy(toollist)
50 for tool in toollist: 50 for tool in toollist:
51 self.toolsList.addItem(tool['menutext']) 51 self.toolsList.addItem(tool["menutext"])
52 52
53 for mode in self.redirectionModes: 53 for mode in self.redirectionModes:
54 self.redirectCombo.addItem(mode[1]) 54 self.redirectCombo.addItem(mode[1])
55 55
56 if len(toollist): 56 if len(toollist):
57 self.toolsList.setCurrentRow(0) 57 self.toolsList.setCurrentRow(0)
58 self.on_toolsList_currentRowChanged(0) 58 self.on_toolsList_currentRowChanged(0)
59 59
60 t = self.argumentsEdit.whatsThis() 60 t = self.argumentsEdit.whatsThis()
61 if t: 61 if t:
62 t += Utilities.getPercentReplacementHelp() 62 t += Utilities.getPercentReplacementHelp()
63 self.argumentsEdit.setWhatsThis(t) 63 self.argumentsEdit.setWhatsThis(t)
64 64
65 def __findModeIndex(self, shortName): 65 def __findModeIndex(self, shortName):
66 """ 66 """
67 Private method to find the mode index by its short name. 67 Private method to find the mode index by its short name.
68 68
69 @param shortName short name of the mode (string) 69 @param shortName short name of the mode (string)
70 @return index of the mode (integer) 70 @return index of the mode (integer)
71 """ 71 """
72 for ind, mode in enumerate(self.redirectionModes): 72 for ind, mode in enumerate(self.redirectionModes):
73 if mode[0] == shortName: 73 if mode[0] == shortName:
74 return ind 74 return ind
75 return 1 # default is "show output" 75 return 1 # default is "show output"
76 76
77 @pyqtSlot() 77 @pyqtSlot()
78 def on_newButton_clicked(self): 78 def on_newButton_clicked(self):
79 """ 79 """
80 Private slot to clear all entry fields. 80 Private slot to clear all entry fields.
81 """ 81 """
82 self.executablePicker.clear() 82 self.executablePicker.clear()
83 self.menuEdit.clear() 83 self.menuEdit.clear()
84 self.iconPicker.clear() 84 self.iconPicker.clear()
85 self.argumentsEdit.clear() 85 self.argumentsEdit.clear()
86 self.redirectCombo.setCurrentIndex(1) 86 self.redirectCombo.setCurrentIndex(1)
87 87
88 @pyqtSlot() 88 @pyqtSlot()
89 def on_addButton_clicked(self): 89 def on_addButton_clicked(self):
90 """ 90 """
91 Private slot to add a new entry. 91 Private slot to add a new entry.
92 """ 92 """
93 menutext = self.menuEdit.text() 93 menutext = self.menuEdit.text()
94 icon = self.iconPicker.text() 94 icon = self.iconPicker.text()
95 executable = self.executablePicker.text() 95 executable = self.executablePicker.text()
96 arguments = self.argumentsEdit.text() 96 arguments = self.argumentsEdit.text()
97 redirect = self.redirectionModes[self.redirectCombo.currentIndex()][0] 97 redirect = self.redirectionModes[self.redirectCombo.currentIndex()][0]
98 98
99 if not executable: 99 if not executable:
100 EricMessageBox.critical( 100 EricMessageBox.critical(
101 self, 101 self,
102 self.tr("Add tool entry"), 102 self.tr("Add tool entry"),
103 self.tr( 103 self.tr(
104 "You have to set an executable to add to the" 104 "You have to set an executable to add to the" " Tools-Menu first."
105 " Tools-Menu first.")) 105 ),
106 return 106 )
107 107 return
108
108 if not menutext: 109 if not menutext:
109 EricMessageBox.critical( 110 EricMessageBox.critical(
110 self, 111 self,
111 self.tr("Add tool entry"), 112 self.tr("Add tool entry"),
112 self.tr( 113 self.tr(
113 "You have to insert a menuentry text to add the" 114 "You have to insert a menuentry text to add the"
114 " selected program to the Tools-Menu first.")) 115 " selected program to the Tools-Menu first."
115 return 116 ),
116 117 )
118 return
119
117 if not Utilities.isinpath(executable): 120 if not Utilities.isinpath(executable):
118 EricMessageBox.critical( 121 EricMessageBox.critical(
119 self, 122 self,
120 self.tr("Add tool entry"), 123 self.tr("Add tool entry"),
121 self.tr( 124 self.tr(
122 "The selected file could not be found or" 125 "The selected file could not be found or"
123 " is not an executable." 126 " is not an executable."
124 " Please choose an executable filename.")) 127 " Please choose an executable filename."
125 return 128 ),
126 129 )
127 if len(self.toolsList.findItems( 130 return
128 menutext, Qt.MatchFlag.MatchExactly)): 131
132 if len(self.toolsList.findItems(menutext, Qt.MatchFlag.MatchExactly)):
129 EricMessageBox.critical( 133 EricMessageBox.critical(
130 self, 134 self,
131 self.tr("Add tool entry"), 135 self.tr("Add tool entry"),
132 self.tr("An entry for the menu text {0} already exists.") 136 self.tr("An entry for the menu text {0} already exists.").format(
133 .format(menutext)) 137 menutext
134 return 138 ),
135 139 )
140 return
141
136 self.toolsList.addItem(menutext) 142 self.toolsList.addItem(menutext)
137 tool = { 143 tool = {
138 'menutext': menutext, 144 "menutext": menutext,
139 'icon': icon, 145 "icon": icon,
140 'executable': executable, 146 "executable": executable,
141 'arguments': arguments, 147 "arguments": arguments,
142 'redirect': redirect, 148 "redirect": redirect,
143 } 149 }
144 self.toollist.append(tool) 150 self.toollist.append(tool)
145 151
146 @pyqtSlot() 152 @pyqtSlot()
147 def on_changeButton_clicked(self): 153 def on_changeButton_clicked(self):
148 """ 154 """
149 Private slot to change an entry. 155 Private slot to change an entry.
150 """ 156 """
151 row = self.toolsList.currentRow() 157 row = self.toolsList.currentRow()
152 if row < 0: 158 if row < 0:
153 return 159 return
154 160
155 menutext = self.menuEdit.text() 161 menutext = self.menuEdit.text()
156 icon = self.iconPicker.text() 162 icon = self.iconPicker.text()
157 executable = self.executablePicker.text() 163 executable = self.executablePicker.text()
158 arguments = self.argumentsEdit.text() 164 arguments = self.argumentsEdit.text()
159 redirect = self.redirectionModes[self.redirectCombo.currentIndex()][0] 165 redirect = self.redirectionModes[self.redirectCombo.currentIndex()][0]
160 166
161 if not executable: 167 if not executable:
162 EricMessageBox.critical( 168 EricMessageBox.critical(
163 self, 169 self,
164 self.tr("Change tool entry"), 170 self.tr("Change tool entry"),
165 self.tr( 171 self.tr(
166 "You have to set an executable to change the" 172 "You have to set an executable to change the" " Tools-Menu entry."
167 " Tools-Menu entry.")) 173 ),
168 return 174 )
169 175 return
176
170 if not menutext: 177 if not menutext:
171 EricMessageBox.critical( 178 EricMessageBox.critical(
172 self, 179 self,
173 self.tr("Change tool entry"), 180 self.tr("Change tool entry"),
174 self.tr( 181 self.tr(
175 "You have to insert a menuentry text to change the" 182 "You have to insert a menuentry text to change the"
176 " selected Tools-Menu entry.")) 183 " selected Tools-Menu entry."
177 return 184 ),
178 185 )
186 return
187
179 if not Utilities.isinpath(executable): 188 if not Utilities.isinpath(executable):
180 EricMessageBox.critical( 189 EricMessageBox.critical(
181 self, 190 self,
182 self.tr("Change tool entry"), 191 self.tr("Change tool entry"),
183 self.tr( 192 self.tr(
184 "The selected file could not be found or" 193 "The selected file could not be found or"
185 " is not an executable." 194 " is not an executable."
186 " Please choose an existing executable filename.")) 195 " Please choose an existing executable filename."
187 return 196 ),
188 197 )
198 return
199
189 self.toollist[row] = { 200 self.toollist[row] = {
190 'menutext': menutext, 201 "menutext": menutext,
191 'icon': icon, 202 "icon": icon,
192 'executable': executable, 203 "executable": executable,
193 'arguments': arguments, 204 "arguments": arguments,
194 'redirect': redirect, 205 "redirect": redirect,
195 } 206 }
196 self.toolsList.currentItem().setText(menutext) 207 self.toolsList.currentItem().setText(menutext)
197 self.changeButton.setEnabled(False) 208 self.changeButton.setEnabled(False)
198 209
199 @pyqtSlot() 210 @pyqtSlot()
200 def on_deleteButton_clicked(self): 211 def on_deleteButton_clicked(self):
201 """ 212 """
202 Private slot to delete the selected entry. 213 Private slot to delete the selected entry.
203 """ 214 """
204 row = self.toolsList.currentRow() 215 row = self.toolsList.currentRow()
205 if row < 0: 216 if row < 0:
206 return 217 return
207 218
208 del self.toollist[row] 219 del self.toollist[row]
209 itm = self.toolsList.takeItem(row) 220 itm = self.toolsList.takeItem(row)
210 del itm 221 del itm
211 if row >= len(self.toollist): 222 if row >= len(self.toollist):
212 row -= 1 223 row -= 1
213 self.toolsList.setCurrentRow(row) 224 self.toolsList.setCurrentRow(row)
214 self.on_toolsList_currentRowChanged(row) 225 self.on_toolsList_currentRowChanged(row)
215 226
216 @pyqtSlot() 227 @pyqtSlot()
217 def on_downButton_clicked(self): 228 def on_downButton_clicked(self):
218 """ 229 """
219 Private slot to move an entry down in the list. 230 Private slot to move an entry down in the list.
220 """ 231 """
221 curr = self.toolsList.currentRow() 232 curr = self.toolsList.currentRow()
222 self.__swap(curr, curr + 1) 233 self.__swap(curr, curr + 1)
223 self.toolsList.clear() 234 self.toolsList.clear()
224 for tool in self.toollist: 235 for tool in self.toollist:
225 self.toolsList.addItem(tool['menutext']) 236 self.toolsList.addItem(tool["menutext"])
226 self.toolsList.setCurrentRow(curr + 1) 237 self.toolsList.setCurrentRow(curr + 1)
227 if curr + 1 == len(self.toollist): 238 if curr + 1 == len(self.toollist):
228 self.downButton.setEnabled(False) 239 self.downButton.setEnabled(False)
229 self.upButton.setEnabled(True) 240 self.upButton.setEnabled(True)
230 241
231 @pyqtSlot() 242 @pyqtSlot()
232 def on_upButton_clicked(self): 243 def on_upButton_clicked(self):
233 """ 244 """
234 Private slot to move an entry up in the list. 245 Private slot to move an entry up in the list.
235 """ 246 """
236 curr = self.toolsList.currentRow() 247 curr = self.toolsList.currentRow()
237 self.__swap(curr - 1, curr) 248 self.__swap(curr - 1, curr)
238 self.toolsList.clear() 249 self.toolsList.clear()
239 for tool in self.toollist: 250 for tool in self.toollist:
240 self.toolsList.addItem(tool['menutext']) 251 self.toolsList.addItem(tool["menutext"])
241 self.toolsList.setCurrentRow(curr - 1) 252 self.toolsList.setCurrentRow(curr - 1)
242 if curr - 1 == 0: 253 if curr - 1 == 0:
243 self.upButton.setEnabled(False) 254 self.upButton.setEnabled(False)
244 self.downButton.setEnabled(True) 255 self.downButton.setEnabled(True)
245 256
246 @pyqtSlot() 257 @pyqtSlot()
247 def on_separatorButton_clicked(self): 258 def on_separatorButton_clicked(self):
248 """ 259 """
249 Private slot to add a menu separator. 260 Private slot to add a menu separator.
250 """ 261 """
251 self.toolsList.addItem('--') 262 self.toolsList.addItem("--")
252 tool = { 263 tool = {
253 'menutext': '--', 264 "menutext": "--",
254 'icon': '', 265 "icon": "",
255 'executable': '', 266 "executable": "",
256 'arguments': '', 267 "arguments": "",
257 'redirect': 'no', 268 "redirect": "no",
258 } 269 }
259 self.toollist.append(tool) 270 self.toollist.append(tool)
260 271
261 @pyqtSlot(str) 272 @pyqtSlot(str)
262 def on_executablePicker_pathSelected(self, path): 273 def on_executablePicker_pathSelected(self, path):
263 """ 274 """
264 Private slot to check the executable after it has been selected. 275 Private slot to check the executable after it has been selected.
265 276
266 @param path path of the executable 277 @param path path of the executable
267 @type str 278 @type str
268 """ 279 """
269 if path and not Utilities.isinpath(path): 280 if path and not Utilities.isinpath(path):
270 EricMessageBox.critical( 281 EricMessageBox.critical(
271 self, 282 self,
272 self.tr("Select executable"), 283 self.tr("Select executable"),
273 self.tr( 284 self.tr(
274 "The selected file is not an executable." 285 "The selected file is not an executable."
275 " Please choose an executable filename.")) 286 " Please choose an executable filename."
276 287 ),
288 )
289
277 def on_toolsList_currentRowChanged(self, row): 290 def on_toolsList_currentRowChanged(self, row):
278 """ 291 """
279 Private slot to set the lineedits depending on the selected entry. 292 Private slot to set the lineedits depending on the selected entry.
280 293
281 @param row the row of the selected entry (integer) 294 @param row the row of the selected entry (integer)
282 """ 295 """
283 if row >= 0 and row < len(self.toollist): 296 if row >= 0 and row < len(self.toollist):
284 if self.toollist[row]['menutext'] == '--': 297 if self.toollist[row]["menutext"] == "--":
285 self.executablePicker.clear() 298 self.executablePicker.clear()
286 self.menuEdit.clear() 299 self.menuEdit.clear()
287 self.iconPicker.clear() 300 self.iconPicker.clear()
288 self.argumentsEdit.clear() 301 self.argumentsEdit.clear()
289 self.redirectCombo.setCurrentIndex(0) 302 self.redirectCombo.setCurrentIndex(0)
290 else: 303 else:
291 tool = self.toollist[row] 304 tool = self.toollist[row]
292 self.menuEdit.setText(tool['menutext']) 305 self.menuEdit.setText(tool["menutext"])
293 self.iconPicker.setText(tool['icon']) 306 self.iconPicker.setText(tool["icon"])
294 self.executablePicker.setText(tool['executable']) 307 self.executablePicker.setText(tool["executable"])
295 self.argumentsEdit.setText(tool['arguments']) 308 self.argumentsEdit.setText(tool["arguments"])
296 self.redirectCombo.setCurrentIndex( 309 self.redirectCombo.setCurrentIndex(
297 self.__findModeIndex(tool['redirect'])) 310 self.__findModeIndex(tool["redirect"])
298 311 )
312
299 self.changeButton.setEnabled(False) 313 self.changeButton.setEnabled(False)
300 self.deleteButton.setEnabled(True) 314 self.deleteButton.setEnabled(True)
301 315
302 if row != 0: 316 if row != 0:
303 self.upButton.setEnabled(True) 317 self.upButton.setEnabled(True)
304 else: 318 else:
305 self.upButton.setEnabled(False) 319 self.upButton.setEnabled(False)
306 320
307 if row + 1 != len(self.toollist): 321 if row + 1 != len(self.toollist):
308 self.downButton.setEnabled(True) 322 self.downButton.setEnabled(True)
309 else: 323 else:
310 self.downButton.setEnabled(False) 324 self.downButton.setEnabled(False)
311 else: 325 else:
315 self.argumentsEdit.clear() 329 self.argumentsEdit.clear()
316 self.downButton.setEnabled(False) 330 self.downButton.setEnabled(False)
317 self.upButton.setEnabled(False) 331 self.upButton.setEnabled(False)
318 self.deleteButton.setEnabled(False) 332 self.deleteButton.setEnabled(False)
319 self.changeButton.setEnabled(False) 333 self.changeButton.setEnabled(False)
320 334
321 def __toolEntryChanged(self): 335 def __toolEntryChanged(self):
322 """ 336 """
323 Private slot to perform actions when a tool entry was changed. 337 Private slot to perform actions when a tool entry was changed.
324 """ 338 """
325 row = self.toolsList.currentRow() 339 row = self.toolsList.currentRow()
326 if ( 340 if (
327 row >= 0 and 341 row >= 0
328 row < len(self.toollist) and 342 and row < len(self.toollist)
329 self.toollist[row]['menutext'] != '--' 343 and self.toollist[row]["menutext"] != "--"
330 ): 344 ):
331 self.changeButton.setEnabled(True) 345 self.changeButton.setEnabled(True)
332 346
333 def on_menuEdit_textChanged(self, text): 347 def on_menuEdit_textChanged(self, text):
334 """ 348 """
335 Private slot called, when the menu text was changed. 349 Private slot called, when the menu text was changed.
336 350
337 @param text the new text (string) (ignored) 351 @param text the new text (string) (ignored)
338 """ 352 """
339 self.__toolEntryChanged() 353 self.__toolEntryChanged()
340 354
341 def on_iconPicker_textChanged(self, text): 355 def on_iconPicker_textChanged(self, text):
342 """ 356 """
343 Private slot called, when the icon path was changed. 357 Private slot called, when the icon path was changed.
344 358
345 @param text the new text (string) (ignored) 359 @param text the new text (string) (ignored)
346 """ 360 """
347 self.__toolEntryChanged() 361 self.__toolEntryChanged()
348 362
349 def on_executablePicker_textChanged(self, text): 363 def on_executablePicker_textChanged(self, text):
350 """ 364 """
351 Private slot called, when the executable was changed. 365 Private slot called, when the executable was changed.
352 366
353 @param text the new text (string) (ignored) 367 @param text the new text (string) (ignored)
354 """ 368 """
355 self.__toolEntryChanged() 369 self.__toolEntryChanged()
356 370
357 def on_argumentsEdit_textChanged(self, text): 371 def on_argumentsEdit_textChanged(self, text):
358 """ 372 """
359 Private slot called, when the arguments string was changed. 373 Private slot called, when the arguments string was changed.
360 374
361 @param text the new text (string) (ignored) 375 @param text the new text (string) (ignored)
362 """ 376 """
363 self.__toolEntryChanged() 377 self.__toolEntryChanged()
364 378
365 @pyqtSlot(int) 379 @pyqtSlot(int)
366 def on_redirectCombo_currentIndexChanged(self, index): 380 def on_redirectCombo_currentIndexChanged(self, index):
367 """ 381 """
368 Private slot called, when the redirection mode was changed. 382 Private slot called, when the redirection mode was changed.
369 383
370 @param index the selected mode index (integer) (ignored) 384 @param index the selected mode index (integer) (ignored)
371 """ 385 """
372 self.__toolEntryChanged() 386 self.__toolEntryChanged()
373 387
374 def getToollist(self): 388 def getToollist(self):
375 """ 389 """
376 Public method to retrieve the tools list. 390 Public method to retrieve the tools list.
377 391
378 @return a list of tuples containing the menu text, the executable, 392 @return a list of tuples containing the menu text, the executable,
379 the executables arguments and a redirection flag 393 the executables arguments and a redirection flag
380 """ 394 """
381 return self.toollist[:] 395 return self.toollist[:]
382 396
383 def __swap(self, itm1, itm2): 397 def __swap(self, itm1, itm2):
384 """ 398 """
385 Private method used two swap two list entries given by their index. 399 Private method used two swap two list entries given by their index.
386 400
387 @param itm1 index of first entry (int) 401 @param itm1 index of first entry (int)
388 @param itm2 index of second entry (int) 402 @param itm2 index of second entry (int)
389 """ 403 """
390 tmp = self.toollist[itm1] 404 tmp = self.toollist[itm1]
391 self.toollist[itm1] = self.toollist[itm2] 405 self.toollist[itm1] = self.toollist[itm2]

eric ide

mercurial