holoviz / panel
1 7
import pathlib
2

3 7
import param
4

5 7
from ...io.state import state
6 7
from ..base import BasicTemplate
7 7
from ..react import ReactTemplate
8 7
from ..theme import THEMES, DefaultTheme
9

10 7
_ROOT = pathlib.Path(__file__).parent
11

12

13 7
class FastBaseTemplate(BasicTemplate):
14 7
    accent_base_color = param.String(doc="""
15
        Accent color override.""")
16

17 7
    header_accent_base_color = param.String(doc="""
18
        Optional header accent color override.""")
19

20 7
    theme_toggle = param.Boolean(default=True, doc="""
21
        If True a switch to toggle the Theme is shown.""")
22

23 7
    sidebar_footer = param.String("", doc="""
24
        A HTML string appended to the sidebar""")
25

26 7
    _css = [
27
        _ROOT / "css/fast_root.css",
28
        _ROOT / "css/fast_bokeh.css",
29
        _ROOT / "css/fast_bokeh_slickgrid.css",
30
        _ROOT / "css/fast_panel.css",
31
        _ROOT / "css/fast_panel_dataframe.css",
32
        _ROOT / "css/fast_panel_widgets.css",
33
        _ROOT / "css/fast_panel_markdown.css",
34
        _ROOT / "css/fast_awesome.css"
35
    ]
36

37 7
    _js = _ROOT / "js/fast_template.js"
38

39 7
    _resources = {
40
        'js_modules': {
41
            'fast-colors': 'https://unpkg.com/@microsoft/fast-colors@5.1.0',
42
            'fast': 'https://unpkg.com/@microsoft/fast-components@1.13.0'
43
        },
44
        'bundle': False
45
    }
46

47 7
    __abstract = True
48

49 7
    def __init__(self, **params):
50 7
        query_theme = self._get_theme_from_query_args()
51 7
        if query_theme:
52 0
            params['theme'] = THEMES[query_theme]
53 7
        elif "theme" not in params:
54 7
            params['theme'] = DefaultTheme
55 7
        elif isinstance(params['theme'], str):
56 7
            params['theme'] = THEMES[params['theme']]
57

58 7
        super().__init__(**params)
59 7
        theme = self._get_theme()
60 7
        if "accent_base_color" not in params:
61 7
            self.accent_base_color = theme.style.accent_base_color
62 7
        if "header_color" not in params:
63 7
            self.header_color = theme.style.header_color
64 7
        if "header_accent_base_color" not in params:
65 7
            self.header_accent_base_color = theme.style.header_accent_base_color
66 7
        if "header_background" not in params:
67 7
            self.header_background = theme.style.header_background
68

69 7
    @staticmethod
70 2
    def _get_theme_from_query_args():
71 7
        theme_arg = state.session_args.get("theme", None)
72 7
        if not theme_arg:
73 7
            return
74 0
        theme_arg = theme_arg[0].decode("utf-8")
75 0
        return theme_arg.strip("'").strip('"')
76

77 7
    def _update_vars(self):
78 7
        super()._update_vars()
79 7
        style = self._get_theme().style
80 7
        style.accent_base_color = self.accent_base_color
81 7
        style.header_color = self.header_color
82 7
        style.header_background = self.header_background
83 7
        style.header_accent_base_color = self.header_accent_base_color
84 7
        self._render_variables["style"] = style
85 7
        self._render_variables["theme_toggle"] = self.theme_toggle
86 7
        self._render_variables["theme"] = self.theme.__name__[:-5].lower()
87 7
        self._render_variables["sidebar_footer"] = self.sidebar_footer
88

89

90 7
class FastGridBaseTemplate(FastBaseTemplate, ReactTemplate):
91
    """
92
    Combines the FastTemplate and the React template.
93
    """
94

95 7
    _resources = dict(FastBaseTemplate._resources, js=ReactTemplate._resources['js'])
96

97 7
    __abstract = True

Read our documentation on viewing source code .

Loading