Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "_p_void" values in TVTK with VTK 6.x #370

Merged
merged 25 commits into from May 13, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
32dbd6e
added _allow_update_failure_ to tvtk_base
kitchoi Apr 29, 2016
7f5d4d4
make VTKMethodParser.get_method_signature a staticmethod
kitchoi Apr 29, 2016
d41a95f
refactored special cases for _gen_get_set_method and handled _p_void …
kitchoi Apr 29, 2016
6db2ddc
one syntax error for a special case for VTK 5.8
kitchoi Apr 29, 2016
1e4b819
Merge branch 'master' into fix/357-360-tvtk-with-undefined-traits
kitchoi Apr 29, 2016
7c8f967
absorb get_array_meta to get_trait_type and rename get_trait_type to …
kitchoi Apr 29, 2016
7a30bdd
remove debugging print
kitchoi Apr 29, 2016
f03798b
wrapper_gen refactoring
kitchoi May 2, 2016
a68b520
fix language in comment
kitchoi May 2, 2016
07c9f9d
added tests for two tvtk classes
kitchoi May 2, 2016
1ea5cce
this would register kernel to be a traits.Array
kitchoi May 2, 2016
559c567
clean up and add comments
kitchoi May 4, 2016
117b4d4
added more tests for tvtk
kitchoi May 4, 2016
10a3838
fix error message missing formatting input
kitchoi May 4, 2016
8f07d82
Merge branch 'master' into fix/357-360-tvtk-with-undefined-traits
kitchoi May 4, 2016
ad538ef
cols meant to be a min between 3 and length, not max
kitchoi May 4, 2016
52cae16
Merge branch 'master' into fix/357-360-tvtk-with-undefined-traits
kitchoi May 5, 2016
7088434
remove redundant test case
kitchoi May 5, 2016
b619f45
add docstring
kitchoi May 5, 2016
c95e5ab
the default value is not neccessary, nor does it matter
kitchoi May 5, 2016
f88c7c8
improved docstring for get_trait_def
kitchoi May 5, 2016
286e27c
make docstring message on 'Raises' consistent with the code, and impr…
kitchoi May 6, 2016
350c1f6
added comments to the test for spider_actor set_axis_label
kitchoi May 12, 2016
491f88e
make kwargs a dict
kitchoi May 12, 2016
c1e1f46
make traits.Bool have a default value too
kitchoi May 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 25 additions & 5 deletions tvtk/tvtk_base.py
Expand Up @@ -199,10 +199,11 @@ def info(self):

def vtk_color_trait(default, **metadata):
Range = traits.Range

if default[0] == -1.0:
# Occurs for the vtkTextProperty's color trait. Need to work
# around.
return traits.Trait(default, traits.Tuple(*default),
return traits.Trait(default,
traits.Tuple(Range(0.0, 1.0),
Range(0.0, 1.0),
Range(0.0, 1.0),
Expand All @@ -212,7 +213,8 @@ def vtk_color_trait(default, **metadata):
return traits.Trait(traits.Tuple(Range(0.0, 1.0, default[0]),
Range(0.0, 1.0, default[1]),
Range(0.0, 1.0, default[2])),
editor=RGBColorEditor, **metadata)
editor=RGBColorEditor,
**metadata)
else:
return traits.Trait(
traits.Tuple(
Expand Down Expand Up @@ -272,6 +274,11 @@ class TVTKBase(traits.HasStrictTraits):
# The wrapped VTK object.
_vtk_obj = traits.Trait(None, None, vtk.vtkObjectBase())

# Stores the names of the traits whose VTK Get methods may return
# invalid values (e.g. reference to a point) or uninitialised values
# We would try to update but allow it to failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"allow it to fail" :)

_allow_update_failure_ = traits.Tuple

# Stores the names of the traits that need to be updated.
_updateable_traits_ = traits.Tuple

Expand Down Expand Up @@ -471,15 +478,28 @@ def update_traits(self, obj=None, event=None):
vtk.vtkObject.GlobalWarningDisplayOff()

for name, getter in self._updateable_traits_:
if name == 'global_warning_display':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about this one ? what makes it special?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not originally my code, I just moved it out of the try block. So I don't know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Leave it as is. We can't know everything.

setattr(self, name, warn)
continue

try:
val = getattr(vtk_obj, getter)()
except (AttributeError, TypeError):
# Some vtk GetMethod accepts more than 1 arguments
# FIXME: If we really want to try harder, we could
# pass an empty array to the Get method, some Get
# method will populate the array as the return
# value (e.g. vtkImageConvolve.GetKernel3x3 and alike)
pass
else:
if name == 'global_warning_display':
setattr(self, name, warn)
else:
try:
setattr(self, name, val)
except traits.TraitError:
if name in self._allow_update_failure_:
pass
else:
raise

# Reset the warning state.
vtk.vtkObject.SetGlobalWarningDisplay(warn)
self._in_set = 0
Expand Down
10 changes: 5 additions & 5 deletions tvtk/vtk_parser.py
Expand Up @@ -69,13 +69,12 @@ class or instance.
object. Here is an example::

>>> import vtk
>>> p = VTKMethodParser()
>>> o = vtk.vtkProperty
>>> print p.get_method_signature(o.GetClassName)
>>> print VTKMethodParser.get_method_signature(o.GetClassName)
[(['string'], None)]
>>> print p.get_method_signature(o.GetColor)[0]
>>> print VTKMethodParser.get_method_signature(o.GetColor)[0]
([('float', 'float', 'float')], None)
>>> print p.get_method_signature(o.GetColor)[1]
>>> print VTKMethodParser.get_method_signature(o.GetColor)[1]
([None], (('float', 'float', 'float'),))

The `get_method_signature` is fairly efficient and obtaining the
Expand Down Expand Up @@ -295,7 +294,8 @@ def get_other_methods(self):
"""
return self.other_meths

def get_method_signature(self, method):
@staticmethod
def get_method_signature(method):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many occurrence of parser = VTKMethodParser(); parser.get_method_signature(...) in wrapper_gen and in tests (and possibly some other places I have not touched), could do with a separately cleanup PR in order to move this function out of the class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave it as is. not top priority. If you want, open a issue tagged refactoring.

"""Returns information on the Python method signature given
the VTK method.

Expand Down