discussion_942.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from vedo import *
  2. def scroll_left(obj, ename):
  3. global index
  4. i = (index - 1) % len(meshes)
  5. txt.text(meshes[i].name).c("k")
  6. plt.remove(meshes[index]).add(meshes[i])
  7. plt.reset_camera()
  8. index = i
  9. def scroll_right(obj, ename):
  10. global index
  11. i = (index + 1) % len(meshes)
  12. txt.text(meshes[i].name).c("k")
  13. plt.remove(meshes[index]).add(meshes[i])
  14. plt.reset_camera()
  15. index = i
  16. def flag(obj, ename):
  17. global index
  18. txt.text("Flag Button Pressed!").c("r")
  19. plt.reset_camera()
  20. # load some meshes
  21. m1 = Mesh(dataurl + "bunny.obj").c("green5")
  22. m2 = Mesh(dataurl + "apple.ply").c("red5")
  23. m3 = Mesh(dataurl + "beethoven.ply").c("blue5")
  24. m1.name = "a bunny"
  25. m2.name = "an apple"
  26. m3.name = "mr. beethoven"
  27. meshes = [m1, m2, m3]
  28. txt = Text2D(meshes[0].name, font="Courier", pos="top-center", s=1.5)
  29. plt = Plotter()
  30. bu = plt.add_button(
  31. scroll_right,
  32. pos=(0.8, 0.06), # x,y fraction from bottom left corner
  33. states=[">"], # text for each state
  34. c=["w"], # font color for each state
  35. bc=["k5"], # background color for each state
  36. size=40, # font size
  37. )
  38. bu = plt.add_button(
  39. scroll_left,
  40. pos=(0.2, 0.06), # x,y fraction from bottom left corner
  41. states=["<"], # text for each state
  42. c=["w"], # font color for each state
  43. bc=["k5"], # background color for each state
  44. size=40, # font size
  45. )
  46. bu = plt.add_button(
  47. flag,
  48. pos=(0.5, 0.06),
  49. states=["Flag"],
  50. c=["w"],
  51. bc=["r"],
  52. size=40,
  53. )
  54. index = 0 # init global index
  55. plt += txt
  56. plt.show(meshes[0]).close()