Skip to content

Instantly share code, notes, and snippets.

@dgobbi
Created May 7, 2016 20:43
Show Gist options
  • Save dgobbi/285270a0bd3125e9b251e28af58140f5 to your computer and use it in GitHub Desktop.
Save dgobbi/285270a0bd3125e9b251e28af58140f5 to your computer and use it in GitHub Desktop.
"""
This is a simple class that can catch errors from VTK objects.
"""
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment