-
Notifications
You must be signed in to change notification settings - Fork 109
/
index.py
95 lines (84 loc) · 2.59 KB
/
index.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
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from texts import (
URL_KOFI,
URL_REPO,
KINEMATICS_PAGE_PATH,
IK_PAGE_PATH,
PATTERNS_PAGE_PATH,
ROOT_PATH,
)
from settings import DEBUG_MODE
from style_settings import GLOBAL_PAGE_STYLE
from app import app
from pages import page_inverse, page_kinematics, page_patterns, page_landing
server = app.server
# ....................
# Navigation partials
# ....................
icon_link_style = {"margin": "0 0 0 0.5em"}
div_header = html.Div(
[
html.A(html.H6("👾"), href=URL_REPO, target="_blank", style=icon_link_style),
html.A(html.H6("☕"), href=URL_KOFI, target="_blank", style=icon_link_style),
dcc.Link(html.H6("●"), href=PATTERNS_PAGE_PATH, style=icon_link_style),
dcc.Link(html.H6("●"), href=IK_PAGE_PATH, style=icon_link_style),
dcc.Link(html.H6("●"), href=KINEMATICS_PAGE_PATH, style=icon_link_style),
dcc.Link(html.H6("●"), href=ROOT_PATH, style=icon_link_style),
],
style={"display": "flex", "flex-direction": "row"},
)
div_footer = html.Div(
[
html.A("👾 Source Code", href=URL_REPO, target="_blank"),
html.Br(),
html.A("☕ Buy Mithi coffee", href=URL_KOFI, target="_blank"),
html.Br(),
dcc.Link("● Leg Patterns", href=PATTERNS_PAGE_PATH),
html.Br(),
dcc.Link("● Inverse Kinematics", href=IK_PAGE_PATH),
html.Br(),
dcc.Link("● Kinematics", href=KINEMATICS_PAGE_PATH),
html.Br(),
dcc.Link("● Root", href=ROOT_PATH),
html.Br(),
],
)
# ....................
# Page layout
# ....................
app.layout = html.Div(
[
div_header,
dcc.Location(id="url", refresh=False),
html.Div(id="page-content"),
div_footer,
],
style=GLOBAL_PAGE_STYLE,
)
# ....................
# URL redirection
# ....................
PAGES = {
IK_PAGE_PATH: page_inverse.layout,
KINEMATICS_PAGE_PATH: page_kinematics.layout,
PATTERNS_PAGE_PATH: page_patterns.layout,
ROOT_PATH: page_landing.layout,
}
# ....................
# Callback to display page given URL
# ....................
@app.callback(Output("page-content", "children"), [Input("url", "pathname")])
def display_page(pathname):
try:
return PAGES[pathname]
except KeyError:
return PAGES[ROOT_PATH]
# ....................
# Run server
# ....................
if __name__ == "__main__":
app.run_server(
debug=DEBUG_MODE, dev_tools_ui=DEBUG_MODE, dev_tools_props_check=DEBUG_MODE
)