11 |
11 |
12 from PyQt5.QtCore import QFileInfo, Qt, pyqtSlot |
12 from PyQt5.QtCore import QFileInfo, Qt, pyqtSlot |
13 from PyQt5.QtGui import QColor |
13 from PyQt5.QtGui import QColor |
14 from PyQt5.QtWidgets import QListWidgetItem, QDialog |
14 from PyQt5.QtWidgets import QListWidgetItem, QDialog |
15 |
15 |
16 from E5Gui.E5Completers import E5FileCompleter |
16 from E5Gui.E5PathPicker import E5PathPickerModes |
17 from E5Gui import E5FileDialog |
|
18 |
17 |
19 from .Ui_BookmarkedFilesDialog import Ui_BookmarkedFilesDialog |
18 from .Ui_BookmarkedFilesDialog import Ui_BookmarkedFilesDialog |
20 |
|
21 import Utilities |
|
22 import UI.PixmapCache |
|
23 |
19 |
24 |
20 |
25 class BookmarkedFilesDialog(QDialog, Ui_BookmarkedFilesDialog): |
21 class BookmarkedFilesDialog(QDialog, Ui_BookmarkedFilesDialog): |
26 """ |
22 """ |
27 Class implementing a configuration dialog for the bookmarked files menu. |
23 Class implementing a configuration dialog for the bookmarked files menu. |
34 @param parent parent widget (QWidget) |
30 @param parent parent widget (QWidget) |
35 """ |
31 """ |
36 super(BookmarkedFilesDialog, self).__init__(parent) |
32 super(BookmarkedFilesDialog, self).__init__(parent) |
37 self.setupUi(self) |
33 self.setupUi(self) |
38 |
34 |
39 self.fileButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
35 self.filePicker.setMode(E5PathPickerModes.OpenFileMode) |
40 |
|
41 self.fileCompleter = E5FileCompleter(self.fileEdit) |
|
42 |
36 |
43 self.bookmarks = bookmarks[:] |
37 self.bookmarks = bookmarks[:] |
44 for bookmark in self.bookmarks: |
38 for bookmark in self.bookmarks: |
45 itm = QListWidgetItem(bookmark, self.filesList) |
39 itm = QListWidgetItem(bookmark, self.filesList) |
46 if not QFileInfo(bookmark).exists(): |
40 if not QFileInfo(bookmark).exists(): |
47 itm.setBackground(QColor(Qt.red)) |
41 itm.setBackground(QColor(Qt.red)) |
48 |
42 |
49 if len(self.bookmarks): |
43 if len(self.bookmarks): |
50 self.filesList.setCurrentRow(0) |
44 self.filesList.setCurrentRow(0) |
51 |
45 |
52 def on_fileEdit_textChanged(self, txt): |
46 def on_filePicker_textChanged(self, txt): |
53 """ |
47 """ |
54 Private slot to handle the textChanged signal of the file edit. |
48 Private slot to handle the textChanged signal of the file edit. |
55 |
49 |
56 @param txt the text of the file edit (string) |
50 @param txt the text of the file edit (string) |
57 """ |
51 """ |
65 Private slot to set the lineedit depending on the selected entry. |
59 Private slot to set the lineedit depending on the selected entry. |
66 |
60 |
67 @param row the current row (integer) |
61 @param row the current row (integer) |
68 """ |
62 """ |
69 if row == -1: |
63 if row == -1: |
70 self.fileEdit.clear() |
64 self.filePicker.clear() |
71 self.downButton.setEnabled(False) |
65 self.downButton.setEnabled(False) |
72 self.upButton.setEnabled(False) |
66 self.upButton.setEnabled(False) |
73 self.deleteButton.setEnabled(False) |
67 self.deleteButton.setEnabled(False) |
74 self.changeButton.setEnabled(False) |
68 self.changeButton.setEnabled(False) |
75 else: |
69 else: |
78 self.downButton.setEnabled(row != maxIndex) |
72 self.downButton.setEnabled(row != maxIndex) |
79 self.deleteButton.setEnabled(True) |
73 self.deleteButton.setEnabled(True) |
80 self.changeButton.setEnabled(True) |
74 self.changeButton.setEnabled(True) |
81 |
75 |
82 bookmark = self.bookmarks[row] |
76 bookmark = self.bookmarks[row] |
83 self.fileEdit.setText(bookmark) |
77 self.filePicker.setText(bookmark) |
84 |
78 |
85 @pyqtSlot() |
79 @pyqtSlot() |
86 def on_addButton_clicked(self): |
80 def on_addButton_clicked(self): |
87 """ |
81 """ |
88 Private slot to add a new entry. |
82 Private slot to add a new entry. |
89 """ |
83 """ |
90 bookmark = self.fileEdit.text() |
84 bookmark = self.filePicker.text() |
91 if bookmark: |
85 if bookmark: |
92 bookmark = Utilities.toNativeSeparators(bookmark) |
|
93 itm = QListWidgetItem(bookmark, self.filesList) |
86 itm = QListWidgetItem(bookmark, self.filesList) |
94 if not QFileInfo(bookmark).exists(): |
87 if not QFileInfo(bookmark).exists(): |
95 itm.setBackground(QColor(Qt.red)) |
88 itm.setBackground(QColor(Qt.red)) |
96 self.fileEdit.clear() |
89 self.filePicker.clear() |
97 self.bookmarks.append(bookmark) |
90 self.bookmarks.append(bookmark) |
98 row = self.filesList.currentRow() |
91 row = self.filesList.currentRow() |
99 self.on_filesList_currentRowChanged(row) |
92 self.on_filesList_currentRowChanged(row) |
100 |
93 |
101 @pyqtSlot() |
94 @pyqtSlot() |
102 def on_changeButton_clicked(self): |
95 def on_changeButton_clicked(self): |
103 """ |
96 """ |
104 Private slot to change an entry. |
97 Private slot to change an entry. |
105 """ |
98 """ |
106 row = self.filesList.currentRow() |
99 row = self.filesList.currentRow() |
107 bookmark = self.fileEdit.text() |
100 bookmark = self.filePicker.text() |
108 bookmark = Utilities.toNativeSeparators(bookmark) |
|
109 self.bookmarks[row] = bookmark |
101 self.bookmarks[row] = bookmark |
110 itm = self.filesList.item(row) |
102 itm = self.filesList.item(row) |
111 itm.setText(bookmark) |
103 itm.setText(bookmark) |
112 if not QFileInfo(bookmark).exists(): |
104 if not QFileInfo(bookmark).exists(): |
113 itm.setBackground(QColor(Qt.red)) |
105 itm.setBackground(QColor(Qt.red)) |
165 self.upButton.setEnabled(False) |
157 self.upButton.setEnabled(False) |
166 else: |
158 else: |
167 self.upButton.setEnabled(True) |
159 self.upButton.setEnabled(True) |
168 self.downButton.setEnabled(True) |
160 self.downButton.setEnabled(True) |
169 |
161 |
170 @pyqtSlot() |
|
171 def on_fileButton_clicked(self): |
|
172 """ |
|
173 Private slot to handle the file selection via a file selection dialog. |
|
174 """ |
|
175 bookmark = E5FileDialog.getOpenFileName() |
|
176 if bookmark: |
|
177 bookmark = Utilities.toNativeSeparators(bookmark) |
|
178 self.fileEdit.setText(bookmark) |
|
179 |
|
180 def getBookmarkedFiles(self): |
162 def getBookmarkedFiles(self): |
181 """ |
163 """ |
182 Public method to retrieve the tools list. |
164 Public method to retrieve the tools list. |
183 |
165 |
184 @return a list of filenames (list of strings) |
166 @return a list of filenames (list of strings) |