Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from traits.etsconfig.api import ETSConfig
- ETSConfig.toolkit = 'wx'
- from numpy import ogrid, sin
- from traits.api import HasTraits, Instance
- from traitsui.api import View, Item
- from mayavi.sources.api import ArraySource
- from mayavi.modules.api import IsoSurface
- from mayavi.core.ui.api import SceneEditor, MlabSceneModel
- from traitsui.handler import Handler
- class MayaviView(HasTraits):
- scene = Instance(MlabSceneModel, ())
- # The layout of the panel created by Traits
- view = View(Item('scene', editor=SceneEditor(), resizable=True,
- show_label=False),
- resizable=True)
- def __init__(self):
- HasTraits.__init__(self)
- # Create some data, and plot it using the embedded scene's engine
- x, y, z = ogrid[-10:10:100j, -10:10:100j, -10:10:100j]
- scalars = sin(x*y*z)/(x*y*z)
- src = ArraySource(scalar_data=scalars)
- self.scene.engine.add_source(src)
- src.add_module(IsoSurface())
- #-----------------------------------------------------------------------------
- # Wx Code
- import wx
- class MainWindow(wx.Frame):
- def __init__(self, parent, id):
- wx.Frame.__init__(self, parent, id, 'Mayavi in Wx')
- self.mayavi_view = MayaviView()
- # Use traits to create a panel, and use it as the content of this
- # wx frame.
- self.control = self.mayavi_view.edit_traits(
- parent=self,
- kind='subpanel').control
- self.Show(True)
- app = wx.PySimpleApp()
- frame = MainWindow(None, wx.ID_ANY)
- app.MainLoop()
Add Comment
Please, Sign In to add comment