-
Notifications
You must be signed in to change notification settings - Fork 6
/
DialogCheckbox.py
58 lines (48 loc) · 2.02 KB
/
DialogCheckbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
from soma.qt_gui.qt_backend import QtGui, QtCore
from soma.qt_gui.qt_backend.QtCore import *
from soma.qt_gui.qt_backend.QtGui import *
class DialogCheckbox(QMessageBox):
def __init__(self, listOpt, titleWin="", titleList="", defaultSel=None):
super(DialogCheckbox, self).__init__()
# Get the Layout of the MessageBox
layout = self.layout()
# Create a layout to contain all the checkboxes
self.layoutList = QGridLayout();
layout.addLayout(self.layoutList, 1, 1)
self.checkbox = [None] * len(listOpt);
# Create all the the checkboxes
Nrows = 30
for i in range(0, len(listOpt)):
self.checkbox[i] = QCheckBox()
self.checkbox[i].setText(listOpt[i])
self.layoutList.addWidget(self.checkbox[i], i%Nrows, i/Nrows)
if (defaultSel is not None) and (i <= len(defaultSel)) and (defaultSel[i]):
self.checkbox[i].setCheckState(Qt.Checked)
# Configure dialog window
self.setWindowTitle(titleWin)
self.setText(titleList)
self.setStandardButtons(QMessageBox.Cancel |QMessageBox.Ok)
self.setDefaultButton(QMessageBox.Cancel)
def exec_(self, *args, **kwargs):
"""
Override the exec_ method so you can return the value of the checkbox
"""
# Wait for user input
res = QMessageBox.exec_(self, *args, **kwargs)
# Check selection of checkboxes
if res == QMessageBox.Ok:
resList = [None] * len(self.checkbox);
for i in range(0, len(self.checkbox)):
resList[i] = self.checkbox[i].isChecked()
else:
resList = None
return resList
# TEST FUNCTIONS
if __name__ == '__main__':
app = QApplication(sys.argv)
dialog = DialogCheckbox(["XXX_XXXX_XXX1", "XXX_XXXX_XXX2", "XXX_XXXX_XXX3", "XXX_XXXX_XXX4"], "Export", "Select options to run:", [True, True, False, False])
answer = dialog.exec_()
print(answer)
app.quit()
sys.exit(app.exec_())