[vtkusers] Python observer handling
Willi Huber
surfersparadise85-vtk at yahoo.com
Wed Jan 9 11:20:10 EST 2013
Hello all,
I know exception handling in VTK has been discussed quite a while so I don't want to add insult to an injury.
Since David Gobbi very often posted his code:
==== python code ====
import vtk class ErrorObserver: def __init__(self):
self.__ErrorOccurred = False
self.__ErrorMessage = None
self.CallDataType = 'string0' def __call__(self, obj, event, message):
self.__ErrorOccurred = True
self.__ErrorMessage = message def ErrorOccurred(self):
occ = self.__ErrorOccurred
self.__ErrorOccurred = False
return occ def ErrorMessage(self):
return self.__ErrorMessage e = ErrorObserver() a = vtk.vtkImageReader()
a.AddObserver('ErrorEvent', e) print "doing update"
a.Update()
if e.ErrorOccurred():
print e.ErrorMessage()
==== python code ====
Unfortunately it is not working as intended. I tried this code which obviously had to fail:
==== python code ====
mapper = vtk.vtkPolyDataMapper()
mapper.AddObserver('ErrorEvent', e)
mapper.SetInputConnection(reader.GetOutputPort()) #reader is of type vtkMetaImageReader
mapper.Update()
if e.ErrorOccurred():
print e.ErrorMessage()
else:
print "No Error"
==== python code ====
but it didn't. Now I know about this error but I am still curious why it was not working as intended.
Shouldn't it print the cause of the error rather than "No Error"?
Everytime I tried this code a vtk warning window poped up which can't be read since the whole application dies with some Windows failure handling. Therefore I was not able to read the error message in the window and had a tough time finding out about the problem. Uncommenting renWin.Render() let me read the error.
Any suggestions what I am doing wrong?
Cheers,
Willi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130109/aa5eac41/attachment.htm>
More information about the vtkusers
mailing list