src/eric7/EricWidgets/EricStringListEditWidget.py

branch
eric7
changeset 9561
f7bb5739c35a
parent 9534
5ed8445f3b31
child 9586
2750e76fc366
equal deleted inserted replaced
9560:abffba70297f 9561:f7bb5739c35a
14 pyqtSignal, 14 pyqtSignal,
15 pyqtSlot, 15 pyqtSlot,
16 ) 16 )
17 from PyQt6.QtWidgets import QInputDialog, QLineEdit, QWidget 17 from PyQt6.QtWidgets import QInputDialog, QLineEdit, QWidget
18 18
19 from eric7.EricWidgets import EricMessageBox
20
19 from .Ui_EricStringListEditWidget import Ui_EricStringListEditWidget 21 from .Ui_EricStringListEditWidget import Ui_EricStringListEditWidget
20 22
21 23
22 class EricStringListEditWidget(QWidget, Ui_EricStringListEditWidget): 24 class EricStringListEditWidget(QWidget, Ui_EricStringListEditWidget):
23 """ 25 """
30 32
31 def __init__(self, parent=None): 33 def __init__(self, parent=None):
32 """ 34 """
33 Constructor 35 Constructor
34 36
35 @param parent reference to the parent widget (QWidget) 37 @param parent reference to the parent widget
38 @type QWidget
36 """ 39 """
37 super().__init__(parent) 40 super().__init__(parent)
38 self.setupUi(self) 41 self.setupUi(self)
39 42
40 self.__model = QStringListModel(self) 43 self.__model = QStringListModel(self)
42 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive) 45 self.__proxyModel.setFilterCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
43 self.__proxyModel.setSourceModel(self.__model) 46 self.__proxyModel.setSourceModel(self.__model)
44 self.stringList.setModel(self.__proxyModel) 47 self.stringList.setModel(self.__proxyModel)
45 48
46 self.defaultButton.hide() 49 self.defaultButton.hide()
50 self.resetButton.hide()
51 self.resetLine.hide()
52
53 # store some internal state
54 self.__defaultVisible = False
55 self.__resetVisible = False
47 56
48 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString) 57 self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString)
49 58
50 self.removeButton.clicked.connect(self.stringList.removeSelected) 59 self.removeButton.clicked.connect(self.stringList.removeSelected)
51 self.removeAllButton.clicked.connect(self.stringList.removeAll) 60 self.removeAllButton.clicked.connect(self.stringList.removeAll)
53 62
54 def setList(self, stringList): 63 def setList(self, stringList):
55 """ 64 """
56 Public method to set the list of strings to be edited. 65 Public method to set the list of strings to be edited.
57 66
58 @param stringList list of strings to be edited (list of string) 67 @param stringList list of strings to be edited
68 @type list of str
59 """ 69 """
70 self.__initialList = stringList[:]
60 self.__model.setStringList(stringList) 71 self.__model.setStringList(stringList)
61 self.__model.sort(0) 72 self.__model.sort(0)
62 73
63 def getList(self): 74 def getList(self):
64 """ 75 """
65 Public method to get the edited list of strings. 76 Public method to get the edited list of strings.
66 77
67 @return edited list of string (list of string) 78 @return edited list of string
79 @rtype list of str
68 """ 80 """
69 return self.__model.stringList()[:] 81 return self.__model.stringList()[:]
70 82
71 def count(self): 83 def count(self):
72 """ 84 """
88 100
89 def setListWhatsThis(self, txt): 101 def setListWhatsThis(self, txt):
90 """ 102 """
91 Public method to set a what's that help text for the string list. 103 Public method to set a what's that help text for the string list.
92 104
93 @param txt help text to be set (string) 105 @param txt help text to be set
106 @type str
94 """ 107 """
95 self.stringList.setWhatsThis(txt) 108 self.stringList.setWhatsThis(txt)
96 109
97 def setDefaultVisible(self, visible): 110 def setDefaultVisible(self, visible):
98 """ 111 """
100 113
101 @param visible flag indicating the visibility of the default button 114 @param visible flag indicating the visibility of the default button
102 @type bool 115 @type bool
103 """ 116 """
104 self.defaultButton.setVisible(visible) 117 self.defaultButton.setVisible(visible)
118 self.__defaultVisible = visible
119 self.resetLine.setVisible(self.__defaultVisible and self.__resetVisible)
120
121 def setResetVisible(self, visible):
122 """
123 Public method to show or hide the reset button.
124
125 @param visible flag indicating the visibility of the reset button
126 @type bool
127 """
128 self.resetButton.setVisible(visible)
129 self.__resetVisible = visible
130 self.resetLine.setVisible(self.__defaultVisible and self.__resetVisible)
105 131
106 def setAddVisible(self, visible): 132 def setAddVisible(self, visible):
107 """ 133 """
108 Public method to show or hide the add button. 134 Public method to show or hide the add button.
109 135
126 ) 152 )
127 if ok and entry != "" and entry not in self.__model.stringList(): 153 if ok and entry != "" and entry not in self.__model.stringList():
128 self.__model.insertRow(self.__model.rowCount()) 154 self.__model.insertRow(self.__model.rowCount())
129 self.__model.setData(self.__model.index(self.__model.rowCount() - 1), entry) 155 self.__model.setData(self.__model.index(self.__model.rowCount() - 1), entry)
130 self.__model.sort(0) 156 self.__model.sort(0)
157
158 @pyqtSlot()
159 def on_resetButton_clicked(self):
160 """
161 Public slot to reset the list to its initial value.
162 """
163 ok = EricMessageBox.yesNo(
164 self,
165 self.tr("Reset List"),
166 self.tr(
167 "Do you really want to reset the list to its initial value? All changes"
168 " will be lost."
169 ),
170 )
171 if ok:
172 self.__model.setStringList(self.__initialList)
173 self.__model.sort(0)

eric ide

mercurial