Skip to content

Commit

Permalink
docs(examples): improve some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Oct 18, 2024
1 parent d7596fb commit b337de2
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 18 deletions.
44 changes: 44 additions & 0 deletions examples/02_vuetify/01_menu_v3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout
from trame.widgets import vuetify3 as vuetify

# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------

server = get_server()
state, ctrl = server.state, server.controller

state.menu_items = ["one", "two", "three"]


def print_item(item):
print("Clicked on", item)


# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------

state.trame__title = "Menu example"

with SinglePageLayout(server) as layout:
with layout.toolbar:
vuetify.VSpacer()
with vuetify.VMenu():
with vuetify.Template(v_slot_activator="{ on, attrs }"):
with vuetify.VBtn(icon=True, v_bind="attrs", v_on="on"):
vuetify.VIcon("mdi-dots-vertical")
with vuetify.VList():
with vuetify.VListItem(
v_for="(item, i) in menu_items",
key="i",
value=["item"],
):
vuetify.VBtn(
"{{ item }}",
click=(print_item, "[item]"),
)

if __name__ == "__main__":
server.start()
32 changes: 32 additions & 0 deletions examples/09_advanced/external-esm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#

from trame.app import get_server
from trame.widgets import html
from trame.ui.html import DivLayout


class ExternalJS:
def __init__(self, server=None):
self.server = get_server(server)

self.server.enable_module(
{
"module_scripts": [
"https://esm.sh/[email protected]",
],
}
)
self.ui = self._build_ui()

def _build_ui(self):
with DivLayout(self.server):
html.Button("Click Me")


def main():
app = ExternalJS()
app.server.start()


if __name__ == "__main__":
main()
37 changes: 19 additions & 18 deletions examples/blogs/vtk-9.4/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

def setup_vtk():
renderer = vtk.vtkRenderer()
render_window = vtk.vtkRenderWindow()
render_window = vtk.vtkRenderWindow(off_screen_rendering=True)
render_window.AddRenderer(renderer)
render_window.off_screen_rendering = True

render_window_interactor = vtk.vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)
render_window_interactor.GetInteractorStyle().SetCurrentStyleToTrackballCamera()
render_window_interactor = vtk.vtkRenderWindowInteractor(
render_window=render_window
)
render_window_interactor.interactor_style.SetCurrentStyleToTrackballCamera()

# Pipeline
sphere_source = vtk.vtkSphereSource(
Expand All @@ -28,23 +28,24 @@ def setup_vtk():
resolution=30,
)

normals = vtk.vtkPolyDataNormals()
normals.compute_cell_normals = 1
normals.SetInputConnection(sphere_source.GetOutputPort())
normals = vtk.vtkPolyDataNormals(
compute_cell_normals=1,
input_connection=sphere_source.output_port,
)

cell_centers = vtk.vtkCellCenters()
cell_centers.SetInputConnection(normals.GetOutputPort())
cell_centers = vtk.vtkCellCenters(
input_connection=normals.output_port,
)

glyph_mapper = vtk.vtkGlyph3DMapper()
glyph_mapper.SetInputConnection(0, cell_centers.GetOutputPort())
glyph_mapper.SetInputConnection(1, cone_source.GetOutputPort())
glyph_mapper.orient = True
glyph_mapper.orientation_array = "Normals"
glyph_mapper = vtk.vtkGlyph3DMapper(
orient=True,
orientation_array="Normals",
input_connection=cell_centers.output_port,
source_connection=cone_source.output_port,
)

# Rendering
actor = vtk.vtkActor()
actor.SetMapper(glyph_mapper)
renderer.AddActor(actor)
renderer.AddActor(vtk.vtkActor(mapper=glyph_mapper))
renderer.ResetCamera()
render_window.Render()

Expand Down

0 comments on commit b337de2

Please sign in to comment.