示例#1
0
 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)
示例#2
0
def test_spinbox():
    widget = widgets.SpinBox()
    widget.set_disabled()
    widget.set_enabled()
    widget.set_value(10)
    widget.set_special_value("test")
    assert widget.is_valid()
    assert widget.get_value() == 10
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    repr(widget)
示例#3
0
 def __init__(self, label, default=None, min_val=0, max_val=None,
              unit="", step=1, slider=False, check=True):
     super().__init__(label, default=default, min_val=min_val, max_val=max_val,
                      unit=unit, check=check)
     if slider:
         self.widget = widgets.Slider()
     else:
         self.widget = widgets.SpinBox()
         self.widget.setSuffix(unit)
     self.widget.set_range(min_val, max_val)
     self.widget.setSingleStep(step)
     if default is not None:
         self.widget.set_value(default)
示例#4
0
 def _create_widget(
         self) -> custom_widgets.InputAndSlider | widgets.SpinBox:
     min_val = self.range[0]
     max_val = self.range[1]
     if min_val is not None and max_val is not None:
         widget = custom_widgets.InputAndSlider()
         widget.set_range(min_val, max_val)
     else:
         widget = widgets.SpinBox()
         widget.set_range(min_val, max_val)
         widget.setSuffix(self.unit)
     widget.set_step_size(self.step)
     if self.value is not None:
         widget.set_value(self.value)
     return widget
示例#5
0
 def __init__(
     self,
     bounds: tuple[int, int] | None = None,
     parent: QtWidgets.QWidget | None = None,
 ):
     super().__init__(parent)
     self.path = None
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.spinbox = widgets.SpinBox()
     layout.add(self.spinbox)
     self.slider = widgets.Slider()
     layout.add(self.slider)
     if bounds:
         self.set_range(*bounds)
     self.spinbox.valueChanged.connect(self.slider.set_value)
     self.slider.valueChanged.connect(self.spinbox.set_value)
     self.spinbox.valueChanged.connect(self.value_changed)
示例#6
0
def test_spinbox():
    widget = widgets.SpinBox()
    widget.show()