wx_window.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import wx
  2. from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor
  3. import vedo
  4. #####################################################
  5. # Every wx app needs an app
  6. app = wx.App(False)
  7. # create the top-level frame, sizer and wxVTKRWI
  8. frame = wx.Frame(None, -1, "vedo with wxpython", size=(600,600))
  9. widget = wxVTKRenderWindowInteractor(frame, -1)
  10. sizer = wx.BoxSizer(wx.VERTICAL)
  11. sizer.Add(widget, 1, wx.EXPAND)
  12. frame.SetSizer(sizer)
  13. frame.Layout()
  14. # It would be more correct (API-wise) to call widget.Initialize() and
  15. # widget.Start() here, but Initialize() calls RenderWindow.Render().
  16. # That Render() call will get through before we can setup the
  17. # RenderWindow() to render via the wxWidgets-created context; this
  18. # causes flashing on some platforms and downright breaks things on
  19. # other platforms. Instead, we call widget.Enable().
  20. widget.Enable(1)
  21. widget.AddObserver("ExitEvent", lambda o,e,f=frame: f.Close())
  22. ##################################################### vedo example
  23. def func(evt):
  24. print("Event dump:\n", evt)
  25. plt.azimuth(10) # rotate by one degree the camera
  26. cone = vedo.shapes.Cone(c='green8')
  27. axes = vedo.Axes(cone, c='white')
  28. cube = vedo.shapes.Cube()
  29. # Create 2 subwindows with a cone and a cube
  30. plt = vedo.Plotter(N=2, bg='blue2', bg2='blue8', wx_widget=widget)
  31. plt.add_callback("right mouse click", func)
  32. plt.at(0).add([cone, axes, "right-click anywhere"]).reset_camera()
  33. plt.at(1).add(cube).reset_camera()
  34. # plt.show() # vedo.show() is now disabled in wx
  35. #####################################################
  36. # Show everything
  37. frame.Show()
  38. app.MainLoop()