Skip to content

Commit

Permalink
docs(jupyter): more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Sep 1, 2023
1 parent 24964bc commit b962d9e
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 117 deletions.
153 changes: 41 additions & 112 deletions examples/jupyter/multi-tasks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@
"class Slider:\n",
" def __init__(self, server_name=None):\n",
" self.server = get_server(server_name)\n",
" self.ui = DivLayout(self.server, height=\"20px\")\n",
" with self.ui:\n",
" with DivLayout(self.server, height=\"20px\") as self.ui:\n",
" with html.Div(style=\"display: flex;\"):\n",
" html.Input(type=\"range\", v_model=(\"resolution\", 0), min=0, max=10)\n",
" html.Div(\"{{ resolution }}\")\n",
"\n",
" @property\n",
" def resolution(self):\n",
" return self.server.state.resolution\n",
" \n",
" @resolution.setter\n",
" def resolution(self, v):\n",
" with self.server.state as state:\n",
" state.resolution = v\n",
" "
]
},
Expand All @@ -47,13 +55,17 @@
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "21be32c94aa84f3cabd1fecaa364a603",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"True"
"HTML(value='<iframe id=\"a_trame__template_main\" src=\"http://localhost:52268/index.html?ui=main&reconnect=auto\""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
"output_type": "display_data"
}
],
"source": [
Expand All @@ -63,7 +75,9 @@
"\n",
"await a.ui.ready\n",
"await b.ui.ready\n",
"await c.ui.ready"
"await c.ui.ready\n",
"\n",
"a.ui"
]
},
{
Expand All @@ -76,132 +90,47 @@
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"a_trame__template_main\" src=\"http://localhost:60632/index.html?ui=main&reconnect=auto\" style=\"border: none; width: 100%; height: 20px;\"></iframe>"
"application/vnd.jupyter.widget-view+json": {
"model_id": "f6c8c75611534a36a0fa956d9f3ddd98",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(HTML(value='<iframe id=\"a_trame__template_main\" src=\"http://localhost:52268/index.html?ui=main&…"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "display_data"
"output_type": "execute_result"
}
],
"source": [
"a.ui"
"from ipywidgets import HBox\n",
"\n",
"HBox([\n",
" a.ui.ipywidget, b.ui.ipywidget, c.ui.ipywidget, \n",
" a.ui.ipywidget, b.ui.ipywidget, c.ui.ipywidget,\n",
"])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f98d8132-5169-4276-8ba7-e10b3242d0d4",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"b_trame__template_main\" src=\"http://localhost:60634/index.html?ui=main&reconnect=auto\" style=\"border: none; width: 100%; height: 20px;\"></iframe>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"b.ui"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "388c11f7-af78-4ba2-85b9-5adf927dbf25",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"c_trame__template_main\" src=\"http://localhost:60636/index.html?ui=main&reconnect=auto\" style=\"border: none; width: 100%; height: 20px;\"></iframe>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"c.ui"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "2ed92111-bdf5-48f8-b7bb-c8d97dabfd29",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"a_trame__template_main\" src=\"http://localhost:60632/index.html?ui=main&reconnect=auto\" style=\"border: none; width: 100%; height: 20px;\"></iframe>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"a.ui"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "87fa800f-d432-4ec9-b968-5237d3e25288",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"b_trame__template_main\" src=\"http://localhost:60634/index.html?ui=main&reconnect=auto\" style=\"border: none; width: 100%; height: 20px;\"></iframe>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"b.ui"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3aae2a72-2c74-4cf2-9a96-e2fa74e7c419",
"id": "885e43be-a04e-43d3-8e47-360c59df226f",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"c_trame__template_main\" src=\"http://localhost:60636/index.html?ui=main&reconnect=auto\" style=\"border: none; width: 100%; height: 20px;\"></iframe>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"c.ui"
"a.resolution = 2\n",
"b.resolution = 5\n",
"c.resolution = 9"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "885e43be-a04e-43d3-8e47-360c59df226f",
"id": "0bc9e95a-f7a7-445d-b6f5-ffafeb46847c",
"metadata": {},
"outputs": [],
"source": []
Expand Down
11 changes: 6 additions & 5 deletions examples/validation/panel/app_trame.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def __init__(self, server=None):
self.actor = self.ploter.add_mesh(ds, smooth_shading=True, lighting=True)
self.ploter.camera_position = DEFAULT_CAMERA
self.render_window = self.ploter.ren_win
self.actor.prop.RenderPointsAsSpheresOn()
self.actor.prop.SetPointSize(4)

# Set initial values
self.server.state.update(
Expand Down Expand Up @@ -102,7 +104,7 @@ def ui(self):
with quasar.QDrawer(
v_model=("show_drawer", True),
side="left",
overlay=True,
overlay=False,
bordered=True,
width=350,
):
Expand Down Expand Up @@ -266,10 +268,9 @@ def ui(self):
)

with quasar.QPageContainer(classes="fullscreen", style="z-index: 0;"):
with vtk.VtkRemoteView(
self.render_window,
interactive_ratio=1,
) as view:
rw = self.render_window
with vtk.VtkRemoteView(rw, interactive_ratio=1) as view:
# with vtk.VtkLocalView(rw, interactive_ratio=1) as view:
self.ctrl.view_update = view.update
self.ctrl.view_reset_camera = view.reset_camera

Expand Down
77 changes: 77 additions & 0 deletions examples/validation/panel/trame.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "f6eaccef-ef80-4a9b-8997-2c092cf7a09b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import os\n",
"os.environ[\"TRAME_DISABLE_V3_WARNING\"] = \"1\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ddbe0b48-eb10-4e72-a819-68c42bb744bd",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4258a3f1685146418948628ae84b4206",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HTML(value='<iframe id=\"trame_trame__template_main\" src=\"http://localhost:53781/index.html?ui=main&reconnect=a…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from app_trame import StHelens\n",
"\n",
"app = StHelens()\n",
"await app.ui.ready\n",
"app.ui"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eeeb5fd2-2ee0-4207-835c-ae9d7157b4e9",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit b962d9e

Please sign in to comment.