[vtkusers] Question about the shape-shifting __getattr__ magic of QVTKRenderWindowInteractor
elvis.stansvik at orexplore.com
Wed Jun 15 07:55:52 EDT 2016
I'm trying to create our own customized and simplified
QVTKRenderWindowInteractor, since there are features in it that we don't
need (stereo stuff, PySide/PyQt4/QWidget compat, ...), I came across the
magic it does in its __getattr__ in order to behave like a
def __getattr__(self, attr):
"""Makes the object behave like a
if attr == '__vtk__':
return lambda t=self._Iren: t
elif hasattr(self._Iren, attr):
return getattr(self._Iren, attr)
raise AttributeError(self.__class__.__name__ +
" has no attribute named " + attr)
Forgive my ignorance, but is this behavior something that is essential to
keep? Or was this added just as a convenience, so that instances of the
class can be passed to VTK methods that expect an interactor?
In short, I'd like to know if I can remove this whole thing, and if so,
what the consequences would be.
If it's just a convenience, I think we'd want to remove it. I think we want
to encapsulate as much as possible of the VTK workings inside the widget as
possible, and only make the interactor / render window used inside it
available through getters (or attributes).
My goal is to have something that feels more like a Qt API for this class..
But since I'm new to VTK, and still haven't quite figured out how the class
is to be used in certain situations (see my post about using it with
context views for instance), I'd appreciate some guidance.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the vtkusers