Guest User

Sample code for freezing mayavi

a guest
Jun 21st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. from traits.etsconfig.api import ETSConfig
  2. ETSConfig.toolkit = 'wx'
  3. from numpy import ogrid, sin
  4.  
  5. from traits.api import HasTraits, Instance
  6. from traitsui.api import View, Item
  7.  
  8. from mayavi.sources.api import ArraySource
  9. from mayavi.modules.api import IsoSurface
  10.  
  11. from mayavi.core.ui.api import SceneEditor, MlabSceneModel
  12.  
  13. from traitsui.handler import Handler
  14.  
  15.  
  16. class MayaviView(HasTraits):
  17.  
  18.     scene = Instance(MlabSceneModel, ())
  19.  
  20.     # The layout of the panel created by Traits
  21.     view = View(Item('scene', editor=SceneEditor(), resizable=True,
  22.                     show_label=False),
  23.                     resizable=True)
  24.  
  25.     def __init__(self):
  26.         HasTraits.__init__(self)
  27.         # Create some data, and plot it using the embedded scene's engine
  28.         x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
  29.         scalars = sin(x*y*z)/(x*y*z)
  30.         src = ArraySource(scalar_data=scalars)
  31.         self.scene.engine.add_source(src)
  32.         src.add_module(IsoSurface())
  33.  
  34. #-----------------------------------------------------------------------------
  35. # Wx Code
  36. import wx
  37.  
  38. class MainWindow(wx.Frame):
  39.  
  40.     def __init__(self, parent, id):
  41.         wx.Frame.__init__(self, parent, id, 'Mayavi in Wx')
  42.         self.mayavi_view = MayaviView()
  43.         # Use traits to create a panel, and use it as the content of this
  44.         # wx frame.
  45.         self.control = self.mayavi_view.edit_traits(
  46.                         parent=self,
  47.                         kind='subpanel').control
  48.         self.Show(True)
  49.  
  50. app = wx.PySimpleApp()
  51. frame = MainWindow(None, wx.ID_ANY)
  52. app.MainLoop()
Add Comment
Please, Sign In to add comment