trame_ex3.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from trame.app import get_server
  2. from trame.ui.vuetify import SinglePageLayout
  3. from trame.widgets import vtk, vuetify
  4. import vedo
  5. cone = vedo.Cone()
  6. axes = vedo.Axes(cone).unpack()
  7. plt = vedo.Plotter()
  8. plt += [cone, axes]
  9. # -----------------------------------------------------------------------------
  10. # Trame setup
  11. # -----------------------------------------------------------------------------
  12. server = get_server()
  13. state, ctrl = server.state, server.controller
  14. # -----------------------------------------------------------------------------
  15. # Functions
  16. # -----------------------------------------------------------------------------
  17. @state.change("resolution")
  18. def update_resolution(resolution, **kwargs):
  19. cone.color(resolution)
  20. ctrl.view_update()
  21. def reset_resolution():
  22. cone.color("red5")
  23. ctrl.view_update()
  24. # -----------------------------------------------------------------------------
  25. # GUI
  26. # -----------------------------------------------------------------------------
  27. with SinglePageLayout(server) as layout:
  28. layout.title.set_text("Use slider to change color")
  29. with layout.content:
  30. with vuetify.VContainer(
  31. fluid=True,
  32. classes="pa-0 fill-height",
  33. ):
  34. plt.reset_camera()
  35. view = vtk.VtkLocalView(plt.window)
  36. ctrl.view_update = view.update
  37. ctrl.view_reset_camera = view.reset_camera
  38. with layout.toolbar:
  39. vuetify.VSpacer()
  40. vuetify.VSlider(
  41. v_model=("resolution", "blue5"),
  42. min=3,
  43. max=60,
  44. step=1,
  45. hide_details=True,
  46. dense=True,
  47. style="max-width: 300px",
  48. )
  49. with vuetify.VBtn(icon=True, click=reset_resolution):
  50. vuetify.VIcon("mdi-restore")
  51. vuetify.VDivider(vertical=True, classes="mx-2")
  52. vuetify.VSwitch(
  53. v_model="$vuetify.theme.dark",
  54. hide_details=True,
  55. dense=True,
  56. )
  57. with vuetify.VBtn(icon=True, click=ctrl.view_reset_camera):
  58. vuetify.VIcon("mdi-crop-free")
  59. # -----------------------------------------------------------------------------
  60. # Main
  61. # -----------------------------------------------------------------------------
  62. server.start()