|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to manage the list of messages to be ignored. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
|
11 |
|
12 from PyQt4.QtCore import pyqtSlot, Qt |
|
13 from PyQt4.QtGui import QDialog, QStringListModel, QSortFilterProxyModel, \ |
|
14 QInputDialog, QLineEdit |
|
15 |
|
16 from .Ui_E5ErrorMessageFilterDialog import Ui_E5ErrorMessageFilterDialog |
|
17 |
|
18 |
|
19 class E5ErrorMessageFilterDialog(QDialog, Ui_E5ErrorMessageFilterDialog): |
|
20 """ |
|
21 Class implementing a dialog to manage the list of messages to be ignored. |
|
22 """ |
|
23 def __init__(self, messageFilters, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param messageFilters list of message filters to be edited (list of strings) |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 super(E5ErrorMessageFilterDialog, self).__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 self.__model = QStringListModel(messageFilters, self) |
|
34 self.__model.sort(0) |
|
35 self.__proxyModel = QSortFilterProxyModel(self) |
|
36 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive) |
|
37 self.__proxyModel.setSourceModel(self.__model) |
|
38 self.filterList.setModel(self.__proxyModel) |
|
39 |
|
40 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString) |
|
41 |
|
42 self.removeButton.clicked[()].connect(self.filterList.removeSelected) |
|
43 self.removeAllButton.clicked[()].connect(self.filterList.removeAll) |
|
44 |
|
45 @pyqtSlot() |
|
46 def on_addButton_clicked(self): |
|
47 """ |
|
48 Private slot to add an entry to the list. |
|
49 """ |
|
50 filter, ok = QInputDialog.getText( |
|
51 self, |
|
52 self.trUtf8("Error Messages Filter"), |
|
53 self.trUtf8("Enter message filter to add to the list:"), |
|
54 QLineEdit.Normal) |
|
55 if ok and filter != "" and filter not in self.__model.stringList(): |
|
56 self.__model.insertRow(self.__model.rowCount()) |
|
57 self.__model.setData( |
|
58 self.__model.index(self.__model.rowCount() - 1), filter) |
|
59 self.__model.sort(0) |
|
60 |
|
61 def getFilters(self): |
|
62 """ |
|
63 Public method to get the list of message filters. |
|
64 |
|
65 @return error message filters (list of strings) |
|
66 """ |
|
67 return self.__model.stringList()[:] |