def add_custom( self, label: str = "Other", typ: TypeStr = "string", default: None | float | str = None, regex: str | None = None, ): if typ == "string": self.widget_custom = widgets.LineEdit() elif typ == "int": self.widget_custom = widgets.SpinBox() elif typ == "float": self.widget_custom = widgets.DoubleSpinBox() else: raise ValueError(typ) # TODO: Enable this or add BAR radio and option. self.widget_custom.set_disabled() # type: ignore if default is not None: self.widget_custom.set_value(default) # type: ignore self.rb_other.setText(label) self.rb_other.toggled.connect( self.widget_custom.set_enabled) # type: ignore self.widget_custom.value_changed.connect( # type: ignore lambda: self.update_choice(True)) if regex and typ == "string": self.widget_custom.set_regex_validator(regex) # type: ignore layout = widgets.BoxLayout("horizontal") layout.add(self.rb_other) layout.add(self.widget_custom) self.box.add(layout)
def _create_widget(self) -> widgets.DoubleSpinBox: widget = widgets.DoubleSpinBox() widget.set_range(*self.range) widget.setSingleStep(self.step) widget.setSuffix(self.unit) if self.value is not None: widget.set_value(self.value) return widget
def test_doublespinbox(): widget = widgets.DoubleSpinBox() widget.set_disabled() widget.set_enabled() with open("data.pkl", "wb") as jar: pickle.dump(widget, jar) with open("data.pkl", "rb") as jar: widget = pickle.load(jar) repr(widget)
def __init__(self, label, default=None, min_val=None, max_val=None, unit="", step=0.1, slider=False, check=True): super().__init__(label, default=default, min_val=min_val, max_val=max_val, unit=unit, check=check) self.widget = widgets.DoubleSpinBox() self.widget.set_range(min_val, max_val) self.widget.setSingleStep(step) self.widget.setSuffix(unit) if default is not None: self.widget.set_value(default)
def __init__(self, title: str = "", parent: QtWidgets.QWidget | None = None): super().__init__(checkable=False, title=title) self.set_layout("vertical") self.rb_lineedit = widgets.RadioButton("String") self.lineedit = widgets.LineEdit() self.rb_spinbox = widgets.RadioButton("Number") self.spinbox = widgets.DoubleSpinBox() layout_lineedit = widgets.BoxLayout("horizontal") layout_lineedit.add(self.rb_lineedit) layout_lineedit.add(self.lineedit) layout_spinbox = widgets.BoxLayout("horizontal") layout_spinbox.add(self.rb_spinbox) layout_spinbox.add(self.spinbox) self.box.add(layout_lineedit) self.box.add(layout_spinbox) self.rb_spinbox.toggled.connect(self.spinbox.setEnabled) self.rb_spinbox.toggled.connect(self.lineedit.setDisabled) self.rb_lineedit.toggled.connect(self.lineedit.setEnabled) self.rb_lineedit.toggled.connect(self.spinbox.setDisabled) self.spinbox.value_changed.connect(self.on_value_change) self.lineedit.value_changed.connect(self.on_value_change) self.rb_lineedit.setChecked(True)
def test_doublespinbox(): widget = widgets.DoubleSpinBox() widget.show() widget.close()