E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.

Sat, 21 Jul 2018 13:46:07 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 21 Jul 2018 13:46:07 +0200
changeset 6437
3dd851d1edf8
parent 6436
7fa64ad908c3
child 6438
bb9ebc8b4ea6
child 6449
575fa81d2e6d

E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.

APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.E5Gui.E5ListSelectionDialog.html file | annotate | diff | comparison | revisions
E5Gui/E5ListSelectionDialog.py file | annotate | diff | comparison | revisions
Project/Project.py file | annotate | diff | comparison | revisions
--- a/APIs/Python3/eric6.api	Fri Jul 20 20:24:29 2018 +0200
+++ b/APIs/Python3/eric6.api	Sat Jul 21 13:46:07 2018 +0200
@@ -970,8 +970,9 @@
 eric6.E5Gui.E5LineEditButton.E5LineEditButton.setMenu?4(menu)
 eric6.E5Gui.E5LineEditButton.E5LineEditButton?1(parent=None)
 eric6.E5Gui.E5ListSelectionDialog.E5ListSelectionDialog.getSelection?4()
+eric6.E5Gui.E5ListSelectionDialog.E5ListSelectionDialog.on_selectionList_itemChanged?4(itm)
 eric6.E5Gui.E5ListSelectionDialog.E5ListSelectionDialog.on_selectionList_itemSelectionChanged?4()
-eric6.E5Gui.E5ListSelectionDialog.E5ListSelectionDialog?1(entries, selectionMode=QAbstractItemView.ExtendedSelection, title="", message="", parent=None)
+eric6.E5Gui.E5ListSelectionDialog.E5ListSelectionDialog?1(entries, selectionMode=QAbstractItemView.ExtendedSelection, title="", message="", checkBoxSelection=False, parent=None)
 eric6.E5Gui.E5ListView.E5ListView.keyPressEvent?4(evt)
 eric6.E5Gui.E5ListView.E5ListView.removeAll?4()
 eric6.E5Gui.E5ListView.E5ListView.removeSelected?4()
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Fri Jul 20 20:24:29 2018 +0200
+++ b/Documentation/Help/source.qhp	Sat Jul 21 13:46:07 2018 +0200
@@ -4531,6 +4531,7 @@
       <keyword name="E5ListSelectionDialog (Constructor)" id="E5ListSelectionDialog (Constructor)" ref="eric6.E5Gui.E5ListSelectionDialog.html#E5ListSelectionDialog.__init__" />
       <keyword name="E5ListSelectionDialog (Module)" id="E5ListSelectionDialog (Module)" ref="eric6.E5Gui.E5ListSelectionDialog.html" />
       <keyword name="E5ListSelectionDialog.getSelection" id="E5ListSelectionDialog.getSelection" ref="eric6.E5Gui.E5ListSelectionDialog.html#E5ListSelectionDialog.getSelection" />
+      <keyword name="E5ListSelectionDialog.on_selectionList_itemChanged" id="E5ListSelectionDialog.on_selectionList_itemChanged" ref="eric6.E5Gui.E5ListSelectionDialog.html#E5ListSelectionDialog.on_selectionList_itemChanged" />
       <keyword name="E5ListSelectionDialog.on_selectionList_itemSelectionChanged" id="E5ListSelectionDialog.on_selectionList_itemSelectionChanged" ref="eric6.E5Gui.E5ListSelectionDialog.html#E5ListSelectionDialog.on_selectionList_itemSelectionChanged" />
       <keyword name="E5ListView" id="E5ListView" ref="eric6.E5Gui.E5ListView.html#E5ListView" />
       <keyword name="E5ListView (Module)" id="E5ListView (Module)" ref="eric6.E5Gui.E5ListView.html" />
--- a/Documentation/Source/eric6.E5Gui.E5ListSelectionDialog.html	Fri Jul 20 20:24:29 2018 +0200
+++ b/Documentation/Source/eric6.E5Gui.E5ListSelectionDialog.html	Sat Jul 21 13:46:07 2018 +0200
@@ -63,6 +63,9 @@
 <td><a href="#E5ListSelectionDialog.getSelection">getSelection</a></td>
 <td>Public method to retrieve the selected items.</td>
 </tr><tr>
+<td><a href="#E5ListSelectionDialog.on_selectionList_itemChanged">on_selectionList_itemChanged</a></td>
+<td>Private slot handling a change of an item.</td>
+</tr><tr>
 <td><a href="#E5ListSelectionDialog.on_selectionList_itemSelectionChanged">on_selectionList_itemSelectionChanged</a></td>
 <td>Private slot handling a change of the selection.</td>
 </tr>
@@ -73,7 +76,7 @@
 </table>
 <a NAME="E5ListSelectionDialog.__init__" ID="E5ListSelectionDialog.__init__"></a>
 <h4>E5ListSelectionDialog (Constructor)</h4>
-<b>E5ListSelectionDialog</b>(<i>entries, selectionMode=QAbstractItemView.ExtendedSelection, title="", message="", parent=None</i>)
+<b>E5ListSelectionDialog</b>(<i>entries, selectionMode=QAbstractItemView.ExtendedSelection, title="", message="", checkBoxSelection=False, parent=None</i>)
 <p>
         Constructor
 </p><dl>
