Added a 'Reset' capability to the EricStringListEditWidget class. eric7

Mon, 05 Dec 2022 11:37:42 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 05 Dec 2022 11:37:42 +0100
branch
eric7
changeset 9561
f7bb5739c35a
parent 9560
abffba70297f
child 9562
94f349d5cd1e

Added a 'Reset' capability to the EricStringListEditWidget class.

src/eric7/EricWidgets/EricStringListEditWidget.py file | annotate | diff | comparison | revisions
src/eric7/EricWidgets/EricStringListEditWidget.ui file | annotate | diff | comparison | revisions
--- a/src/eric7/EricWidgets/EricStringListEditWidget.py	Sun Dec 04 14:20:53 2022 +0100
+++ b/src/eric7/EricWidgets/EricStringListEditWidget.py	Mon Dec 05 11:37:42 2022 +0100
@@ -16,6 +16,8 @@
 )
 from PyQt6.QtWidgets import QInputDialog, QLineEdit, QWidget
 
+from eric7.EricWidgets import EricMessageBox
+
 from .Ui_EricStringListEditWidget import Ui_EricStringListEditWidget
 
 
@@ -32,7 +34,8 @@
         """
         Constructor
 
-        @param parent reference to the parent widget (QWidget)
+        @param parent reference to the parent widget
+        @type QWidget
         """
         super().__init__(parent)
         self.setupUi(self)
@@ -44,6 +47,12 @@
         self.stringList.setModel(self.__proxyModel)
 
         self.defaultButton.hide()
+        self.resetButton.hide()
+        self.resetLine.hide()
+
+        # store some internal state
+        self.__defaultVisible = False
+        self.__resetVisible = False
 
         self.searchEdit.textChanged.connect(self.__proxyModel.setFilterFixedString)
 
@@ -55,8 +64,10 @@
         """
         Public method to set the list of strings to be edited.
 
-        @param stringList list of strings to be edited (list of string)
+        @param stringList list of strings to be edited
+        @type list of str
         """
+        self.__initialList = stringList[:]
         self.__model.setStringList(stringList)
         self.__model.sort(0)
 
@@ -64,7 +75,8 @@
         """
         Public method to get the edited list of strings.
 
-        @return edited list of string (list of string)
+        @return edited list of string
+        @rtype list of str
         """
         return self.__model.stringList()[:]
 
@@ -90,7 +102,8 @@
         """
         Public method to set a what's that help text for the string list.
 
-        @param txt help text to be set (string)
+        @param txt help text to be set
+        @type str
         """
         self.stringList.setWhatsThis(txt)
 
@@ -102,6 +115,19 @@
         @type bool
         """
         self.defaultButton.setVisible(visible)
+        self.__defaultVisible = visible
+        self.resetLine.setVisible(self.__defaultVisible and self.__resetVisible)
+
+    def setResetVisible(self, visible):
+        """
+        Public method to show or hide the reset button.
+
+        @param visible flag indicating the visibility of the reset button
+        @type bool
+        """
+        self.resetButton.setVisible(visible)
+        self.__resetVisible = visible
+        self.resetLine.setVisible(self.__defaultVisible and self.__resetVisible)
 
     def setAddVisible(self, visible):
         """
@@ -128,3 +154,20 @@
             self.__model.insertRow(self.__model.rowCount())
             self.__model.setData(self.__model.index(self.__model.rowCount() - 1), entry)
             self.__model.sort(0)
+
+    @pyqtSlot()
+    def on_resetButton_clicked(self):
+        """
+        Public slot to reset the list to its initial value.
+        """
+        ok = EricMessageBox.yesNo(
+            self,
+            self.tr("Reset List"),
+            self.tr(
+                "Do you really want to reset the list to its initial value? All changes"
+                " will be lost."
+            ),
+        )
+        if ok:
+            self.__model.setStringList(self.__initialList)
+            self.__model.sort(0)
--- a/src/eric7/EricWidgets/EricStringListEditWidget.ui	Sun Dec 04 14:20:53 2022 +0100
+++ b/src/eric7/EricWidgets/EricStringListEditWidget.ui	Mon Dec 05 11:37:42 2022 +0100
@@ -70,7 +70,7 @@
    </item>
    <item>
     <layout class="QGridLayout" name="gridLayout">
-     <item row="0" column="0" rowspan="6">
+     <item row="0" column="0" rowspan="8">
       <widget class="EricListView" name="stringList">
        <property name="alternatingRowColors">
         <bool>true</bool>
@@ -140,6 +140,23 @@
       </spacer>
      </item>
      <item row="5" column="1">
+      <widget class="QPushButton" name="resetButton">
+       <property name="toolTip">
+        <string>Press to reset the list to its initial value</string>
+       </property>
+       <property name="text">
+        <string>Re&amp;set</string>
+       </property>
+      </widget>
+     </item>
+     <item row="6" column="1">
+      <widget class="Line" name="resetLine">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+      </widget>
+     </item>
+     <item row="7" column="1">
       <widget class="QPushButton" name="defaultButton">
        <property name="toolTip">
         <string>Press to set the default list of values</string>
@@ -166,6 +183,7 @@
   <tabstop>addButton</tabstop>
   <tabstop>removeButton</tabstop>
   <tabstop>removeAllButton</tabstop>
+  <tabstop>resetButton</tabstop>
   <tabstop>defaultButton</tabstop>
  </tabstops>
  <resources/>

eric ide

mercurial