Preferences/ToolConfigurationDialog.py

changeset 4582
3a1d1d4c6f4f
parent 4021
195a471c327b
child 4631
5c1a96925da4
equal deleted inserted replaced
4581:76999ca7bbf1 4582:3a1d1d4c6f4f
12 import copy 12 import copy
13 13
14 from PyQt5.QtCore import Qt, pyqtSlot 14 from PyQt5.QtCore import Qt, pyqtSlot
15 from PyQt5.QtWidgets import QDialog 15 from PyQt5.QtWidgets import QDialog
16 16
17 from E5Gui.E5Completers import E5FileCompleter 17 from E5Gui import E5MessageBox
18 from E5Gui import E5MessageBox, E5FileDialog 18 from E5Gui.E5PathPicker import E5PathPickerModes
19 19
20 from .Ui_ToolConfigurationDialog import Ui_ToolConfigurationDialog 20 from .Ui_ToolConfigurationDialog import Ui_ToolConfigurationDialog
21 21
22 import Utilities 22 import Utilities
23 import UI.PixmapCache
24 23
25 24
26 class ToolConfigurationDialog(QDialog, Ui_ToolConfigurationDialog): 25 class ToolConfigurationDialog(QDialog, Ui_ToolConfigurationDialog):
27 """ 26 """
28 Class implementing a configuration dialog for the tools menu. 27 Class implementing a configuration dialog for the tools menu.
35 @param parent parent widget (QWidget) 34 @param parent parent widget (QWidget)
36 """ 35 """
37 super(ToolConfigurationDialog, self).__init__(parent) 36 super(ToolConfigurationDialog, self).__init__(parent)
38 self.setupUi(self) 37 self.setupUi(self)
39 38
40 self.iconButton.setIcon(UI.PixmapCache.getIcon("open.png")) 39 self.iconPicker.setMode(E5PathPickerModes.OpenFileMode)
41 self.executableButton.setIcon(UI.PixmapCache.getIcon("open.png")) 40 self.iconPicker.setFilters(self.tr("Icon files (*.png)"))
42 41 self.executablePicker.setMode(E5PathPickerModes.OpenFileMode)
43 self.iconCompleter = E5FileCompleter(self.iconEdit)
44 self.executableCompleter = E5FileCompleter(self.executableEdit)
45 42
46 self.redirectionModes = [ 43 self.redirectionModes = [
47 ("no", self.tr("no redirection")), 44 ("no", self.tr("no redirection")),
48 ("show", self.tr("show output")), 45 ("show", self.tr("show output")),
49 ("insert", self.tr("insert into current editor")), 46 ("insert", self.tr("insert into current editor")),
84 @pyqtSlot() 81 @pyqtSlot()
85 def on_newButton_clicked(self): 82 def on_newButton_clicked(self):
86 """ 83 """
87 Private slot to clear all entry fields. 84 Private slot to clear all entry fields.
88 """ 85 """
89 self.executableEdit.clear() 86 self.executablePicker.clear()
90 self.menuEdit.clear() 87 self.menuEdit.clear()
91 self.iconEdit.clear() 88 self.iconPicker.clear()
92 self.argumentsEdit.clear() 89 self.argumentsEdit.clear()
93 self.redirectCombo.setCurrentIndex(1) 90 self.redirectCombo.setCurrentIndex(1)
94 91
95 @pyqtSlot() 92 @pyqtSlot()
96 def on_addButton_clicked(self): 93 def on_addButton_clicked(self):
97 """ 94 """
98 Private slot to add a new entry. 95 Private slot to add a new entry.
99 """ 96 """
100 menutext = self.menuEdit.text() 97 menutext = self.menuEdit.text()
101 icon = self.iconEdit.text() 98 icon = self.iconPicker.text()
102 executable = self.executableEdit.text() 99 executable = self.executablePicker.text()
103 arguments = self.argumentsEdit.text() 100 arguments = self.argumentsEdit.text()
104 redirect = self.redirectionModes[self.redirectCombo.currentIndex()][0] 101 redirect = self.redirectionModes[self.redirectCombo.currentIndex()][0]
105 102
106 if not executable: 103 if not executable:
107 E5MessageBox.critical( 104 E5MessageBox.critical(
158 row = self.toolsList.currentRow() 155 row = self.toolsList.currentRow()
159 if row < 0: 156 if row < 0:
160 return 157 return
161 158
162 menutext = self.menuEdit.text() 159 menutext = self.menuEdit.text()
163 icon = self.iconEdit.text() 160 icon = self.iconPicker.text()
164 executable = self.executableEdit.text() 161 executable = self.executablePicker.text()
165 arguments = self.argumentsEdit.text() 162 arguments = self.argumentsEdit.text()
166 redirect = self.redirectionModes[self.redirectCombo.currentIndex()][0] 163 redirect = self.redirectionModes[self.redirectCombo.currentIndex()][0]
167 164
168 if not executable: 165 if not executable:
169 E5MessageBox.critical( 166 E5MessageBox.critical(
262 'executable': '', 259 'executable': '',
263 'arguments': '', 260 'arguments': '',
264 'redirect': 'no', 261 'redirect': 'no',
265 } 262 }
266 self.toollist.append(tool) 263 self.toollist.append(tool)
267 264
268 @pyqtSlot() 265 @pyqtSlot(str)
269 def on_executableButton_clicked(self): 266 def on_executablePicker_pathSelected(self, path):
270 """ 267 """
271 Private slot to handle the executable selection via a file selection 268 Private slot to check the executable after it has been selected.
272 dialog. 269
273 """ 270 @param path path of the executable
274 execfile = E5FileDialog.getOpenFileName( 271 @type str
275 self, 272 """
276 self.tr("Select executable"), 273 if path:
277 self.executableEdit.text(), 274 if not Utilities.isinpath(path):
278 "")
279 if execfile:
280 execfile = Utilities.toNativeSeparators(execfile)
281 if not Utilities.isinpath(execfile):
282 E5MessageBox.critical( 275 E5MessageBox.critical(
283 self, 276 self,
284 self.tr("Select executable"), 277 self.tr("Select executable"),
285 self.tr( 278 self.tr(
286 "The selected file is not an executable." 279 "The selected file is not an executable."
287 " Please choose an executable filename.")) 280 " Please choose an executable filename."))
288 return
289
290 self.executableEdit.setText(execfile)
291
292 @pyqtSlot()
293 def on_iconButton_clicked(self):
294 """
295 Private slot to handle the icon selection via a file selection dialog.
296 """
297 icon = E5FileDialog.getOpenFileName(
298 self,
299 self.tr("Select icon file"),
300 self.iconEdit.text(),
301 self.tr("Icon files (*.png)"))
302 if icon:
303 self.iconEdit.setText(icon)
304 281
305 def on_toolsList_currentRowChanged(self, row): 282 def on_toolsList_currentRowChanged(self, row):
306 """ 283 """
307 Private slot to set the lineedits depending on the selected entry. 284 Private slot to set the lineedits depending on the selected entry.
308 285
309 @param row the row of the selected entry (integer) 286 @param row the row of the selected entry (integer)
310 """ 287 """
311 if row >= 0 and row < len(self.toollist): 288 if row >= 0 and row < len(self.toollist):
312 if self.toollist[row]['menutext'] == '--': 289 if self.toollist[row]['menutext'] == '--':
313 self.executableEdit.clear() 290 self.executablePicker.clear()
314 self.menuEdit.clear() 291 self.menuEdit.clear()
315 self.iconEdit.clear() 292 self.iconPicker.clear()
316 self.argumentsEdit.clear() 293 self.argumentsEdit.clear()
317 self.redirectCombo.setCurrentIndex(0) 294 self.redirectCombo.setCurrentIndex(0)
318 else: 295 else:
319 tool = self.toollist[row] 296 tool = self.toollist[row]
320 self.menuEdit.setText(tool['menutext']) 297 self.menuEdit.setText(tool['menutext'])
321 self.iconEdit.setText(tool['icon']) 298 self.iconPicker.setText(tool['icon'])
322 self.executableEdit.setText(tool['executable']) 299 self.executablePicker.setText(tool['executable'])
323 self.argumentsEdit.setText(tool['arguments']) 300 self.argumentsEdit.setText(tool['arguments'])
324 self.redirectCombo.setCurrentIndex( 301 self.redirectCombo.setCurrentIndex(
325 self.__findModeIndex(tool['redirect'])) 302 self.__findModeIndex(tool['redirect']))
326 303
327 self.changeButton.setEnabled(False) 304 self.changeButton.setEnabled(False)
335 if row + 1 != len(self.toollist): 312 if row + 1 != len(self.toollist):
336 self.downButton.setEnabled(True) 313 self.downButton.setEnabled(True)
337 else: 314 else:
338 self.downButton.setEnabled(False) 315 self.downButton.setEnabled(False)
339 else: 316 else:
340 self.executableEdit.clear() 317 self.executablePicker.clear()
341 self.menuEdit.clear() 318 self.menuEdit.clear()
342 self.iconEdit.clear() 319 self.iconPicker.clear()
343 self.argumentsEdit.clear() 320 self.argumentsEdit.clear()
344 self.downButton.setEnabled(False) 321 self.downButton.setEnabled(False)
345 self.upButton.setEnabled(False) 322 self.upButton.setEnabled(False)
346 self.deleteButton.setEnabled(False) 323 self.deleteButton.setEnabled(False)
347 self.changeButton.setEnabled(False) 324 self.changeButton.setEnabled(False)
362 339
363 @param text the new text (string) (ignored) 340 @param text the new text (string) (ignored)
364 """ 341 """
365 self.__toolEntryChanged() 342 self.__toolEntryChanged()
366 343
367 def on_iconEdit_textChanged(self, text): 344 def on_iconPicker_textChanged(self, text):
368 """ 345 """
369 Private slot called, when the icon path was changed. 346 Private slot called, when the icon path was changed.
370 347
371 @param text the new text (string) (ignored) 348 @param text the new text (string) (ignored)
372 """ 349 """
373 self.__toolEntryChanged() 350 self.__toolEntryChanged()
374 351
375 def on_executableEdit_textChanged(self, text): 352 def on_executablePicker_textChanged(self, text):
376 """ 353 """
377 Private slot called, when the executable was changed. 354 Private slot called, when the executable was changed.
378 355
379 @param text the new text (string) (ignored) 356 @param text the new text (string) (ignored)
380 """ 357 """

eric ide

mercurial