eric6/E5Gui/E5StringListEditWidget.py

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

eric ide

mercurial