Exemplo n.º 1
0
 def __init__(self,
              children: ChildrenType = None,
              classes: ClassesType = None,
              row_classes: ClassesType = None,
              styles: StylesType = None,
              props: PropsType = None,
              events: EventsType = None):
     classes = merge_classes('column', classes
                             or self.defaults.get('classes', ''))
     self.row_classes = merge_classes(
         'row', row_classes or self.defaults.get('row_classes', ''))
     children = self._wrap_children(children)
     super().__init__(children, classes, styles, props, events)
Exemplo n.º 2
0
 def _wrap_children(self, children):
     result = []
     for child in children or []:
         if isinstance(child, Columns):
             wrapped_child = child
             wrapped_child.classes = merge_classes(wrapped_child.classes,
                                                   self.row_classes)
         else:
             wrapped_child = Div(children=[child], classes=self.row_classes)
         result.append(wrapped_child)
     return result
Exemplo n.º 3
0
 def _build_defaults(cls, defaults, custom):
     results = custom.copy()
     for category, settings in defaults.items():
         if category not in results:
             results[category] = settings
         elif '_classes' in category:
             results[category] = merge_classes(settings, results[category])
         elif isinstance(settings, dict):
             results[category] = build_props(settings, results[category])
         else:
             continue
     return results
Exemplo n.º 4
0
 def __init__(self,
              label: str = None,
              model: Model = None,
              appearance: str = 'editor',
              classes: ClassesType = None,
              label_classes: ClassesType = None,
              styles: StylesType = None,
              props: PropsType = None,
              events: EventsType = None,
              children: List[Slot] = None):
     """
     :param label:
     :param model:
     :param appearance: 'editor' or 'textarea'
     :param classes:
     :param styles:
     :param props:
     :param events:
     :param children:
     """
     model = model or Model('')
     if appearance == 'editor':
         raise NotImplementedError(
             'Cannot use appearance == "editor" '
             'at the moment since it is not editable for some reason'
             'and we couldn\'t fix it.')
         self.component = 'div'
         children = [
             label,
             QEditor(model=model,
                     classes=classes,
                     styles=styles,
                     props=props,
                     events=events,
                     children=children)
         ]
         label_classes = merge_classes(self.defaults['label_classes'],
                                       label_classes)
         super().__init__(classes=label_classes, children=children)
     else:
         self.component = 'q-input'
         props = build_props({'type': 'textarea'}, props, {
             'label': label,
             'v-model': model
         })
         super().__init__(classes=classes,
                          styles=styles,
                          props=props,
                          events=events,
                          children=children)
Exemplo n.º 5
0
 def __init__(self,
              title: str = None,
              href: PropValueType[str] = None,
              classes: ClassesType = None,
              styles: StylesType = None,
              children: ChildrenType = None,
              events: EventsType = None):
     if children is None and title is None:
         raise AssertionError(
             'either title or children parameter must be set')
     props = build_props(self.defaults['props'], {'href': href})
     styles = build_props(self.defaults['styles'], styles)
     if props['target'] == '_blank' and children is None:
         children = [QIcon('open_in_new')]
     if title is not None:
         children = [title] + (children or [])
     classes = merge_classes(self.defaults['classes'], classes or '')
     super().__init__(children=children,
                      props=props,
                      classes=classes,
                      styles=styles,
                      events=events)
Exemplo n.º 6
0
    def __init__(self,
                 label: str = None,
                 model: Model = None,
                 appearance: str = None,
                 min: Union[int, float] = None,
                 max: Union[int, float] = None,
                 props: PropsType = None,
                 field_props: PropsType = None,
                 field_classes: ClassesType = None,
                 field_styles: StylesType = None,
                 children: List[Slot] = None,
                 classes: ClassesType = None,
                 styles: StylesType = None,
                 events: EventsType = None):
        appearance = appearance or 'input'
        self.component = {
            'input': 'q-input',
            'knob': 'q-field',
            'slider': 'q-field'
        }[appearance]
        model = model or Model(0, self._type)
        model.modifiers.add('number')
        model.set_conversion(self._type)
        special_props = {'min': min, 'max': max}

        if appearance in {'knob', 'slider'}:
            min = 0 if min is None else min
            max = 100 if max is None else max
            component_class = {'knob': QKnob, 'slider': QSlider}[appearance]

            control_props = build_props({'snap': self._type == int}, props)
            control_props = build_props(self.defaults['control_props'],
                                        control_props)
            if self._type == float:
                control_props = build_props({'step': (max - min) / 1000},
                                            control_props)
            control_props = build_props(
                {
                    'label-position':
                    'before' if appearance == 'knob' else 'top'
                }, control_props, special_props)
            control = component_class(
                model=model,
                props=control_props,
                children=children,
                classes=classes,
                styles=styles,
                events=events,
            )
            label_position = control_props['label-position']

            field_props = build_props(
                {
                    'borderless': True,
                    'stack-label': True,
                }, field_props,
                {'label': label if label_position == 'top' else None})
            label_slot = []
            if label and label_position != 'top':
                field_classes = merge_classes(self.defaults['field_classes'],
                                              field_classes or '')
                if isinstance(label, str):
                    label = Div([label], classes=field_classes)
                label_position = {
                    'left': 'before',
                    'right': 'after'
                }.get(label_position, label_position)
                label_slot = [Slot(label_position, children=[label])]
            super().__init__(model=model,
                             props=field_props,
                             children=[Slot('control', [control])] +
                             label_slot)
        else:
            props = build_props({'type': 'number'}, props, special_props)
            props = build_props(props, field_props, {'label': label})
            classes = merge_classes(classes or '', field_classes or '')
            styles = build_props(styles or {}, field_styles)
            self.component = 'q-input'
            super().__init__(model=model,
                             classes=classes,
                             styles=styles,
                             props=props,
                             events=events,
                             children=children)