def _data_changed(self, old, new): if has_attributes(self.data): aa = self._assign_attribute aa.input = new self._update_data() self.outputs = [aa.output] else: self.outputs = [self.data] self.data_changed = True self.output_info.datasets = \ [get_tvtk_dataset_name(self.outputs[0])] # Add an observer to the VTK dataset after removing the one # for the old dataset. We use the messenger to avoid an # uncollectable reference cycle. See the # enthought.tvtk.messenger module documentation for details. if old is not None: old.remove_observer(self._observer_id) self._observer_id = new.add_observer('ModifiedEvent', messenger.send) new_vtk = tvtk.to_vtk(new) messenger.connect(new_vtk, 'ModifiedEvent', self._fire_data_changed) # Change our name so that our label on the tree is updated. self.name = self._get_name()
def _set_origin(self, value): # Ugly, but needed. w = tvtk.to_vtk(self.widget) old = w.GetOrigin() w.SetOrigin(list(value)) self.trait_property_changed("origin", old, value) self.update_plane()
def _set_origin(self, value): # Ugly, but needed. w = tvtk.to_vtk(self.widget) old = w.GetOrigin() w.SetOrigin(list(value)) self.trait_property_changed('origin', old, value) self.update_plane()
def OnPaint(self, event): """This method is overridden temporarily in order to create the light manager. This is necessary because it makes sense to create the light manager only when the widget is realized. Only when the widget is realized is the VTK render window created and only then are the default lights all setup correctly. This handler is removed on the first Paint event and the default paint handler of the wxVTKRenderWindowInteractor is used instead.""" # Call the original handler (this will Show the widget) self._vtk_control.OnPaint(event) if len(self.renderer.lights) == 0: # The renderer is not ready yet, we do not do anything, and # we do not remove this callback, so that it will be called # later. return # Now create the light manager. self.light_manager = light_manager.LightManager(self) renwin = self._renwin renwin.update_traits() vtk_rw = tvtk.to_vtk(renwin) renwin.add_observer('StartEvent', messenger.send) messenger.connect(vtk_rw, 'StartEvent', self._start_event_callback) renwin.add_observer('EndEvent', messenger.send) messenger.connect(vtk_rw, 'EndEvent', self._end_event_callback) # Reset the event handler to the default since our job is done. wx.EVT_PAINT(self._vtk_control, None) # Remove the default handler. wx.EVT_PAINT(self._vtk_control, self._vtk_control.OnPaint)
def _remove_listners(self): object = self.object kids = self.children_cache for key, val in kids.items(): if isinstance(val, tvtk.Collection): vtk_obj = tvtk.to_vtk(val) messenger.disconnect(vtk_obj, "ModifiedEvent", self._notify_children) else: object.on_trait_change(self._notify_children, key, remove=True)
def _remove_listners(self): object = self.object kids = self.children_cache for key, val in kids.items(): if isinstance(val, tvtk.Collection): vtk_obj = tvtk.to_vtk(val) messenger.disconnect(vtk_obj, 'ModifiedEvent', self._notify_children) else: object.on_trait_change(self._notify_children, key, remove=True)
def _recorder_changed(self, r): """When the recorder is set we add an event handler so we can record the change to the camera position after the interaction. """ iren = self._interactor if r is not None: self._script_id = r.get_script_id(self) id = iren.add_observer('EndInteractionEvent', messenger.send) self._camera_observer_id = id i_vtk = tvtk.to_vtk(iren) messenger.connect(i_vtk, 'EndInteractionEvent', self._record_camera_position) else: self._script_id = '' iren.remove_observer(self._camera_observer_id) i_vtk = tvtk.to_vtk(iren) messenger.disconnect(i_vtk, 'EndInteractionEvent', self._record_camera_position)
def paintEvent(self, e): """ Reimplemented to create the light manager only when needed. This is necessary because it makes sense to create the light manager only when the widget is realized. Only when the widget is realized is the VTK render window created and only then are the default lights all setup correctly. """ QVTKRenderWindowInteractor.paintEvent(self, e) scene = self._scene if scene.light_manager is None: scene.light_manager = light_manager.LightManager(scene) renwin = scene._renwin renwin.update_traits() vtk_rw = tvtk.to_vtk(renwin) renwin.add_observer('StartEvent', messenger.send) messenger.connect(vtk_rw, 'StartEvent', self._start_event_callback) renwin.add_observer('EndEvent', messenger.send) messenger.connect(vtk_rw, 'EndEvent', self._end_event_callback)
def __hash__(self): return hash(tvtk.to_vtk(self.object))
def get_children(self, obj): """Returns the child objects of a particular tvtk object in a dictionary, the keys are the trait names. This is used to generate the tree in the browser.""" vtk_obj = tvtk.to_vtk(obj) methods = self._get_methods(vtk_obj) kids = {} def _add_kid(key, x): if x is None: kids[key] = None else: if type(x) in (type([]), type(())): x1 = [i for i in x if isinstance(i, TVTKBase)] if x1: kids[key] = x1 elif isinstance(x, TVTKBase): if hasattr(x, '__iter__'): # Don't add iterable objects that contain non # acceptable nodes if len(list(x)) and isinstance(list(x)[0], TVTKBase): kids[key] = x else: kids[key] = x for method in methods: attr = camel2enthought(method[0]) if hasattr(obj, attr): _add_kid(attr, getattr(obj, attr)) # Check for sources and inputs. if hasattr(obj, 'number_of_sources'): srcs = [obj.get_source(i) \ for i in range(obj.number_of_sources)] _add_kid('source', srcs) elif hasattr(obj, 'source'): _add_kid('source', obj.source) if hasattr(obj, 'get_input'): inputs = [] if hasattr(obj, 'number_of_input_ports'): if obj.number_of_input_ports: # Sometimes not all the inputs can be retrieved using # 'get_input', as they may be sources (for instance # the ProbeFilter). inputs = list() for i in range(obj.number_of_input_ports): try: inputs.append(obj.get_input(i)) except TypeError: pass if not inputs: inputs = [obj.get_input()] else: inputs = [obj.get_input(i) \ for i in range(obj.number_of_inputs)] _add_kid('input', inputs) elif hasattr(obj, 'input'): _add_kid('input', obj.input) if hasattr(obj, 'producer_port'): _add_kid('producer_port', obj.producer_port) return kids