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 from PySide import QtCore, QtGui
34
35 import roslib
36 import rospy
37 from parameter_dialog import ScrollArea
40 '''
41 This dialog creates an input mask for a string list and return selected entries.
42 '''
43
44 - def __init__(self, input=list(), buttons=QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok, exclusive=False, parent=None):
45 '''
46 Creates an input dialog.
47 @param input: a list with strings
48 @type input: C{list()}
49 '''
50 QtGui.QDialog.__init__(self, parent=parent)
51 self.setObjectName(' - '.join(['SelectDialog', str(input)]))
52
53 self.verticalLayout = QtGui.QVBoxLayout(self)
54 self.verticalLayout.setObjectName("verticalLayout")
55 self.verticalLayout.setContentsMargins(1, 1, 1, 1)
56
57
58 self.scrollArea = scrollArea = QtGui.QScrollArea(self);
59 scrollArea.setObjectName("scrollArea")
60 scrollArea.setWidgetResizable(True)
61 self.content = MainBox(self)
62 scrollArea.setWidget(self.content)
63 self.verticalLayout.addWidget(scrollArea)
64
65
66 if not exclusive:
67 options = QtGui.QWidget(self)
68 hLayout = QtGui.QHBoxLayout(options)
69 hLayout.setContentsMargins(1, 1, 1, 1)
70 self.select_all_checkbox = QtGui.QCheckBox('all')
71
72 self.select_all_checkbox.setCheckState(QtCore.Qt.CheckState.Checked)
73 self.select_all_checkbox.toggled.connect(self._on_select_all_checkbox_toggled)
74 hLayout.addWidget(self.select_all_checkbox)
75
76 spacerItem = QtGui.QSpacerItem(515, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
77 hLayout.addItem(spacerItem)
78 self.verticalLayout.addWidget(options)
79
80
81 self.buttonBox = QtGui.QDialogButtonBox(self)
82 self.buttonBox.setObjectName("buttonBox")
83 self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
84 self.buttonBox.setStandardButtons(buttons)
85 self.buttonBox.accepted.connect(self.accept)
86 self.buttonBox.rejected.connect(self.reject)
87 self.verticalLayout.addWidget(self.buttonBox)
88
89
90 if input:
91 self.content.createFieldsFromValues(input, exclusive)
92
93
94
95
96
97
100
102 self.content.filter(self.filter_field.text())
103
106
107 @staticmethod
108 - def getValue(title, input=list(), exclusive=False, parent=None):
109 selectDia = SelectDialog(input, exclusive=exclusive, parent=parent)
110 selectDia.setWindowTitle(title)
111 selectDia.resize(480, 256)
112 if selectDia.exec_():
113 return selectDia.getSelected()
114 return list()
115
116
117
118
119
120
122 self.setResult(QtGui.QDialog.Accepted)
123 self.hide()
124
126 self.setResult(QtGui.QDialog.Rejected)
127 self.hide()
128
131
133 '''
134 Test the open files for changes and save this if needed.
135 '''
136 self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
137 QtGui.QDialog.closeEvent(self, event)
138
139
140 -class MainBox(QtGui.QWidget):
141 '''
142 A widget with entries.
143 '''
144 - def __init__(self, parent=None):
145 QtGui.QWidget.__init__(self, parent)
146 self.setObjectName("MainBox")
147 boxLayout = QtGui.QFormLayout()
148 boxLayout.setVerticalSpacing(0)
149 self.box_group = QtGui.QButtonGroup(self)
150 self.setLayout(boxLayout)
151
152 - def createFieldsFromValues(self, values, exclusive=False):
153 self.setUpdatesEnabled(False)
154 self.box_group.setExclusive(exclusive)
155 try:
156 if isinstance(values, list):
157 for v in values:
158 checkbox = QtGui.QCheckBox(v)
159 checkbox.setObjectName(v)
160 self.box_group.addButton(checkbox)
161 self.layout().addRow(checkbox)
162 checkbox.setCheckState(QtCore.Qt.CheckState.Checked)
163 finally:
164 self.setUpdatesEnabled(True)
165
166 - def getSelected(self):
167 result = list()
168 for i in range(self.layout().count()):
169 item = self.layout().itemAt(i).widget()
170 if isinstance(item, QtGui.QCheckBox):
171 if item.isChecked():
172 result.append(item.text())
173 return result
174
175 - def setState(self, state):
176 for i in range(self.layout().count()):
177 item = self.layout().itemAt(i).widget()
178 if isinstance(item, QtGui.QCheckBox):
179 item.setCheckState(QtCore.Qt.CheckState.Checked if state else QtCore.Qt.CheckState.Unchecked)
180