| 246 | return dialog |
| 247 | |
| 248 | def setup(self): |
| 249 | for label, value in self.data: |
| 250 | if label is None and value is None: |
| 251 | # Separator: (None, None) |
| 252 | self.formlayout.addRow(QtWidgets.QLabel(" "), |
| 253 | QtWidgets.QLabel(" ")) |
| 254 | self.widgets.append(None) |
| 255 | continue |
| 256 | elif label is None: |
| 257 | # Comment |
| 258 | self.formlayout.addRow(QtWidgets.QLabel(value)) |
| 259 | self.widgets.append(None) |
| 260 | continue |
| 261 | elif tuple_to_qfont(value) is not None: |
| 262 | field = FontLayout(value, self) |
| 263 | elif (label.lower() not in BLACKLIST |
| 264 | and mcolors.is_color_like(value)): |
| 265 | field = ColorLayout(to_qcolor(value), self) |
| 266 | elif isinstance(value, str): |
| 267 | field = QtWidgets.QLineEdit(value, self) |
| 268 | elif isinstance(value, (list, tuple)): |
| 269 | if isinstance(value, tuple): |
| 270 | value = list(value) |
| 271 | # Note: get() below checks the type of value[0] in self.data so |
| 272 | # it is essential that value gets modified in-place. |
| 273 | # This means that the code is actually broken in the case where |
| 274 | # value is a tuple, but fortunately we always pass a list... |
| 275 | selindex = value.pop(0) |
| 276 | field = QtWidgets.QComboBox(self) |
| 277 | if isinstance(value[0], (list, tuple)): |
| 278 | keys = [key for key, _val in value] |
| 279 | value = [val for _key, val in value] |
| 280 | else: |
| 281 | keys = value |
| 282 | field.addItems(value) |
| 283 | if selindex in value: |
| 284 | selindex = value.index(selindex) |
| 285 | elif selindex in keys: |
| 286 | selindex = keys.index(selindex) |
| 287 | elif not isinstance(selindex, Integral): |
| 288 | _log.warning( |
| 289 | "index '%s' is invalid (label: %s, value: %s)", |
| 290 | selindex, label, value) |
| 291 | selindex = 0 |
| 292 | field.setCurrentIndex(selindex) |
| 293 | elif isinstance(value, bool): |
| 294 | field = QtWidgets.QCheckBox(self) |
| 295 | field.setChecked(value) |
| 296 | elif isinstance(value, Integral): |
| 297 | field = QtWidgets.QSpinBox(self) |
| 298 | field.setRange(-10**9, 10**9) |
| 299 | field.setValue(value) |
| 300 | elif isinstance(value, Real): |
| 301 | field = QtWidgets.QLineEdit(repr(value), self) |
| 302 | field.setCursorPosition(0) |
| 303 | field.setValidator(QtGui.QDoubleValidator(field)) |
| 304 | field.validator().setLocale(QtCore.QLocale("C")) |
| 305 | dialog = self.get_dialog() |