This repository was archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_button.py
More file actions
105 lines (77 loc) · 2.52 KB
/
_button.py
File metadata and controls
105 lines (77 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""PytSite Button Widgets
"""
__author__ = 'Oleksandr Shepetko'
__email__ = 'a@shepetko.com'
__license__ = 'MIT'
import htmler
from typing import Union, List
from . import _base
class Button(_base.Abstract):
"""Button.
"""
def __init__(self, uid: str, **kwargs):
"""Init.
"""
super().__init__(uid, **kwargs)
self._css += ' inline'
self._icon = kwargs.get('icon')
self._color = kwargs.get('color', ['default', 'secondary'])
self._dismiss = kwargs.get('dismiss', None)
self._form_group = False
self._has_messages = False
self._html_em = htmler.Button(type='button')
if self._dismiss:
self._html_em.set_attr('data_dismiss', self._dismiss)
@property
def icon(self) -> str:
return self._icon
@icon.setter
def icon(self, value):
self._icon = value
@property
def color(self) -> Union[str, List[str]]:
return self._color
@color.setter
def color(self, value: Union[str, List[str]]):
self._color = value
def _get_element(self, **kwargs) -> htmler.Element:
"""Render the widget.
:param **kwargs:
"""
self._html_em.set_attr('uid', self._uid)
if isinstance(self._color, list):
self._html_em.set_attr('css', 'btn ' + ' '.join('btn-' + c for c in self._color))
else:
self._html_em.set_attr('css', 'btn btn-' + self._color)
self._html_em.append_text(self.get_val())
if self._icon and not self._html_em.children:
self._html_em.append_child(htmler.I(css=self._icon))
for k, v in self._data.items():
self._html_em.set_attr('data_' + k, v)
return self._html_em
class Submit(Button):
"""Submit Button.
"""
def __init__(self, uid: str, **kwargs):
"""Init.
"""
super().__init__(uid, **kwargs)
self._html_em = htmler.Button(type='submit')
if self._dismiss:
self._html_em.set_attr('data_dismiss', self._dismiss)
class Link(Button):
"""Link Button.
"""
def __init__(self, uid: str, **kwargs):
"""Init.
"""
super().__init__(uid, **kwargs)
self._html_em = htmler.A(href=kwargs.get('href', '#'))
if self._dismiss:
self._html_em.set_attr('data_dismiss', self._dismiss)
@property
def href(self) -> str:
return self._html_em.get_attr('href')
@href.setter
def href(self, value: str):
self._html_em.set_attr('href', value)