def __init__(self, title: str, pattern: Union[str, Pattern[str]] = None, allowed_characters: Container[str] = None, forbidden_characters: Container[str] = None, initial=None, **kwargs): super().__init__(title, **kwargs) pattern = optional_valid(pattern=pattern, PATTERN=self.PATTERN, _self=self) self.pattern: Optional[Pattern[str]] = re.compile( pattern) if isinstance(pattern, str) else pattern self.allowed_characters = optional_valid( allowed_characters=allowed_characters, ALLOWED_CHARACTERS=self.ALLOWED_CHARACTERS, _self=self) self.forbidden_characters = optional_valid( forbidden_characters=forbidden_characters, FORBIDDEN_CHARACTERS=self.FORBIDDEN_CHARACTERS, _self=self) self.initial = first_valid(initial=initial, INITIAL=self.INITIAL, _self=self)
def __init__(self, title, minimum=None, maximum=None, step=None, force_float=None, prefix=None, suffix=None, decimals=None, initial_value=None, **kwargs): super().__init__(title, **kwargs) minimum = first_valid(minimum=minimum, MINIMUM=self.MINIMUM, _self=self) maximum = first_valid(maximum=maximum, MAXIMUM=self.MAXIMUM, _self=self) step = first_valid(step=step, STEP=self.STEP, _self=self) decimals = optional_valid(decimals=decimals, DECIMALS=self.DECIMALS, _self=self) force_float = first_valid(force_float=force_float, FORCE_FLOAT=self.FORCE_FLOAT, _self=self) self.use_float = force_float or (decimals is not None) \ or any(isinstance(i, float) for i in (minimum, maximum, step)) prefix = optional_valid(prefix=prefix, PREFIX=self.PREFIX, _self=self) suffix = optional_valid(suffix=suffix, SUFFIX=self.SUFFIX, _self=self) self.spin: Union[QSpinBox, QDoubleSpinBox] = None self.init_ui(minimum=minimum, maximum=maximum, step=step, use_float=self.use_float, prefix=prefix, suffix=suffix, decimals=decimals, initial_value=initial_value)
def __init__(self, title, option=None, **kwargs): option = optional_valid(_self=self, option=option, OPTION=self.OPTION) if option: if 'options' in kwargs: raise TypeError('"option" and "options" arguments cannot be simultaneously used in FidgetConst') kwargs['options'] = [option] super().__init__(title, **kwargs) if len(self.options) != 1: raise ValueError('FidgetConst must have exactly 1 option, got ' + str(len(self.options))) self.label: QLabel = None self.init_ui() self.fill_initial()
def init_ui(self, minimum=None, maximum=None, step=None, use_float=None, prefix=None, suffix=None, decimals=None, initial_value=None): super().init_ui() layout = QHBoxLayout() with self.setup_provided(layout): spin_cls = QDoubleSpinBox if use_float else QSpinBox self.spin = spin_cls() self.spin.valueChanged[int].connect(self.change_value) if minimum: self.spin.setMinimum(minimum) if maximum: self.spin.setMaximum(maximum) if step: self.spin.setSingleStep(step) if prefix: self.spin.setPrefix(prefix) if suffix: self.spin.setSuffix(suffix) if decimals: self.spin.setDecimals(decimals) layout.addWidget(self.spin) if use_float: self.add_plaintext_delegates(FidgetFloat) else: self.add_plaintext_delegates(FidgetInt) initial_value = optional_valid(initial_value=initial_value, INITIAL_VALUE=self.INITIAL_VALUE, _self=self) if initial_value: self.spin.setValue(initial_value) self.setFocusProxy(self.spin) self.setLayout(layout) return layout
def __init__(self, title, *args, validation_func: Callable[[T], None] = None, auto_func: Callable[[], T] = None, make_title: bool = None, make_indicator: bool = None, make_plaintext: bool = None, help: str = None, **kwargs): """ :param title: the title of the Fidget :param args: additional arguments forwarded to QWidget :param validation_func: a validation callable, that will raise ValidationError if the parsed value is invalid :param auto_func: a function that returns an automatic value, to fill in the UI :param make_title: whether to create a title widget :param make_indicator: whether to make an indicator widget :param make_plaintext: whether to make a plaintext_edit widget :param help: a help string to describe the widget :param kwargs: additional arguments forwarded to QWidget :inheritors: don't set default values for these parameters, change the uppercase class variables instead. """ if kwargs.get('flags', None) is None: kwargs['flags'] = self.FLAGS if 'flags' in kwargs and __backend__.wrapper == QtWrapper.PYSIDE: kwargs['f'] = kwargs.pop('flags') try: super().__init__(*args, **kwargs) except (TypeError, AttributeError): print(f'args: {args}, kwargs: {kwargs}') raise self.title = title self.help = help self.make_title = first_valid(make_title=make_title, MAKE_TITLE=self.MAKE_TITLE, _self=self) self.make_indicator = first_valid(make_indicator=make_indicator, MAKE_INDICATOR=self.MAKE_INDICATOR, _self=self) self.make_plaintext = first_valid(make_plaintext=make_plaintext, MAKE_PLAINTEXT=self.MAKE_PLAINTEXT, _self=self) self.indicator_label: Optional[QLabel] = None self.auto_button: Optional[QPushButton] = None self.plaintext_button: Optional[QPushButton] = None self.title_label: Optional[QLabel] = None self._plaintext_widget: Optional[PlaintextEditWidget[T]] = None self.validation_func = validation_func self.auto_func = optional_valid(auto_func=auto_func, AUTO_FUNC=self.AUTO_FUNC, _self=self) self._suppress_update = False self._value: FidgetValue[T] = None self._joined_plaintext_printer = None self._joined_plaintext_parser = None self._plaintext_printer_delegates: List[Callable[[], Iterable[PlaintextPrinter[T]]]] = [] self._plaintext_parser_delegates: List[Callable[[], Iterable[PlaintextParser[T]]]] = [] if self.auto_func: if self.fill is None: raise Exception('auto_func can only be used on a Fidget with an implemented fill method') else: self.make_auto = True else: self.make_auto = False