class ActorViewer(HasTraits):
engine = Instance(Engine, ())
scene = Instance(MlabSceneModel, ())
path = Str
label = Str
view = View(Item(name='scene',
editor=SceneEditor(scene_class=MayaviScene),
show_label=False,
resizable=True,
height=500,
width=500
),
)
def __init__(self, path, label, engine=None, **traits):
self.path = path
self.label = label
HasTraits.__init__(self, **traits)
self.engine.start()
if engine is not None:
self.scene=MlabSceneModel(engine=self.engine)
else:
self.scene=MlabSceneModel()
@on_trait_change('scene.activated')
def scene_initiation(self):
src=self.scene.mlab.pipeline.open(self.path+self.label+'.vtr')
self.scene.mlab.pipeline.iso_surface(src, contours=60, opacity=0.5)
out=self.scene.mlab.pipeline.outline(src, figure=self.scene.mayavi_scene, line_width=0.5)
out.outline_mode = "cornered"
self.scene.render() #test to prevent active_camera error
self.scene.mlab.view(40, 50, figure=self.scene.mayavi_scene)
ut.actor.actor.estimated_render_time = 0.0001
out.actor.actor.render_time_multiplier = 0.9029244662077185
out.actor.actor.reference_count = 3
class MainView(HasTraits):
actor_viewers = List(Instance(ActorViewer))
traits_view = View(Item("actor_viewers"
,
show_label=False,
style="custom",
editor=ListEditor(style="custom", # use the ActiveViewer View for the tab content
use_notebook=True,
# dock_style="tab",
page_name=".label", # this is the trait on ActorViewer to use for the tab name
deletable=True, # if True then the user can close tabs
),
),
resizable=True,
title='Multiple scenes',
)
if __name__ == '__main__':
filelist_sort=[]
actor_viewers_list=[]
abs_path = "/home/me/Documents/ddscat7.3.3_200717/"
filelist = os.listdir(abs_path)
for i in filelist:
if i.endswith(".vtr"):
filelist_sort.append(i)
filelist_sort.sort(key=lambda f: int(re.sub('\D', '', f)))
for i in filelist_sort:
if ("E2_" in i):
print("file name ", i)
a = ActorViewer(path=abs_path,label=i.strip('.vtr'))
actor_viewers_list.append(a)
main_view=main_view = MainView(actor_viewers=actor_viewers_list)
main_view.configure_traits()
file name E2_600_1.vtr
Exception occurred in traits notification handler for object: <__main__.ActorViewer object at 0x7f53d2ee4a90>, trait: scene, old value: <mayavi.tools.mlab_scene_model.MlabSceneModel object at 0x7f53d25f2220>, new value: <mayavi.tools.mlab_scene_model.MlabSceneModel object at 0x7f53d25ed1d0>
Traceback (most recent call last):
File "/home/me/anaconda3/envs/mayavi/lib/python3.8/site-packages/traits/trait_notifiers.py", line 524, in _dispatch_change_event
self.dispatch(handler, *args)
File "/home/me/anaconda3/envs/mayavi/lib/python3.8/site-packages/traits/trait_notifiers.py", line 486, in dispatch
handler(*args)
File "/home/me/Documents/ddscat7.3.3_200717/this_code.py", line 60, in scene_initiation
self.scene.mlab.view(40, 50, figure=self.scene.mayavi_scene)
File "/home/me/anaconda3/envs/mayavi/lib/python3.8/site-packages/mayavi/tools/camera.py", line 255, in view
cam = scene.camera
File "/home/me/anaconda3/envs/mayavi/lib/python3.8/site-packages/tvtk/pyface/tvtk_scene.py", line 709, in _get_camera
return self._renderer.active_camera
AttributeError: 'NoneType' object has no attribute 'active_camera'
--
You received this message because you are subscribed to the Google Groups "Enthought Tool Suite users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ets-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ets-users/3080d798-7782-4360-9ff6-e0aac1941537n%40googlegroups.com.
#!/usr/bin/env python
import os
# Enthought imports.
from traits.api import HasTraits, Instance, List, Str, on_trait_change
from traitsui.api import View, Item, ListEditor
from tvtk.pyface.scene_editor import SceneEditor
from mayavi.core.api import Engine
from mayavi.tools.mlab_scene_model import MlabSceneModel
from mayavi.core.ui.mayavi_scene import MayaviScene
######################################################################
class ActorViewer(HasTraits):
#Create a mayavi scene with a specified engine
engine = Instance(Engine, ())
scene = Instance(MlabSceneModel, ())
# load_next = Button('Load next')
path = Str
label = Str
# # Using 'scene_class=MayaviScene' adds a Mayavi icon to the toolbar,to pop up a dialog editing the pipeline.
view = View(Item(name='scene',
editor=SceneEditor(scene_class=MayaviScene),
show_label=False,
resizable=True,
height=500,
width=500
),
)
def __init__(self, infile, label, engine=None, **traits):
self.insrc = infile
self.label = label
HasTraits.__init__(self, **traits)
self.engine.start()
if engine is not None:
self.scene=MlabSceneModel(engine=self.engine)
else:
self.scene=MlabSceneModel()
@on_trait_change('scene.activated')
def scene_initiation(self):
src=self.scene.mlab.pipeline.open(self.insrc)
self.scene.mlab.pipeline.surface(src)
out=self.scene.mlab.pipeline.outline(src, figure=self.scene.mayavi_scene, line_width=0.5)
self.scene.render() #test to prevent active_camera error
self.scene.mlab.view(40, 50, figure=self.scene.mayavi_scene)
class MainView(HasTraits):
actor_viewers = List(Instance(ActorViewer))
traits_view = View(Item("actor_viewers",
show_label=False,
style="custom",
editor=ListEditor(style="custom", # use the ActiveViewer View for the tab content
use_notebook=True,
# dock_style="tab",
page_name=".label", # this is the trait on ActorViewer to use for the tab name
deletable=True, # if True then the user can close tabs
),
),
resizable=True,
title='Multiple scenes',
)
if __name__ == '__main__'
:
actor_viewers_list=[]
filelist = os.listdir()
for i in filelist:
if i.endswith(".vtr"
):
a = ActorViewer(i, label=i)
actor_viewers_list.append(a)
main_view=main_view = MainView(actor_viewers=actor_viewers_list)
main_view.configure_traits()
<?xml version="1.0"?>
<VTKFile type="RectilinearGrid" version="0.1" byte_order="LittleEndian">
<RectilinearGrid WholeExtent="0 5 0 5 0 0">
<Piece Extent="0 5 0 5 0 0">
<CellData Scalars="cell_scalars">
<DataArray type="Float32" Name="cell_scalars" format="ascii">
0.2 0.2 0.2 0.2 0.2
0.2 0.4 0.6 0.4 0.2
0.2 0.6 0.8 0.6 0.2
0.2 0.4 0.6 0.4 0.2
0.2 0.2 0.2 0.2 0.2
</DataArray>
</CellData>
<PointData Scalars="colorful">
<DataArray type="Float32" Name="colorful" format="ascii">
0.2 0.2 0.2 0.2 0.2 0.2
0.2 0.4 0.6 0.6 0.4 0.2
0.2 0.6 0.8 0.8 0.6 0.2
0.2 0.6 0.8 0.8 0.6 0.2
0.2 0.4 0.6 0.6 0.4 0.2
0.2 0.2 0.2 0.2 0.2 0.2
</DataArray>
</PointData>
<Coordinates>
<DataArray type="Float32" format="ascii" RangeMin="0" RangeMax="5">
0.0 1.0 2.0 3.0 4.0 5.0
</DataArray>
<DataArray type="Float32" format="ascii" RangeMin="0" RangeMax="5">
0.0 1.0 2.0 3.0 4.0 5.0
</DataArray>
<DataArray type="Float32" format="ascii">
0.0
</DataArray>
</Coordinates>
</Piece>
</RectilinearGrid>
</VTKFile>
To view this discussion on the web visit https://groups.google.com/d/msgid/ets-users/e40060dd-5cb9-4b1d-8c70-a4bc529992ddn%40googlegroups.com.