Embedding mayaVI within wxPython

爱⌒轻易说出口 提交于 2019-12-13 03:20:57

问题


UPDATE: I've placed print commands within the code to isolate the moment of error. The output for the below code is a b c d. I ended up switching to pyqt/pyside using the alternative code provided, but please let me know if I can help in any other way from my current setup in debugging this issue.

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

class MayaviView(HasTraits):

    scene = Instance(MlabSceneModel, ())

    print "a"

    view = View(Item('scene', editor=SceneEditor(), resizable=True,
                show_label=False),
                resizable=True)

    print "b"

    def __init__(self):

        print "z"

        HasTraits.__init__(self)
        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

print "c"

class MainWindow(wx.Frame):

    print "d"

    def __init__(self, parent, id):

        print "e"

        wx.Frame.__init__(self, parent, id, 'Mayavi in Wx')
        self.mayavi_view = MayaviView()
        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()

Initial Post:

I'm trying to reproduce the official code on mayaVI's website for embedding in wxWidgets (Wx embedding example).

The first error occurs while using app = wx.PySimpleApp(), and I change it to app = wx.App(False) via an online suggestion.

After this step, the program runs without command line error, but hangs during the data visualization step (the python visualization window never opens up, but does appear as an icon).

To test that my modules were installed correctly, I used MayaVI's official Qt example (Qt embedding example) - and it worked perfectly.

Details: I'm running Pythonw v=2.7.14 within a conda environment, with wxPython v=4.0.1 (osx-cocoa phoenix) and mayaVI v=4.5.0, all via macOS High Sierra Version 10.13.3.

Any advice on this matter would be a huge help - let me know if I can answer anything myself.

来源:https://stackoverflow.com/questions/48628650/embedding-mayavi-within-wxpython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!