Beispiel #1
0
 def __init__(self, css: Union[hc.Css, hc.CssChunk], prob: float = 0.5):
     if isinstance(css, hc.CssChunk):
         css = hc.Css([css])
     choices = {
         css: prob,
         hc.Css(): 1 - prob,
     }
     super().__init__(choices)
Beispiel #2
0
    def get_css(self) -> hc.Css:
        if self.style_generator is None:
            return hc.Css()

        if self._css is None:
            self._css = self.style_generator(self.name)
        return self._css
Beispiel #3
0
    def __init__(self, klass: Union[hc.HtmlClass, str]):
        super().__init__(klass)

        self.css.add_style(kv.KLoc.L.get_css())

        self.css.add_style(
            hc.Css([
                # group container styles
                hc.CssChunk(
                    self.get_selector(SelectorType.GROUP),
                    {
                        'display': 'grid',
                        'grid-template-columns': 'auto',
                        'grid-gap': '5px 10px',  # vert, horz
                    }),

                # kv key styles
                hc.CssChunk(self.get_selector(SelectorType.KEY), {
                    'text-align': 'left',
                }),

                # kv value styles
                hc.CssChunk(self.get_selector(SelectorType.VALUE), {
                    'text-align': 'right',
                }),
            ]))
Beispiel #4
0
 def _call_inner(self,
                 kv_name: Optional[str] = None,
                 *args,
                 **kwargs) -> hc.Css:
     extra_css = hc.Css()
     if self.extra_css_creator is not None:
         extra_css += self.extra_css_creator()
     return self.kv_loc.get_css(kv_name).add_style(extra_css)
Beispiel #5
0
 def set_kv_horz_alignment(self, alignment: KvAlign):
     self.css.add_style(
         hc.Css([
             hc.CssChunk(self.get_selector(SelectorType.KEY), {
                 'text-align': alignment.key_alignment,
             }),
             hc.CssChunk(self.get_selector(SelectorType.VALUE), {
                 'text-align': alignment.value_alignment,
             }),
         ]))
Beispiel #6
0
    def get_css(
            self,
            kv_name: Optional[str] = None,
            containing_class: Optional[Union[hc.HtmlClass, str]] = None,
    ) -> hc.Css:
        kv_css = hc.Css()

        # TODO: clean this selector creation business up
        if kv_name is not None and containing_class is not None:
            raise ValueError(f'Only one of kv_name and containing_class may be set')
        elif containing_class is not None:
            if isinstance(containing_class, hc.HtmlClass):
                class_name = containing_class.name
            elif isinstance(containing_class, str):
                class_name = containing_class
            else:
                raise ValueError(f'containing_class should be either an HtmlClass or str.  '
                                 f'Got {type(containing_class)}')
            container_selector = hc.HtmlClassesNested([class_name, SelectorType.KV_CONTAINER.html_class_name])
            key_selector = hc.HtmlClassesNested([class_name, SelectorType.KEY.html_class_name])
            value_selector = hc.HtmlClassesNested([class_name, SelectorType.VALUE.html_class_name])
        else:
            # containing_class is None.  kv_name is set or is None
            container_selector = get_all_classes_container_selector(kv_name)
            key_selector = get_all_classes_key_selector(kv_name)
            value_selector = get_all_classes_value_selector(kv_name)

        kv_css.add_style(hc.CssChunk(
            container_selector,
            {
                'display': 'grid',
                'grid-template-columns': ' '.join(['auto'] * self.num_cols),
                'grid-template-rows': ' '.join(['auto'] * self.num_rows),
            },
        ))

        kv_css.add_style(hc.CssChunk(
            key_selector,
            {
                'grid-column-start': self.key_col,
                'grid-row-start': self.key_row,
            },
        ))

        kv_css.add_style(hc.CssChunk(
            value_selector,
            {
                'grid-column-start': self.value_col,
                'grid-row-start': self.value_row,
            },
        ))

        return kv_css
Beispiel #7
0
 def set_kv_vert_alignment(self, alignment: KvAlign):
     self.css.add_style(
         hc.Css([
             hc.CssChunk(
                 self.get_selector(SelectorType.KEY_OUTER), {
                     'display': 'flex',
                     'flex-direction': 'column',
                     'justify-content': alignment.key_alignment,
                     'height': '100%',
                 }),
             hc.CssChunk(
                 self.get_selector(SelectorType.VALUE_OUTER), {
                     'display': 'flex',
                     'flex-direction': 'column',
                     'justify-content': alignment.value_alignment,
                     'height': '100%',
                 }),
         ]))
Beispiel #8
0
    def __init__(self, klass: Union[hc.HtmlClass, str]):
        super().__init__(klass)
        self.html_chunks = []

        css = hc.Css([
            hc.CssChunk(self.get_selector(SelectorType.GROUP), {
                'border-collapse': 'collapse',
                'height': '1px',
            }),
            hc.CssChunk(
                self.get_selector(SelectorType.TDS_IN_GROUP), {
                    'border-style': 'solid',
                    'border-width': '1px',
                    'padding': '1px',
                    'height': '100%',
                }),
            hc.CssChunk(self.get_selector(SelectorType.TRS_IN_GROUP), {
                'height': '100%',
            }),
        ])
        self.add_style(css)
Beispiel #9
0
 def call_inner(self, values: Iterable[hc.Css], *args, **kwargs):
     css = hc.Css()
     for c in values:
         css.add_style(c)
     return css
Beispiel #10
0
 def __init__(self, klass: Union[hc.HtmlClass, str]):
     super().__init__(hc.Div('', classes=[klass]), hc.Css())
     self.klass = klass
     self.kvs = []