def _data_changed(self, old, new): if has_attributes(self.data): aa = self._assign_attribute self.configure_input_data(aa, new) self._update_data() aa.update() 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 # 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 _file_path_changed(self, fpath): value = fpath.get() if len(value) == 0: self.name = 'No VTK file' return else: self.reader.file_name = value self.update() # Setup the outputs by resetting self.outputs. Changing # the outputs automatically fires a pipeline_changed # event. try: n = self.reader.number_of_outputs except AttributeError: # for VTK >= 4.5 n = self.reader.number_of_output_ports outputs = [] for i in range(n): outputs.append(self.reader.get_output(i)) self.outputs = outputs # FIXME: Only the first output goes through the assign # attribute filter. aa = self._assign_attribute self.configure_input_data(aa, outputs[0]) outputs[0] = aa.output self.update_data() self.outputs = outputs # FIXME: The output info is only based on the first output. self.output_info.datasets = [get_tvtk_dataset_name(outputs[0])] # Change our name on the tree view self.name = self._get_name()
def _data_changed(self, old, new): if has_attributes(self.data): aa = self._assign_attribute self.configure_input_data(aa, new) self._update_data() aa.update() 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 # 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 _file_path_changed(self, fpath): value = fpath.get() if len(value) == 0: self.name = 'No VTK file' return else: self.reader.file_name = value self.update() # Setup the outputs by resetting self.outputs. Changing # the outputs automatically fires a pipeline_changed # event. try: n = self.reader.number_of_outputs except AttributeError: # for VTK >= 4.5 n = self.reader.number_of_output_ports outputs = [] for i in range(n): outputs.append(self.reader.get_output(i)) self.outputs = outputs # FIXME: Only the first output goes through the assign # attribute filter. aa = self._assign_attribute aa.input = outputs[0] outputs[0] = aa.output self.update_data() self.outputs = outputs # FIXME: The output info is only based on the first output. self.output_info.datasets = [get_tvtk_dataset_name(outputs[0])] # Change our name on the tree view self.name = self._get_name()
def _data_changed(self, old, new): """When the vtk dataset changes, adjust the pipeline accordingly so that we sync against the new dataset""" if has_attributes(self.data): aa = self._assign_attribute self.configure_input_data(aa, new) self._update_vtk_dataset_content() aa.update() self.outputs = [aa.output] else: self.outputs = [self.data] # Notify the pipeline to refresh against the new 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 # 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)
def _set_outputs(self, new_outputs): """Set `self.outputs` to the given list of `new_outputs`. You should always use this method to set `self.outputs`. """ old_outputs = self.outputs self.outputs = new_outputs if len(new_outputs) > 0: self.output_info.datasets = \ [get_tvtk_dataset_name(new_outputs[0])] if old_outputs == self.outputs: # Even if the outputs don't change we want to propagate a # data_changed event since the data could have changed. self.data_changed = True
def test_tvtk_dataset_name(self): "Can tvtk datasets can be converted to names correctly." datasets = [ tvtk.ImageData(), tvtk.StructuredPoints(), tvtk.RectilinearGrid(), tvtk.StructuredGrid(), tvtk.PolyData(), tvtk.UnstructuredGrid(), tvtk.Property(), # Not a dataset! 'foo', # Not a TVTK object. ] expect = [ 'image_data', 'image_data', 'rectilinear_grid', 'structured_grid', 'poly_data', 'unstructured_grid', 'none', 'none' ] result = [pipeline_info.get_tvtk_dataset_name(d) for d in datasets] self.assertEqual(result, expect)
def test_tvtk_dataset_name(self): "Can tvtk datasets can be converted to names correctly." datasets = [tvtk.ImageData(), tvtk.StructuredPoints(), tvtk.RectilinearGrid(), tvtk.StructuredGrid(), tvtk.PolyData(), tvtk.UnstructuredGrid(), tvtk.Property(), # Not a dataset! 'foo', # Not a TVTK object. ] expect = ['image_data', 'image_data', 'rectilinear_grid', 'structured_grid', 'poly_data', 'unstructured_grid', 'none', 'none' ] result = [pipeline_info.get_tvtk_dataset_name(d) for d in datasets] self.assertEqual(result, expect)
def _file_path_changed(self, fpath): value = fpath.get() if len(value) == 0: return else: if self.reader is None: d_type = find_file_data_type(fpath.get()) self.reader = eval('tvtk.XML%sReader()' % d_type) reader = self.reader reader.file_name = value reader.update() aa = self._assign_attribute self.configure_input(aa, self.reader) self.update_data() aa.update() outputs = [aa] self.outputs = outputs self.output_info.datasets = [get_tvtk_dataset_name(outputs[0])] # Change our name on the tree view self.name = self._get_name()
def _file_path_changed(self, fpath): value = fpath.get() if len(value) == 0: self.name = 'No VTK file' return else: self.reader.file_name = value self.update() # Setup the outputs by resetting self.outputs. Changing # the outputs automatically fires a pipeline_changed # event. try: n = self.reader.number_of_outputs except AttributeError: # for VTK >= 4.5 n = self.reader.number_of_output_ports if n > 0: outputs = [] for i in range(n): outputs.append(self.reader.get_output(i)) # FIXME: currently handling only one output (the first one) # with assign attributes. if has_attributes(outputs[0]): aa = self._assign_attribute self.configure_input_data(aa, outputs[0]) self.update_data() aa.update() outputs[0] = aa.output self.outputs = outputs # FIXME: The output info is only based on the first output. self.output_info.datasets = [get_tvtk_dataset_name(outputs[0])] # Change our name on the tree view self.name = self._get_name()
def _file_path_changed(self, fpath): value = fpath.get() if len(value) == 0: return else: if self.reader is None: d_type = find_file_data_type(fpath.get()) self.reader = eval('tvtk.XML%sReader()'%d_type) reader = self.reader reader.file_name = value reader.update() # Setup the outputs by resetting self.outputs. Changing # the outputs automatically fires a pipeline_changed # event. try: n = reader.number_of_outputs except AttributeError: # for VTK >= 4.5 n = reader.number_of_output_ports outputs = [] for i in range(n): outputs.append(reader.get_output(i)) # FIXME: Only the first output goes through the assign # attribute filter. aa = self._assign_attribute self.configure_input_data(aa, outputs[0]) outputs[0] = aa.output self.update_data() self.outputs = outputs # FIXME: The output info is only based on the first output. self.output_info.datasets = [get_tvtk_dataset_name(outputs[0])] # Change our name on the tree view self.name = self._get_name()
def _file_path_changed(self, fpath): value = fpath.get() if len(value) == 0: return else: if self.reader is None: d_type = find_file_data_type(fpath.get()) self.reader = eval('tvtk.XML%sReader()' % d_type) reader = self.reader reader.file_name = value reader.update() # Setup the outputs by resetting self.outputs. Changing # the outputs automatically fires a pipeline_changed # event. try: n = reader.number_of_outputs except AttributeError: # for VTK >= 4.5 n = reader.number_of_output_ports outputs = [] for i in range(n): outputs.append(reader.get_output(i)) # FIXME: Only the first output goes through the assign # attribute filter. aa = self._assign_attribute aa.input = outputs[0] outputs[0] = aa.output self.update_data() self.outputs = outputs # FIXME: The output info is only based on the first output. self.output_info.datasets = [get_tvtk_dataset_name(outputs[0])] # Change our name on the tree view self.name = self._get_name()
def _file_path_changed(self, fpath): value = fpath.get() if len(value) == 0: self.name = 'No VTK file' return else: self.reader.file_name = value self.update() outputs = [] if has_attributes(self.reader.output): aa = self._assign_attribute self.configure_input(aa, self.reader) self.update_data() aa.update() outputs = [aa] else: outputs = [self.reader] self.outputs = outputs self.output_info.datasets = [get_tvtk_dataset_name(outputs[0])] # Change our name on the tree view self.name = self._get_name()