コード例 #1
0
ファイル: confirmer.py プロジェクト: talos-gis/Fidget
    def __init__(self, inner_template: TemplateLike[T] = None, layout_cls=None,
                 cancel_value: C = NO_CANCEL, close_on_confirm=None, ok_text=None, cancel_text=None,
                 window_modality=None, **kwargs):
        """
        :param inner_template: an inner template to wrap
        :param layout_cls: the class of the layout
        :param cancel_value: the value to parse upon the cancel button being clicked. If this argument is provided,
         a cancel button is created.
        :param close_on_confirm: whether to close this widget if Ok or Cancel is clicked and the value is valid.
        :param ok_text: text for the ok button
        :param cancel_text: text for the cancel button
        :param window_modality: the modality of the widget, convenience parameter
        :param kwargs: forwarded to Fidget
        """
        inner_template = only_valid(inner_template=inner_template, INNER_TEMPLATE=self.INNER_TEMPLATE, _self=self).template_of()

        super().__init__(inner_template.title, **kwargs)

        self.inner_template = inner_template

        self.inner: Fidget[T] = None
        self.ok_button: QPushButton = None
        self.cancel_button: QPushButton = None

        self.cancel_value = cancel_value
        self.make_cancel = cancel_value is not self.NO_CANCEL
        self.cancel_flag = False

        self.close_on_confirm = first_valid(close_on_confirm=close_on_confirm, CLOSE_ON_CONFIRM=self.CLOSE_ON_CONFIRM, _self=self)

        self.init_ui(layout_cls=layout_cls, ok_text=ok_text, cancel_text=cancel_text, modality=window_modality)

        self._inner_changed()
コード例 #2
0
ファイル: minimalist.py プロジェクト: talos-gis/Fidget
    def __init__(self, inner_template: TemplateLike[T] = None, outer_template: TemplateLike[T] = None, layout_cls=None,
                 initial_value: T = NOT_INITIAL, **kwargs):
        inner_template = only_valid(inner_template=inner_template, INNER_TEMPLATE=self.INNER_TEMPLATE,
                                    _self=self).template_of()

        super().__init__(inner_template.title, **kwargs)

        self.inner_template = inner_template
        self.outer_template = only_valid(outer_template=outer_template,
                                         OUTER_TEMPLATE=self.OUTER_TEMPLATE, _self=self).template_of()

        self.browse_btn: QPushButton = None

        self.question: FidgetQuestion[T] = None
        self.outer: Fidget[T] = None

        self.__value = None

        self.init_ui(layout_cls=layout_cls)

        initial_value = first_valid(initial_value=initial_value, INITIAL_VALUE=self.INITIAL_VALUE,
                                    _invalid=self.NOT_INITIAL, _self=self)

        self.fill_value(initial_value)
コード例 #3
0
ファイル: matrix.py プロジェクト: talos-gis/Fidget
    def __init__(self,
                 inner_template: TemplateLike[T] = None,
                 layout_cls=None,
                 rows: CountBounds = None,
                 columns: CountBounds = None,
                 row_button_text_func: Callable[[int], str] = None,
                 column_button_text_func: Callable[[int], str] = None,
                 scrollable=None,
                 **kwargs):
        self.row_bounds = CountBounds[first_valid(rows=rows,
                                                  ROWS=self.ROWS,
                                                  _self=self)]
        self.column_bounds = CountBounds[first_valid(columns=columns,
                                                     COLUMNS=self.COLUMNS,
                                                     _self=self)]

        inner_template = only_valid(inner_template=inner_template,
                                    INNER_TEMPLATE=self.INNER_TEMPLATE,
                                    _self=self).template_of()

        super().__init__(inner_template.title, **kwargs)

        self.inner_template = inner_template
        self.row_button_text_func = first_valid(
            row_button_text_func=row_button_text_func,
            ROW_BUTTON_TEXT_FUNC=self.ROW_BUTTON_TEXT_FUNC,
            _self=self)
        self.column_button_text_func = first_valid(
            column_button_text_func=column_button_text_func,
            COLUMN_BUTTON_TEXT_FUNC=self.COLUMN_BUTTON_TEXT_FUNC,
            _self=self)
        if self.column_button_text_func is ...:
            self.column_button_text_func = self.row_button_text_func

        self.grid_layout: QGridLayout = None
        self.inners: List[List[Fidget[
            T]]] = None  # first row, then column, self.inners[row][column]
        self.col_btns: List[QPushButton[T]] = None
        self.row_btns: List[QPushButton[T]] = None

        self.row_offset = None
        self.col_offset = None

        self.row_count = 0
        self.column_count = 0

        self.init_ui(layout_cls=layout_cls, scrollable=scrollable)
コード例 #4
0
    def __init__(self,
                 inner_template: FidgetTemplate[T] = None,
                 default_state=False,
                 layout_cls=None,
                 none_value: C = None,
                 **kwargs):
        """
        :param inner_template: the template to wrap
        :param default_state: whether the default value of the widget will be enabled
        :param layout_cls: the layout class
        :param none_value: the value to set when the widget is disabled
        :param kwargs: forwarded to Fidget
        """

        inner_template = only_valid(inner_template=inner_template,
                                    INNER_TEMPLATE=self.INNER_TEMPLATE,
                                    _self=self).template_of()

        inner_template.extract_default(sink=kwargs, upper_space=type(self))

        super().__init__(inner_template.title, **kwargs)

        self.inner_template = inner_template

        self.inner: Fidget[T] = None
        self.not_none_checkbox: QCheckBox = None
        self.warden: FidgetOptional.MouseWarden = None

        self.none_value = none_value
        none_names = self.singleton_names.get(self.none_value)
        if none_names:

            @high_priority
            def NoneParser(s: str):
                if s.lower() in none_names:
                    return self.none_value
                raise PlaintextParseError(
                    f'this parser only accepts {next(iter(none_names))}')

            self.none_parser = NoneParser
        else:
            self.none_parser = None

        self.init_ui(layout_cls)

        self.not_none_checkbox.setChecked(default_state)