@@ -89,6 +92,10 @@
 </dd><dt><i>message</i> (str)</dt>
 <dd>
 message to be show in the dialog
+</dd><dt><i>checkBoxSelection</i> (bool)</dt>
+<dd>
+flag indicating to select items via their
+            checkbox
 </dd><dt><i>parent</i> (QWidget)</dt>
 <dd>
 reference to the parent widget
@@ -108,6 +115,16 @@
 <dd>
 list of str
 </dd>
+</dl><a NAME="E5ListSelectionDialog.on_selectionList_itemChanged" ID="E5ListSelectionDialog.on_selectionList_itemChanged"></a>
+<h4>E5ListSelectionDialog.on_selectionList_itemChanged</h4>
+<b>on_selectionList_itemChanged</b>(<i>itm</i>)
+<p>
+        Private slot handling a change of an item.
+</p><dl>
+<dt><i>itm</i> (QListWidgetItem)</dt>
+<dd>
+reference to the changed item
+</dd>
 </dl><a NAME="E5ListSelectionDialog.on_selectionList_itemSelectionChanged" ID="E5ListSelectionDialog.on_selectionList_itemSelectionChanged"></a>
 <h4>E5ListSelectionDialog.on_selectionList_itemSelectionChanged</h4>
 <b>on_selectionList_itemSelectionChanged</b>(<i></i>)
--- a/E5Gui/E5ListSelectionDialog.py	Fri Jul 20 20:24:29 2018 +0200
+++ b/E5Gui/E5ListSelectionDialog.py	Sat Jul 21 13:46:07 2018 +0200
@@ -9,8 +9,9 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import pyqtSlot
-from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractItemView
+from PyQt5.QtCore import pyqtSlot, Qt
+from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractItemView, \
+    QListWidgetItem
 
 from .Ui_E5ListSelectionDialog import Ui_E5ListSelectionDialog
 
@@ -21,7 +22,7 @@
     """
     def __init__(self, entries,
                  selectionMode=QAbstractItemView.ExtendedSelection,
-                 title="", message="", parent=None):
+                 title="", message="", checkBoxSelection=False, parent=None):
         """
         Constructor
         
@@ -33,19 +34,32 @@
         @type str
         @param message message to be show in the dialog
         @type str
+        @param checkBoxSelection flag indicating to select items via their
+            checkbox
+        @type bool
         @param parent reference to the parent widget
         @type QWidget
         """
         super(E5ListSelectionDialog, self).__init__(parent)
         self.setupUi(self)
         
-        self.selectionList.setSelectionMode(selectionMode)
         if title:
             self.setWindowTitle(title)
         if message:
             self.messageLabel.setText(message)
         
-        self.selectionList.addItems(entries)
+        self.__checkCount = 0
+        self.__isCheckBoxSelection = checkBoxSelection
+        if self.__isCheckBoxSelection:
+            self.selectionList.setSelectionMode(QAbstractItemView.NoSelection)
+            for entry in entries:
+                itm = QListWidgetItem(entry)
+                itm.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
+                itm.setCheckState(Qt.Unchecked)
+                self.selectionList.addItem(itm)
+        else:
+            self.selectionList.setSelectionMode(selectionMode)
+            self.selectionList.addItems(entries)
         
         self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
     
@@ -54,8 +68,24 @@
         """
         Private slot handling a change of the selection.
         """
-        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
-            len(self.selectionList.selectedItems()) > 0)
+        if not self.__isCheckBoxSelection:
+            self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
+                len(self.selectionList.selectedItems()) > 0)
+    
+    def on_selectionList_itemChanged(self, itm):
+        """
+        Private slot handling a change of an item.
+        
+        @param itm reference to the changed item
+        @type QListWidgetItem
+        """
+        if self.__isCheckBoxSelection:
+            if itm.checkState() == Qt.Checked:
+                self.__checkCount += 1
+            else:
+                self.__checkCount -= 1
+            self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
+                self.__checkCount > 0)
     
     def getSelection(self):
         """
@@ -65,6 +95,12 @@
         @rtype list of str
         """
         entries = []
-        for item in self.selectionList.selectedItems():
-            entries.append(item.text())
+        if self.__isCheckBoxSelection:
+            for row in range(self.selectionList.count()):
+                item = self.selectionList.item(row)
+                if item.checkState() == Qt.Checked:
+                    entries.append(item.text())
+        else:
+            for item in self.selectionList.selectedItems():
+                entries.append(item.text())
         return entries
--- a/Project/Project.py	Fri Jul 20 20:24:29 2018 +0200
+++ b/Project/Project.py	Sat Jul 21 13:46:07 2018 +0200
@@ -5180,7 +5180,8 @@
         elif len(pkglists) > 1:
             dlg = E5ListSelectionDialog(
                 sorted(pkglists), title=self.tr("Create Plugin Archive"),
-                message=self.tr("Select package lists:"))
+                message=self.tr("Select package lists:"),
+                checkBoxSelection=True)
             if dlg.exec_() == QDialog.Accepted:
                 selectedLists = [os.path.join(self.ppath, s)
                                  for s in dlg.getSelection()]

eric ide

mercurial