|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to show the found files to the user. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_AddFoundFilesDialog import Ui_AddFoundFilesDialog |
|
14 |
|
15 |
|
16 class AddFoundFilesDialog(QDialog, Ui_AddFoundFilesDialog): |
|
17 """ |
|
18 Class implementing a dialog to show the found files to the user. |
|
19 |
|
20 The found files are displayed in a listview. Pressing the 'Add All' button |
|
21 adds all files to the current project, the 'Add Selected' button adds only |
|
22 the selected files and the 'Cancel' button cancels the operation. |
|
23 """ |
|
24 def __init__(self, files, parent=None, name=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param files list of files, that have been found for addition |
|
29 (list of strings) |
|
30 @param parent parent widget of this dialog (QWidget) |
|
31 @param name name of this dialog (string) |
|
32 """ |
|
33 super().__init__(parent) |
|
34 if name: |
|
35 self.setObjectName(name) |
|
36 self.setupUi(self) |
|
37 |
|
38 self.addAllButton = self.buttonBox.addButton( |
|
39 self.tr("Add All"), QDialogButtonBox.ButtonRole.AcceptRole) |
|
40 self.addAllButton.setToolTip(self.tr("Add all files.")) |
|
41 self.addSelectedButton = self.buttonBox.addButton( |
|
42 self.tr("Add Selected"), QDialogButtonBox.ButtonRole.AcceptRole) |
|
43 self.addSelectedButton.setToolTip( |
|
44 self.tr("Add selected files only.")) |
|
45 |
|
46 self.fileList.addItems(files) |
|
47 |
|
48 def on_buttonBox_clicked(self, button): |
|
49 """ |
|
50 Private slot called by a button of the button box clicked. |
|
51 |
|
52 @param button button that was clicked (QAbstractButton) |
|
53 """ |
|
54 if button == self.addAllButton: |
|
55 self.on_addAllButton_clicked() |
|
56 elif button == self.addSelectedButton: |
|
57 self.on_addSelectedButton_clicked() |
|
58 |
|
59 @pyqtSlot() |
|
60 def on_addAllButton_clicked(self): |
|
61 """ |
|
62 Private slot to handle the 'Add All' button press. |
|
63 |
|
64 Always returns the value 1 (integer). |
|
65 """ |
|
66 self.done(1) |
|
67 |
|
68 @pyqtSlot() |
|
69 def on_addSelectedButton_clicked(self): |
|
70 """ |
|
71 Private slot to handle the 'Add Selected' button press. |
|
72 |
|
73 Always returns the value 2 (integer). |
|
74 """ |
|
75 self.done(2) |
|
76 |
|
77 def getSelection(self): |
|
78 """ |
|
79 Public method to return the selected items. |
|
80 |
|
81 @return list of selected files (list of strings) |
|
82 """ |
|
83 list_ = [] |
|
84 for itm in self.fileList.selectedItems(): |
|
85 list_.append(itm.text()) |
|
86 return list_ |