Example #1
0
 def index(self):
     user_id = flask.session.setdefault('user_id', uuid.uuid4())
     root = View(_css_class='rootApp')
     self._setup_func(root)
     template = Template((Path(__file__).parent / 'static' /
                          'index_template.html').read_text())
     index_html = template.safe_substitute(app_name=self.app.name,
                                           gap=self.app.gap,
                                           content=root._render())
     View._clear_dirties()
     return index_html
Example #2
0
 def __init__(self, title, **kwargs):
     super().__init__(**kwargs)
     self.title_view = View(
         chrome=True,
         text=title,
         gap=0,
     )
     self.title_view.dock = self.top
     self.container = View(gap=0)
     self.container.dock = self.bottom
     self.container.top = self.title_view.bottom
Example #3
0
    def event_loop(self):
        view_id = flask.request.headers.get('Hx-Trigger')
        event_header = json.loads(
            urllib.parse.unquote(
                flask.request.headers.get('Triggering-Event')))
        animation_id = event_header['detail']['animationID']

        return View._process_event_loop(animation_id)
Example #4
0
 def __init__(self, alignment=None, padding=8, **kwargs):
     super().__init__()
     self._text_view = View(
         parent=self,
         style=BaseStyle,
         _css_class='label-content',
     )
     # self._text_view._mark_dirty = lambda: self._mark_dirty()
     self._css_class = 'label'
     self._alignment = self.DEFAULT_ALIGNMENT
     self.alignment = alignment or set(self.DEFAULT_ALIGNMENT)
     self.padding = padding
     self.apply(kwargs)
Example #5
0
    def handle_event(self):
        view_id = flask.request.headers.get('Hx-Trigger')
        event_header_raw = flask.request.headers.get('Triggering-Event')
        if event_header_raw:
            event_header = urllib.parse.unquote(event_header_raw)
            event_name = json.loads(event_header)['type']
        else:
            event_name = 'load'  # Load events do not include a "Triggering-Event" header
        view = View.get_view(view_id)
        value = flask.request.values.get(view_id)
        if value:
            view._properties['value'] = value  # No update to front

        return view._process_event(event_name, view)
Example #6
0
    def __init__(self, on=False, **kwargs):
        super().__init__()

        self._base_height = 24

        self.width = 40
        self.height = self._base_height

        self._circle = View(
            parent=self,
            width=22,
            height=22,
            top=1,
            corner_radius=11,
            background_color='white',
        )
        self.corner_radius = '50%'
        self.apply(kwargs)

        self._properties['on'] = on
        self._set_state_appearance()
Example #7
0
class Container(View):

    container = View()
Example #8
0
class Label(View):

    _DIMENSIONS = {
        'alignment_horizontal': {'left', 'center', 'right'},
        'alignment_vertical': {'top', 'middle', 'bottom'},
    }
    DEFAULT_ALIGNMENT = {'center', 'middle'}

    def __init__(self, alignment=None, padding=8, **kwargs):
        super().__init__()
        self._text_view = View(
            parent=self,
            style=BaseStyle,
            _css_class='label-content',
        )
        # self._text_view._mark_dirty = lambda: self._mark_dirty()
        self._css_class = 'label'
        self._alignment = self.DEFAULT_ALIGNMENT
        self.alignment = alignment or set(self.DEFAULT_ALIGNMENT)
        self.padding = padding
        self.apply(kwargs)

    font = View._passthrough('_text_view', 'font')
    font_size = View._passthrough('_text_view', 'font_size')
    text = View._passthrough('_text_view', 'text')
    text_style = View._passthrough('_text_view', 'style')

    @prop
    def alignment(self, *values):
        if not values:
            return self._alignment

        value = values[0]
        if not isinstance(value, (list, tuple, set)):
            value = {value}
        self._combine_keys(value)
        for dimension_key, keywords in self._DIMENSIONS.items():
            for key in keywords:
                if key in self._alignment:
                    setattr(self, dimension_key, key)

    def _combine_keys(self, values):
        for key in values:
            for dimension in self._DIMENSIONS.values():
                if key in dimension:
                    self._alignment = self._alignment.difference(dimension)
                    self._alignment.add(key)
                    break
            else:
                raise ValueError('Unknown label alignment value', key)
        return self._alignment

    alignment_horizontal = View._css_mapping_prop('alignment_horizontal',
                                                  'align-items', {
                                                      'left': 'flex-start',
                                                      'center': 'center',
                                                      'right': 'flex-end',
                                                  })
    alignment_vertical = View._css_mapping_prop('alignment_vertical',
                                                'justify-content', {
                                                    'top': 'flex-start',
                                                    'middle': 'center',
                                                    'bottom': 'flex-end',
                                                })