class BoolInputWidget(InputWidgetSingle): """Boolean data input widget""" def __init__(self, parent=None, **kwds): super(BoolInputWidget, self).__init__(parent=parent, **kwds) self.cb = QCheckBox(self) self.setWidget(self.cb) self.cb.stateChanged.connect( lambda val: self.dataSetCallback(bool(val))) def blockWidgetSignals(self, bLocked): self.cb.blockSignals(bLocked) def setWidgetValue(self, val): if bool(val): self.cb.setCheckState(QtCore.Qt.Checked) else: self.cb.setCheckState(QtCore.Qt.Unchecked)
class BoolEditor(BaseEditor, object): attr_type = 'bool' def __init__(self, parent=None, **kwargs): super(BoolEditor, self).__init__(parent=parent, **kwargs) self._default_value = False self.cbx = QCheckBox(self) self.main_layout.addWidget(self.cbx) self.cbx.toggled.connect(self.OnValueUpdated) def get_value(self): return self.cbx.isChecked() def initialize_editor(self): editor_value = self.default_value node_values = self.values if node_values: if len(node_values) > 1: pass elif len(node_values) == 1: if node_values[0]: editor_value = node_values[0] self.cbx.blockSignals(True) self.cbx.setChecked(editor_value) self.cbx.blockSignals(False) def set_connected(self, conn): if conn != self._connection: self._connection = conn self.value_line.setText(conn) self.cbx.setEnabled(False) self.value_line.setProperty('class', 'Connected')