MCPcopy Create free account
hub / github.com/LabPy/lantz / DictFeatWidget

Class DictFeatWidget

lantz/ui/widgets.py:308–393  ·  view source on GitHub ↗

Widget to show a DictFeat. :param parent: parent widget. :param target: driver object to connect. :param feat: DictFeat to connect.

Source from the content-addressed store, hash-verified

306
307
308class DictFeatWidget(QtGui.QWidget):
309 """Widget to show a DictFeat.
310
311 :param parent: parent widget.
312 :param target: driver object to connect.
313 :param feat: DictFeat to connect.
314 """
315
316 def __init__(self, parent, target, feat):
317 super().__init__(parent)
318 self._feat = feat
319
320 layout = QtGui.QHBoxLayout(self)
321
322 if feat.keys:
323 wid = QtGui.QComboBox()
324 if isinstance(feat.keys, dict):
325 self._keys = list(feat.keys.keys())
326 else:
327 self._keys = list(feat.keys)
328
329 wid.addItems([str(key) for key in self._keys])
330 wid.currentIndexChanged.connect(self._combobox_changed)
331 else:
332 wid = QtGui.QLineEdit()
333 wid.textChanged.connect(self._lineedit_changed)
334
335 layout.addWidget(wid)
336 self._key_widget = wid
337
338 wid = WidgetMixin.from_feat(feat)
339 wid.bind_feat(feat)
340 wid.feat_key = self._keys[0]
341 wid.lantz_target = target
342 layout.addWidget(wid)
343 self._value_widget = wid
344
345 @QtCore.Slot(int, object, object)
346 def _combobox_changed(self, value, old_value=MISSING, other=MISSING):
347 self._value_widget.feat_key = self._keys[self._key_widget.currentIndex()]
348
349 @QtCore.Slot(str, object, object)
350 def _lineedit_changed(self, value, old_value=MISSING, other=MISSING):
351 self._value_widget.feat_key = self._key_widget.text()
352
353 def value(self):
354 """Get widget value.
355 """
356 return self._value_widget.value()
357
358 def setValue(self, value):
359 """Set widget value.
360 """
361 if value is MISSING:
362 return
363 self._value_widget.setValue(value)
364
365 def setReadOnly(self, value):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected