def test_selectionwidget(qtbot): widget = custom_widgets.SelectionWidget() class Test: pass test = Test() items = {";": "Semicolon", "tab": "Tab", ",": "Comma", test: "class"} widget.add_items(items) widget.add_items(("a", "b")) widget.add_tooltip_icon("test") widget.add_custom(label="test", regex=r"\S{1}") radiobuttons = [k for k, v in widget.buttons.items()] radiobuttons[1].click() assert widget.get_value() == "tab" radiobuttons[3].click() assert widget.current_choice() == test for i in widget: pass widget.select_radio_by_data(";") choice = widget.current_choice() assert choice == ";" widget.set_value(",") assert widget.get_value() == "," widget.update_choice(True)
def test_selectionwidget(): widget = custom_widgets.SelectionWidget() items = {"Semicolon": ";", "Tab": "\t", "Comma": ","} widget.add_items(items) widget.add_custom(label="test", regex=r"\S{1}") choice = widget.current_choice() assert choice == ";"
def test_selectionwidget(): widget = custom_widgets.SelectionWidget() items = {"Semicolon": ";", "Tab": "\t", "Comma": ","} widget.add_items(items) widget.add_items(("a", "b")) widget.add_custom(label="test", regex=r"\S{1}") for i in widget: pass widget.select_radio_by_data(";") choice = widget.current_choice() assert choice == ";" widget.set_value(",") assert widget.get_value() == "," widget.update_choice(True)
def __init__(self, label, choices, value=None, check=True, radio=False): super().__init__(label, value=value, check=check) if radio: self.widget = custom_widgets.SelectionWidget(layout="vertical") else: self.widget = widgets.ComboBox() for item in choices: if isinstance(item, tuple): if len(item) == 2: self.widget.add(item[1], item[0]) elif len(item) == 3: self.widget.add(item[1], item[0], item[2]) else: self.widget.add(item) if value is not None: self.widget.set_value(value)
def _create_widget( self, ) -> custom_widgets.ColorChooserButton | widgets.ComboBox: if self.radio: widget = custom_widgets.SelectionWidget(layout="vertical") else: widget = widgets.ComboBox() if isinstance(self.choices, Mapping): widget.add_items(self.choices) else: for item in self.choices: if isinstance(item, tuple): if len(item) == 2: widget.add(item[1], item[0]) elif len(item) == 3: widget.add(item[1], item[0], item[2]) else: widget.add(item) if self.value is not None: widget.set_value(self.value) return widget