コード例 #5
0
    def __init__(self,
                 title,
                 inner_templates: Iterable[TemplateLike] = None,
                 **kwargs):
        inner_templates = self._make_inner_templates(
            only_valid(inner_templates=inner_templates,
                       INNER_TEMPLATES=self.INNER_TEMPLATES,
                       _self=self))

        FidgetTemplate.extract_default(
            *self.inner_templates_values(inner_templates),
            sink=kwargs,
            upper_space=type(self))

        super().__init__(title, **kwargs)

        self.inner_templates = inner_templates

        self.inners = None
コード例 #6
0
    def __init__(self,
                 title,
                 inner_templates: Iterable[NamedTemplate[T]] = None,
                 frame_style=None,
                 selector_cls: Union[Type[Selector], str] = None,
                 layout_cls: Type[QBoxLayout] = None,
                 **kwargs):
        """
        :param title: the title
        :param inner_templates: an iterable of name-templates to act as key-value pairs
        :param frame_style: the frame style to apply to the encompassing frame, if any
        :param selector_cls: the class (or name) of a selector
        :param layout_cls: the class of the layout
        :param scrollable: whether to make the widget scrollable
        :param kwargs: forwarded to Fidget
        """
        self.inner_templates = dict(
            self._to_name_subtemplate(o)
            for o in only_valid(inner_templates=inner_templates,
                                INNER_TEMPLATES=self.INNER_TEMPLATES,
                                _self=self))

        FidgetTemplate.extract_default(*self.inner_templates.values(),
                                       sink=kwargs,
                                       upper_space=type(self),
                                       union=True)

        super().__init__(title, **kwargs)

        self.inners: Dict[str, Fidget[T]] = None

        self.selector: FidgetStacked.Selector = None

        selector_cls = first_valid(selector_cls=selector_cls,
                                   SELECTOR_CLS=self.SELECTOR_CLS,
                                   _self=self)
        if isinstance(selector_cls, str):
            selector_cls = self.selectors[selector_cls]
        self.selector_cls = selector_cls
        self.stacked: QStackedWidget = None

        self.init_ui(frame_style=frame_style, layout_cls=layout_cls)
コード例 #7
0
ファイル: table.py プロジェクト: talos-gis/Fidget
    def __init__(self,
                 title: str,
                 inner_templates: Iterable[TemplateLike[T]] = None,
                 layout_cls=None,
                 rows: CountBounds = None,
                 row_button_text_func: Callable[[int], str] = None,
                 scrollable=None,
                 **kwargs):
        self.row_bounds = CountBounds[first_valid(rows=rows,
                                                  ROWS=self.ROWS,
                                                  _self=self)]

        inner_templates = tuple(
            t.template_of()
            for t in only_valid(inner_templates=inner_templates,
                                INNER_TEMPLATES=self.INNER_TEMPLATES,
                                _self=self))

        super().__init__(title, **kwargs)

        self.inner_templates = inner_templates
        self.row_button_text_func = first_valid(
            row_button_text_func=row_button_text_func,
            ROW_BUTTON_TEXT_FUNC=self.ROW_BUTTON_TEXT_FUNC,
            _self=self)

        self.grid_layout: QGridLayout = None
        self.inners: List[List[Fidget[
            T]]] = None  # first row, then column, self.inners[row][column]
        self.col_labels: List[QLabel[T]] = None
        self.row_btns: List[QPushButton[T]] = None

        self.row_offset = 1
        self.col_offset = None

        self.row_count = 0
        self.column_count = None

        self.value_type: Type[NamedTuple] = None

        self.init_ui(layout_cls=layout_cls, scrollable=scrollable)
コード例 #8
0
    def __init__(self,
                 inner_template: FidgetTemplate[F] = None,
                 converter_func: Callable[[F], T] = None,
                 back_converter_func: Optional[Callable[[T], F]] = None,
                 layout_cls=None,
                 **kwargs):
        """
        :param inner_template: the template to wrap
        :param converter_func: a conversion function
        :param back_converter_func: a backwards conversion function
        :param kwargs: forwarded to either the inner template or Fidget
        """
        inner_template = only_valid(inner_template=inner_template,
                                    INNER_TEMPLATE=self.INNER_TEMPLATE,
                                    _self=self).template_of()

        template_args = {}

        for key in ('make_plaintext', 'make_indicator', 'make_title'):
            if key in kwargs:
                template_args[key] = kwargs[key]
            else:
                v = getattr(self, key.upper(), None)
                if v is not None:
                    template_args[key] = v
            kwargs[key] = True
        inner_template = inner_template.template(**template_args)

        super().__init__(inner_template.title, **kwargs)

        self.inner_template = inner_template
        self.inner: Fidget[F] = None
        self.converter_func = converter_func
        self.back_converter_func = back_converter_func

        self.init_ui(layout_cls=layout_cls)