-
-
Notifications
You must be signed in to change notification settings - Fork 473
/
base.py
146 lines (117 loc) · 5.19 KB
/
base.py
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import pathlib
import param
from ...io.state import state
from ..base import BasicTemplate
from ..react import ReactTemplate
from ..theme import THEMES, DefaultTheme
_ROOT = pathlib.Path(__file__).parent
class FastBaseTemplate(BasicTemplate):
accent_base_color = param.String(doc="""
Optional body accent color override.""")
background_color = param.String(doc="""
Optional body background color override.""")
corner_radius = param.Integer(default=3, bounds=(0,25), doc="""
The corner radius applied to controls.""")
font = param.String(doc="""
The font to use.""")
font_url = param.String(doc="""
A font url to import.""")
header_neutral_color = param.String(doc="""
Optional header neutral color override.""")
header_accent_base_color = param.String(doc="""
Optional header accent color override.""")
neutral_color = param.String(doc="""
Optional body neutral color override.""")
theme_toggle = param.Boolean(default=True, doc="""
If True a switch to toggle the Theme is shown.""")
shadow = param.Boolean(doc="""
Optional shadow override. Whether or not to apply shadow.""")
sidebar_footer = param.String("", doc="""
A HTML string appended to the sidebar""")
# Might be extended to accordion or tabs in the future
main_layout = param.Selector(default="card", label="Layout", objects=["", "card"], doc="""
What to wrap the main components into. Options are '' (i.e. none) and 'card' (Default).
Could be extended to Accordion, Tab etc. in the future.""")
_css = [
_ROOT / "css/fast_root.css",
_ROOT / "css/fast_bokeh.css",
_ROOT / "css/fast_bokeh_slickgrid.css",
_ROOT / "css/fast_panel.css",
_ROOT / "css/fast_panel_dataframe.css",
_ROOT / "css/fast_panel_widgets.css",
_ROOT / "css/fast_panel_markdown.css",
_ROOT / "css/fast_awesome.css"
]
_js = _ROOT / "js/fast_template.js"
_resources = {
'js_modules': {
'fast-colors': 'https://unpkg.com/@microsoft/fast-colors@5.1.0',
'fast': 'https://unpkg.com/@microsoft/fast-components@1.13.0'
},
'bundle': False
}
__abstract = True
def __init__(self, **params):
query_theme = self._get_theme_from_query_args()
if query_theme:
params['theme'] = THEMES[query_theme]
elif "theme" not in params:
params['theme'] = DefaultTheme
elif isinstance(params['theme'], str):
params['theme'] = THEMES[params['theme']]
super().__init__(**params)
theme = self._get_theme()
if "background_color" not in params:
self.background_color = theme.style.background_color
if "accent_base_color" not in params:
self.accent_base_color = theme.style.accent_base_color
if "header_color" not in params:
self.header_color = theme.style.header_color
if "header_accent_base_color" not in params:
self.header_accent_base_color = theme.style.header_accent_base_color
if "header_background" not in params:
self.header_background = theme.style.header_background
if "neutral_color" not in params:
self.neutral_color = theme.style.neutral_color
if "header_neutral_color" not in params:
self.header_neutral_color = theme.style.header_neutral_color
if "corner_radius" not in params:
self.corner_radius = theme.style.corner_radius
if "font" not in params:
self.font = theme.style.font
if "font_url" not in params:
self.font_url = theme.style.font_url
if "shadow" not in params:
self.shadow = theme.style.shadow
@staticmethod
def _get_theme_from_query_args():
theme_arg = state.session_args.get("theme", None)
if not theme_arg:
return
theme_arg = theme_arg[0].decode("utf-8")
return theme_arg.strip("'").strip('"')
def _update_vars(self):
super()._update_vars()
style = self._get_theme().style
style.background_color = self.background_color
style.accent_base_color = self.accent_base_color
style.header_color = self.header_color
style.header_background = self.header_background
style.header_accent_base_color = self.header_accent_base_color
style.neutral_color = self.neutral_color
style.header_neutral_color = self.header_neutral_color
style.corner_radius = self.corner_radius
style.font = self.font
style.font_url = self.font_url
style.shadow = self.shadow
self._render_variables["style"] = style
self._render_variables["theme_toggle"] = self.theme_toggle
self._render_variables["theme"] = self.theme.__name__[:-5].lower()
self._render_variables["sidebar_footer"] = self.sidebar_footer
self._render_variables["main_layout"] = self.main_layout
class FastGridBaseTemplate(FastBaseTemplate, ReactTemplate):
"""
Combines the FastTemplate and the React template.
"""
_resources = dict(FastBaseTemplate._resources, js=ReactTemplate._resources['js'])
__abstract = True