Skip to content

Commit 0216b21

Browse files
committed
add gallery to landing page
sphinx-panels was broken so we switch to sphinx-design instead
1 parent 8c64801 commit 0216b21

File tree

13 files changed

+185
-84
lines changed

13 files changed

+185
-84
lines changed

docs/source/_exts/interactive_widget.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
from docutils.nodes import raw
4-
from docutils.parsers.rst import Directive
4+
from docutils.parsers.rst import Directive, directives
55
from sphinx.application import Sphinx
66

77

@@ -15,6 +15,10 @@ class IteractiveWidget(Directive):
1515
required_arguments = 1
1616
_next_id = 0
1717

18+
option_spec = {
19+
"no-activate-button": directives.flag,
20+
}
21+
1822
def run(self):
1923
IteractiveWidget._next_id += 1
2024
container_id = f"idom-widget-{IteractiveWidget._next_id}"
@@ -27,7 +31,12 @@ def run(self):
2731
<div id="{container_id}" class="interactive widget-container center-content" style="" />
2832
<script type="module">
2933
import {{ mountWidgetExample }} from "{_IDOM_STATIC_HOST}/_static/custom.js";
30-
mountWidgetExample("{container_id}", "{view_id}", "{_IDOM_EXAMPLE_HOST}");
34+
mountWidgetExample(
35+
"{container_id}",
36+
"{view_id}",
37+
"{_IDOM_EXAMPLE_HOST}",
38+
{"false" if "no-activate-button" in self.options else "true"},
39+
);
3140
</script>
3241
</div>
3342
""",

docs/source/_exts/widget_example.py

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from docutils.statemachine import StringList
55
from sphinx.application import Sphinx
66
from sphinx.util.docutils import SphinxDirective
7-
from sphinx_panels.tabs import TabbedDirective
7+
from sphinx_design.tabs import TabSetDirective
88

99

1010
here = Path(__file__).parent
@@ -17,7 +17,10 @@ class WidgetExample(SphinxDirective):
1717
required_arguments = 1
1818
_next_id = 0
1919

20-
option_spec = {"linenos": directives.flag}
20+
option_spec = {
21+
"linenos": directives.flag,
22+
"live-example-is-default-tab": directives.flag,
23+
}
2124

2225
def run(self):
2326
example_name = self.arguments[0]
@@ -30,45 +33,39 @@ def run(self):
3033
f"Missing example file named {py_ex_path} referenced by document {src_file}:{line_num}"
3134
)
3235

33-
py_code_tab = TabbedDirective(
34-
"WidgetExample",
35-
["Python Code"],
36-
{},
37-
_literal_include_py_lines(
36+
labeled_tab_items = {
37+
"Python Code": _literal_include_py(
3838
name=example_name,
3939
linenos=show_linenos,
4040
),
41-
self.lineno - 1,
42-
self.content_offset,
43-
"",
44-
self.state,
45-
self.state_machine,
46-
).run()
41+
"Live Example": _interactive_widget(
42+
name=example_name,
43+
use_activate_button="live-example-is-default-tab" not in self.options,
44+
),
45+
}
4746

4847
if (examples / f"{example_name}.js").exists():
49-
js_code_tab = TabbedDirective(
50-
"WidgetExample",
51-
["Javascript Code"],
52-
{},
53-
_literal_include_js_lines(
54-
name=example_name,
55-
linenos=show_linenos,
56-
),
57-
self.lineno - 1,
58-
self.content_offset,
59-
"",
60-
self.state,
61-
self.state_machine,
62-
).run()
63-
else:
64-
js_code_tab = []
65-
66-
example_tab = TabbedDirective(
48+
labeled_tab_items["Javascript Code"] = _literal_include_js(
49+
name=example_name,
50+
linenos=show_linenos,
51+
)
52+
53+
tab_label_order = (
54+
["Live Example", "Python Code", "Javascript Code"]
55+
if "live-example-is-default-tab" in self.options
56+
else ["Python Code", "Javascript Code", "Live Example"]
57+
)
58+
59+
return TabSetDirective(
6760
"WidgetExample",
68-
["Live Example"],
61+
[],
6962
{},
70-
_string_to_nested_lines(
71-
_interactive_widget_template.format(name=example_name)
63+
_make_tab_items(
64+
[
65+
(label, labeled_tab_items[label])
66+
for label in tab_label_order
67+
if label in labeled_tab_items
68+
]
7269
),
7370
self.lineno - 1,
7471
self.content_offset,
@@ -77,33 +74,52 @@ def run(self):
7774
self.state_machine,
7875
).run()
7976

80-
return py_code_tab + js_code_tab + example_tab
8177

82-
83-
def _literal_include_py_lines(name, linenos):
84-
return _string_to_nested_lines(
85-
_literal_include_template.format(
86-
name=name,
87-
ext="py",
88-
language="python",
89-
linenos=":linenos:" if linenos else "",
78+
def _make_tab_items(labeled_content_tuples):
79+
tab_items = ""
80+
for label, content in labeled_content_tuples:
81+
tab_items += _tab_item_template.format(
82+
label=label,
83+
content=content.replace("\n", "\n "),
9084
)
85+
return _string_to_nested_lines(tab_items)
86+
87+
88+
def _literal_include_py(name, linenos):
89+
return _literal_include_template.format(
90+
name=name,
91+
ext="py",
92+
language="python",
93+
linenos=":linenos:" if linenos else "",
9194
)
9295

9396

94-
def _literal_include_js_lines(name, linenos):
95-
return _string_to_nested_lines(
96-
_literal_include_template.format(
97-
name=name,
98-
ext="js",
99-
language="javascript",
100-
linenos=":linenos:" if linenos else "",
101-
)
97+
def _literal_include_js(name, linenos):
98+
return _literal_include_template.format(
99+
name=name,
100+
ext="js",
101+
language="javascript",
102+
linenos=":linenos:" if linenos else "",
102103
)
103104

104105

106+
def _interactive_widget(name, use_activate_button):
107+
return _interactive_widget_template.format(
108+
name=name,
109+
activate_button_opt="" if use_activate_button else ":no-activate-button:",
110+
)
111+
112+
113+
_tab_item_template = """
114+
.. tab-item:: {label}
115+
116+
{content}
117+
"""
118+
119+
105120
_interactive_widget_template = """
106121
.. interactive-widget:: {name}
122+
{activate_button_opt}
107123
"""
108124

109125

docs/source/_static/css/interactive-widget.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
color: #ffffff !important;
2020
text-transform: uppercase;
2121
text-decoration: none;
22-
background: #3980b9;
23-
border: 2px solid #3980b9 !important;
22+
background: #526cfe;
23+
border: 2px solid #526cfe !important;
2424
transition: all 0.1s ease 0s;
2525
box-shadow: 0 5px 10px var(--color-foreground-border);
2626
}
2727
.enable-widget-button:hover {
28-
color: #3980b9 !important;
28+
color: #526cfe !important;
2929
background: #ffffff;
3030
transition: all 0.1s ease 0s;
3131
}

docs/source/_static/css/larger-headings.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ h4,
55
h5,
66
h6 {
77
margin-top: 2em !important;
8-
margin-bottom: 0 !important;
98
font-weight: 900 !important;
109
}
1110

docs/source/_static/custom.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,12 +1884,30 @@ const HTTP_PROTO = LOC.protocol;
18841884
const WS_PROTO = HTTP_PROTO === "https:" ? "wss:" : "ws:";
18851885
const IDOM_MODULES_PATH = "/_modules";
18861886

1887-
function mountWidgetExample(mountID, viewID, idomServerHost) {
1888-
const idom_url = "//" + (idomServerHost || LOC.host);
1889-
const http_idom_url = HTTP_PROTO + idom_url;
1890-
const ws_idom_url = WS_PROTO + idom_url;
1887+
function mountWidgetExample(
1888+
mountID,
1889+
viewID,
1890+
idomServerHost,
1891+
useActivateButton
1892+
) {
1893+
const idomUrl = "//" + (idomServerHost || LOC.host);
1894+
const httpIdomUrl = HTTP_PROTO + idomUrl ;
1895+
const wsIdomUrl = WS_PROTO + idomUrl ;
18911896

18921897
const mountEl = document.getElementById(mountID);
1898+
1899+
console.log(useActivateButton);
1900+
1901+
if (!useActivateButton) {
1902+
mountLayoutWithWebSocket(
1903+
mountEl,
1904+
wsIdomUrl + `/_idom/stream?view_id=${viewID}`,
1905+
(source, sourceType) =>
1906+
loadImportSource(httpIdomUrl, source, sourceType)
1907+
);
1908+
return;
1909+
}
1910+
18931911
const enableWidgetButton = document.createElement("button");
18941912
enableWidgetButton.appendChild(document.createTextNode("Enable Widget"));
18951913
enableWidgetButton.setAttribute("class", "enable-widget-button");
@@ -1901,9 +1919,9 @@ function mountWidgetExample(mountID, viewID, idomServerHost) {
19011919
mountEl.setAttribute("class", "interactive widget-container");
19021920
mountLayoutWithWebSocket(
19031921
mountEl,
1904-
ws_idom_url + `/_idom/stream?view_id=${viewID}`,
1922+
wsIdomUrl + `/_idom/stream?view_id=${viewID}`,
19051923
(source, sourceType) =>
1906-
loadImportSource(http_idom_url, source, sourceType)
1924+
loadImportSource(httpIdomUrl, source, sourceType)
19071925
);
19081926
}
19091927
})

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
"sphinx.ext.extlinks",
5555
"sphinx.ext.autosectionlabel",
5656
# third party extensions
57-
"sphinx_panels",
5857
"sphinx_copybutton",
5958
"sphinx_reredirects",
59+
"sphinx_design",
6060
# custom extensions
6161
"async_doctest",
6262
"autogen_api_docs",

docs/source/custom_js/src/index.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,30 @@ const HTTP_PROTO = LOC.protocol;
55
const WS_PROTO = HTTP_PROTO === "https:" ? "wss:" : "ws:";
66
const IDOM_MODULES_PATH = "/_modules";
77

8-
export function mountWidgetExample(mountID, viewID, idomServerHost) {
9-
const idom_url = "//" + (idomServerHost || LOC.host);
10-
const http_idom_url = HTTP_PROTO + idom_url;
11-
const ws_idom_url = WS_PROTO + idom_url;
8+
export function mountWidgetExample(
9+
mountID,
10+
viewID,
11+
idomServerHost,
12+
useActivateButton
13+
) {
14+
const idomUrl = "//" + (idomServerHost || LOC.host);
15+
const httpIdomUrl = HTTP_PROTO + idomUrl ;
16+
const wsIdomUrl = WS_PROTO + idomUrl ;
1217

1318
const mountEl = document.getElementById(mountID);
19+
20+
console.log(useActivateButton);
21+
22+
if (!useActivateButton) {
23+
mountLayoutWithWebSocket(
24+
mountEl,
25+
wsIdomUrl + `/_idom/stream?view_id=${viewID}`,
26+
(source, sourceType) =>
27+
loadImportSource(httpIdomUrl, source, sourceType)
28+
);
29+
return;
30+
}
31+
1432
const enableWidgetButton = document.createElement("button");
1533
enableWidgetButton.appendChild(document.createTextNode("Enable Widget"));
1634
enableWidgetButton.setAttribute("class", "enable-widget-button");
@@ -22,9 +40,9 @@ export function mountWidgetExample(mountID, viewID, idomServerHost) {
2240
mountEl.setAttribute("class", "interactive widget-container");
2341
mountLayoutWithWebSocket(
2442
mountEl,
25-
ws_idom_url + `/_idom/stream?view_id=${viewID}`,
43+
wsIdomUrl + `/_idom/stream?view_id=${viewID}`,
2644
(source, sourceType) =>
27-
loadImportSource(http_idom_url, source, sourceType)
45+
loadImportSource(httpIdomUrl, source, sourceType)
2846
);
2947
}
3048
})

docs/source/examples/simple_dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async def animate():
6464
{
6565
"data": data,
6666
"style": {
67-
"parent": {"width": "500px"},
67+
"parent": {"width": "100%"},
6868
"data": {"stroke": "royalblue"},
6969
},
7070
}

docs/source/getting-started.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
Getting Started
22
===============
33

4-
Let's look at the example that you may have seen
5-
:ref:`at a glance <At a Glance>` on the homepage:
4+
Let's break down the following example:
65

76
.. example:: slideshow
87
:linenos:

docs/source/handling-events.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ to demonstrate this is the ``currentTime`` attribute of ``audio`` and ``video``
5959
elements. Normally this would be accessible via ``event.target.currenTime``, but here
6060
it's simply passed in under the key ``currentTime``:
6161

62-
.. example:: play_audio_sound
62+
.. example:: audio_player

0 commit comments

Comments
 (0)