You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having an issue where I cannot get Mayavi to render the window when embedded in a TraitsUI window. Specifically, if I run the following code (minimal representation of Mayavi scene in TraitsUI window), I get strange results:
# Enthought imports.
from traits.api import HasTraits, Instance
from traitsui.api import View, Item
from tvtk.pyface.scene_editor import SceneEditor
from mayavi.tools.mlab_scene_model import MlabSceneModel
from mayavi.sources.api import ParametricSurface
from mayavi import mlab
import pylab as pl
pl.ion()
class Mayavi(HasTraits):
scene = Instance(MlabSceneModel, ())
view = View(Item(name='scene', editor=SceneEditor(),
show_label=False, resizable=True, height=250,
width=500))
s = ParametricSurface()
m = Mayavi()
m.edit_traits()
mlab.pipeline.surface(s, figure=m.scene.mayavi_scene)
# this one comes up all black
img = mlab.screenshot(figure=m.scene.mayavi_scene)
pl.imshow(img)
# wait a second for the figure to appear, then it works correctly
The output of the first call to pl.imshow(img) is:
Once that pops up, the Mayavi screen then finally shows up on-screen, and renders correctly:
And after that has happened, re-running the two lines to get the screenshot and plot the image with pylab works:
So basically, I need a way to force Mayavi (and/or TraitsUI) to have the window 1) show up, and then 2) fully render before moving on to the screenshot() line. I've tried inserting mlab.draw() after the addition of the surface (immediately preceding mlab.screenshot() to no avail. It's possible this might be solvable by telling TraitsUI to draw the window and not return control until it has. If that's the case, it would be useful to add to the examples, since I've searched and not managed to find a workable solution to this...
Note that this is not an issue if the figure is created with mlab.figure() instead of being buried inside a TraitsUI window, but that is not a workable solution for my use case because I want to pull up several plots simultaneously (several Mayavi scenes) in the same window. This is part of a GUI that shows multiple views of the same object, and I need them to be rendered properly in order to determine certain useful properties (such as optimal camera distance) that, at the moment, is broken. I also can't for example, set the lighting properties, since after telling the windows to be created, the scenes aren't rendered immediately so the lights or light_manager property is None (whereas, again, if I wait a few seconds for the window to actually show up, those properties exist).
Running Mayavi 4.1.0 on Ubuntu Linux.
The text was updated successfully, but these errors were encountered:
Found a hackish way to do it by looking at how mlab.show() works; this allows the code to function, at least on my system. Adding this before the mlab.screenshot() call causes the correct screenshot to be taken:
The _gui.process_events() was not enough (although this caused the image to go from black to light gray). I needed both that and _gui.set_busy(busy=True) to get it to work. Somehow this seems sub-optimal to me. Is there a cleaner way?
Hello,
I am having an issue where I cannot get Mayavi to render the window when embedded in a TraitsUI window. Specifically, if I run the following code (minimal representation of Mayavi scene in TraitsUI window), I get strange results:
The output of the first call to
pl.imshow(img)
is:Once that pops up, the Mayavi screen then finally shows up on-screen, and renders correctly:
And after that has happened, re-running the two lines to get the screenshot and plot the image with pylab works:
So basically, I need a way to force Mayavi (and/or TraitsUI) to have the window 1) show up, and then 2) fully render before moving on to the
screenshot()
line. I've tried insertingmlab.draw()
after the addition of the surface (immediately precedingmlab.screenshot()
to no avail. It's possible this might be solvable by telling TraitsUI to draw the window and not return control until it has. If that's the case, it would be useful to add to the examples, since I've searched and not managed to find a workable solution to this...Note that this is not an issue if the figure is created with
mlab.figure()
instead of being buried inside a TraitsUI window, but that is not a workable solution for my use case because I want to pull up several plots simultaneously (several Mayavi scenes) in the same window. This is part of a GUI that shows multiple views of the same object, and I need them to be rendered properly in order to determine certain useful properties (such as optimal camera distance) that, at the moment, is broken. I also can't for example, set the lighting properties, since after telling the windows to be created, the scenes aren't rendered immediately so thelights
orlight_manager
property is None (whereas, again, if I wait a few seconds for the window to actually show up, those properties exist).Running Mayavi 4.1.0 on Ubuntu Linux.
The text was updated successfully, but these errors were encountered: