Created
July 20, 2016 14:40
-
-
Save rexissimus/009b303e4cadcd4b8f2fec6cf848cb2b to your computer and use it in GitHub Desktop.
New patch example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patches = { | |
'UpdateAlgorithm': | |
""" | |
is_aborted = [False] | |
if hasattr($self, '_callback') and $self._callback is not None: | |
cbId = None | |
def ProgressEvent(obj, event): | |
try: | |
$self._callback(obj.GetProgress()) | |
except Exception, e: | |
if e.__name__ == 'AbortExecution': | |
obj.SetAbortExecute(True) | |
$self.RemoveObserver(cbId) | |
is_aborted[0] = True | |
else: | |
raise | |
cbId = $self.AddObserver('ProgressEvent', ProgressEvent) | |
$original | |
if $self._callback is not None and not is_aborted[0]: | |
$self.RemoveObserver(cbId) | |
""", | |
'guarded_SimpleScalarTree': | |
""" | |
$original | |
# This builds the scalar tree | |
$self.BuildTree() | |
""", | |
'guarded_Writer': | |
""" | |
# The behavior for vtkWriter subclasses is to call Write() | |
# If the user sets a name, we will create a file with that name | |
# If not, we will create a temporary file using _tempfile | |
$output = $self.GetFileName() | |
if not $output: | |
$output = $self._tempfile(suffix='.vtk') | |
$self.SetFileName(fn) | |
$self.Write() | |
""", | |
'guarded_SetFileName': # fixme add imports somewhere | |
""" | |
# This checks for the presence of file in VTK readers | |
# Skips the check if it's a vtkImageReader or vtkPLOT3DReader, because | |
# it has other ways of specifying files, like SetFilePrefix for | |
# multiple files | |
import vtk | |
import os | |
skip = [vtk.vtkBYUReader, | |
vtk.vtkImageReader, | |
vtk.vtkDICOMImageReader, | |
vtk.vtkTIFFReader] | |
# vtkPLOT3DReader does not exist from version 6.0.0 | |
if not any(issubclass(type($self), x) for x in skip): | |
filename = $self.GetFileName() | |
if not os.path.isfile(filename): | |
raise Exception('File does not exist') | |
$original | |
""", | |
'SetRenderWindow': | |
""" | |
import vtk | |
window = vtk.vtkRenderWindow() | |
w = 512 | |
h = 512 | |
window.OffScreenRenderingOn() | |
window.SetSize(w, h) | |
window.AddRenderer($input) | |
window.Render() | |
$self.SetRenderWindow(window) | |
""", | |
'TransferFunction': | |
""" | |
$input.set_on_vtk_volume_property($self) | |
""", | |
'PointData': | |
""" | |
$self.GetPointData().ShallowCopy($input) | |
""", | |
'CellData': | |
""" | |
$self.GetCellData().ShallowCopy($input) | |
""", | |
'PointIds': | |
""" | |
$self.GetPointIds().SetNumberOfIds($input.GetNumberOfIds()) | |
for i in xrange($input.GetNumberOfIds()): | |
$self.GetPointIds().SetId(i, $input.GetId(i)) | |
""", | |
'CopyImportVoidPointer': | |
""" | |
$self.CopyImportVoidPointer($input, len($input)) | |
""", | |
'GetFirstBlock': | |
""" | |
$output = $self.GetOutput().GetBlock(0) | |
""", | |
# Set magic tempfile | |
'_set_tempfile': | |
""" | |
$self._tempfile = $input | |
""", | |
# Set magic callback | |
'_set_callback': | |
""" | |
$self._callback = $input | |
""", | |
# Set initialize | |
'_initialize': | |
""" | |
import locale | |
$self._previous_locale = locale.setlocale(locale.LC_ALL) | |
locale.setlocale(locale.LC_ALL, 'C') | |
""", | |
# Set cleanup | |
'_cleanup': | |
""" | |
import locale | |
locale.setlocale(locale.LC_ALL, $self._previous_locale) | |
""", | |
'SetLookupTable': # from fix_classes | |
""" | |
$self.UserControlledLookupTableOn() | |
$original | |
""", | |
#basic:Color translation | |
'basic:Color#input': | |
""" | |
$output = $input.tuple | |
""", | |
'basic:Color#output': | |
""" | |
from vistrails.core.utils import InstanceObject | |
$output = InstanceObject(tuple=$input) | |
""", | |
#basic:File translation | |
'basic:File#input': | |
""" | |
$output = $input.name | |
""", | |
'basic:File#output': | |
""" | |
vistrails.core.modules.basic_modules import PathObject | |
$output = PathObject($input) | |
""", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment