eric6/E5Gui/E5ListSelectionDialog.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 8038
73ec029d4107
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to select from a list of strings.
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
6437
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
10 from PyQt5.QtCore import pyqtSlot, Qt
7252
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
11 from PyQt5.QtWidgets import (
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 QDialog, QDialogButtonBox, QAbstractItemView, QListWidgetItem
c5e3705073eb Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
13 )
5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_E5ListSelectionDialog import Ui_E5ListSelectionDialog
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class E5ListSelectionDialog(QDialog, Ui_E5ListSelectionDialog):
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing a dialog to select from a list of strings.
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 def __init__(self, entries,
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 selectionMode=QAbstractItemView.ExtendedSelection,
6437
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
24 title="", message="", checkBoxSelection=False, parent=None):
5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @param entries list of entries to select from
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @type list of str
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param selectionMode selection mode for the list
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @type QAbstractItemView.SelectionMode
8038
73ec029d4107 MicroPython: improved the support for "BBC micro:bit" and "Calliope mini".
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
32 @param title title of the dialog
5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 @type str
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param message message to be show in the dialog
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 @type str
6437
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
36 @param checkBoxSelection flag indicating to select items via their
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
37 checkbox
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
38 @type bool
5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @param parent reference to the parent widget
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @type QWidget
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 super(E5ListSelectionDialog, self).__init__(parent)
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.setupUi(self)
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 if title:
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.setWindowTitle(title)
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 if message:
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.messageLabel.setText(message)
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
6437
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
50 self.__checkCount = 0
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
51 self.__isCheckBoxSelection = checkBoxSelection
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
52 if self.__isCheckBoxSelection:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
53 self.selectionList.setSelectionMode(QAbstractItemView.NoSelection)
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
54 for entry in entries:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
55 itm = QListWidgetItem(entry)
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
56 itm.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
57 itm.setCheckState(Qt.Unchecked)
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
58 self.selectionList.addItem(itm)
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
59 else:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
60 self.selectionList.setSelectionMode(selectionMode)
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
61 self.selectionList.addItems(entries)
5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @pyqtSlot()
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 def on_selectionList_itemSelectionChanged(self):
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 Private slot handling a change of the selection.
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
6437
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
70 if not self.__isCheckBoxSelection:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
71 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
72 len(self.selectionList.selectedItems()) > 0)
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
73
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
74 def on_selectionList_itemChanged(self, itm):
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
75 """
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
76 Private slot handling a change of an item.
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
77
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
78 @param itm reference to the changed item
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
79 @type QListWidgetItem
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
80 """
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
81 if self.__isCheckBoxSelection:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
82 if itm.checkState() == Qt.Checked:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
83 self.__checkCount += 1
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
84 else:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
85 self.__checkCount -= 1
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
86 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
87 self.__checkCount > 0)
5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 def getSelection(self):
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 Public method to retrieve the selected items.
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 @return selected entries
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @rtype list of str
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 entries = []
6437
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
97 if self.__isCheckBoxSelection:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
98 for row in range(self.selectionList.count()):
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
99 item = self.selectionList.item(row)
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
100 if item.checkState() == Qt.Checked:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
101 entries.append(item.text())
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
102 else:
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
103 for item in self.selectionList.selectedItems():
3dd851d1edf8 E5ListSelectionDialog: added a selection mode for items to be selected via a checkbox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
104 entries.append(item.text())
5244
54a0f215a6f0 Added a dialog to select from a list and extended the plug-in archive build process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 return entries

eric ide

mercurial