E5Gui/E5StringListEditWidget.py

Tue, 29 Aug 2017 17:18:18 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 29 Aug 2017 17:18:18 +0200
changeset 5858
7afdb26fcabc
parent 5389
9b1c800daff3
child 6048
82ad8ec9548c
permissions
-rw-r--r--

Added capability to reset to default to the message filter dialog and the mimetypes configuration page.

4093
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
5389
9b1c800daff3 Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
3 # Copyright (c) 2015 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
4093
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to edit a list of strings.
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
5858
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
11 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QSortFilterProxyModel, \
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
12 QStringListModel
4093
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from PyQt5.QtWidgets import QWidget, QInputDialog, QLineEdit
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_E5StringListEditWidget import Ui_E5StringListEditWidget
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class E5StringListEditWidget(QWidget, Ui_E5StringListEditWidget):
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing a dialog to edit a list of strings.
5858
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
21
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
22 @signal setToDefault() emitted to request the default list of values
4093
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
5858
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
24 setToDefault = pyqtSignal()
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
25
4093
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 def __init__(self, parent=None):
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Constructor
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param parent reference to the parent widget (QWidget)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 super(E5StringListEditWidget, self).__init__(parent)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.setupUi(self)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.__model = QStringListModel(self)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.__proxyModel = QSortFilterProxyModel(self)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseInsensitive)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.__proxyModel.setSourceModel(self.__model)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.stringList.setModel(self.__proxyModel)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
5858
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
41 self.defaultButton.hide()
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
42
4093
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.searchEdit.textChanged.connect(
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__proxyModel.setFilterFixedString)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.removeButton.clicked.connect(self.stringList.removeSelected)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 self.removeAllButton.clicked.connect(self.stringList.removeAll)
5858
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
48 self.defaultButton.clicked.connect(self.setToDefault)
4093
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 def setList(self, stringList):
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 Public method to set the list of strings to be edited.
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @param stringList list of strings to be edited (list of string)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__model.setStringList(stringList)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 self.__model.sort(0)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def getList(self):
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Public method to get the edited list of strings.
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 @return edited list of string (list of string)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 return self.__model.stringList()[:]
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 def setListWhatsThis(self, txt):
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 Public method to set a what's that help text for the string list.
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 @param txt help text to be set (string)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.stringList.setWhatsThis(txt)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
5858
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
75 def setDefaultVisible(self, visible):
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
76 """
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
77 Public method to show or hide the default button.
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
78
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
79 @param visible flag indicating the visibility of the default button
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
80 @type bool
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
81 """
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
82 self.defaultButton.setVisible(visible)
7afdb26fcabc Added capability to reset to default to the message filter dialog and the mimetypes configuration page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
83
4093
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @pyqtSlot()
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 def on_addButton_clicked(self):
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 Private slot to add an entry to the list.
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 entry, ok = QInputDialog.getText(
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self,
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.tr("Add Entry"),
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.tr("Enter the entry to add to the list:"),
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 QLineEdit.Normal)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if ok and entry != "" and entry not in self.__model.stringList():
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.__model.insertRow(self.__model.rowCount())
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.__model.setData(
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.__model.index(self.__model.rowCount() - 1), entry)
8dd5c3a49b82 Created a generic widget for editing a list of strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.__model.sort(0)

eric ide

mercurial