Skip to content

Commit 8b4cf3a

Browse files
committed
docs(jupyter): update example with TrameApp
1 parent 3a7f8f2 commit 8b4cf3a

File tree

3 files changed

+25
-49
lines changed

3 files changed

+25
-49
lines changed
-124 KB
Loading
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
# Exposing a trame application into Jupyter
22

3-
## Disable warning
4-
5-
```python
6-
import os
7-
os.environ["TRAME_DISABLE_V3_WARNING"] = "1"
8-
```
9-
103
## Define application
114

125
<<< @/../../examples/core_features/jupyter.py
@@ -15,8 +8,7 @@ os.environ["TRAME_DISABLE_V3_WARNING"] = "1"
158

169
```python
1710
cone = Cone()
18-
await cone.ui.ready
19-
cone.ui
11+
cone
2012
```
2113

2214
![Trame in Jupyer](/assets/images/deployment/jupyter.png)
@@ -26,4 +18,3 @@ cone.ui
2618
```python
2719
cone.resolution = 4
2820
```
29-

examples/core_features/jupyter.py

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
from trame.app import get_server
2-
from trame.ui.vuetify import SinglePageLayout
3-
from trame.widgets import html, vtk, vuetify
1+
from trame.app import TrameApp
2+
from trame.ui.vuetify3 import SinglePageLayout
3+
from trame.widgets import html, vtk, vuetify3
44

55

6-
class Cone:
6+
class Cone(TrameApp):
77
def __init__(self, name=None):
8-
self.server = get_server(name, client_type="vue2")
9-
self._ui = None
10-
11-
# Build UI
12-
self.ui
13-
14-
@property
15-
def state(self):
16-
return self.server.state
17-
18-
@property
19-
def ctrl(self):
20-
return self.server.controller
8+
super().__init__(server=name)
9+
self._build_ui()
2110

2211
@property
2312
def resolution(self):
@@ -31,25 +20,21 @@ def resolution(self, v):
3120
def reset_resolution(self):
3221
self.resolution = 6
3322

34-
@property
35-
def ui(self):
36-
if self._ui is None:
37-
with SinglePageLayout(self.server) as layout:
38-
self._ui = layout
39-
with layout.toolbar:
40-
html.Div("a: {{ a }}")
41-
vuetify.VSpacer()
42-
vuetify.VSlider(
43-
v_model=("resolution", 6), min=3, max=60, hide_details=True
44-
)
45-
vuetify.VBtn("Reset", click=self.reset_resolution)
46-
with layout.content:
47-
with vuetify.VContainer(fluid=True, classes="pa-0 fill-height"):
48-
with vtk.VtkView() as vtk_view:
49-
self.ctrl.reset_camera = vtk_view.reset_camera
50-
with vtk.VtkGeometryRepresentation():
51-
vtk.VtkAlgorithm(
52-
vtkClass="vtkConeSource", state=("{ resolution }",)
53-
)
54-
55-
return self._ui
23+
def _build_ui(self):
24+
with SinglePageLayout(self.server) as self.ui:
25+
self.ui.icon.click = self.ctrl.reset_camera
26+
with self.ui.toolbar:
27+
html.Div("resolution: {{ resolution }}")
28+
vuetify3.VSpacer()
29+
vuetify3.VSlider(
30+
v_model=("resolution", 6), min=3, max=60, step=1, hide_details=True
31+
)
32+
vuetify3.VBtn("Reset", click=self.reset_resolution)
33+
with self.ui.content:
34+
with vuetify3.VContainer(fluid=True, classes="pa-0 fill-height"):
35+
with vtk.VtkView() as vtk_view:
36+
self.ctrl.reset_camera = vtk_view.reset_camera
37+
with vtk.VtkGeometryRepresentation():
38+
vtk.VtkAlgorithm(
39+
vtkClass="vtkConeSource", state=("{ resolution }",)
40+
)

0 commit comments

Comments
 (0)