Commit 6352f3e5 authored by David Gobbi's avatar David Gobbi
Browse files

Make the QVTKRenderWindowInteractor more widely compatible.

Fix compatibility issues with recent commit 5316dff1.  It used the new
"import as" syntax that isn't supported on python 2.5 and earlier.
It also used a new signal/slot mechanism that is only available in
PyQt 4.5 and later, even though the old signal/slot mechanism was
still being used elsewhere in the file (mixing old and new ways
of doing the same thing in a single file makes the code hard to read).

The test TestQVTKRenderWindowInteractor.py did not draw anything,
because it didn't connect the renderer to the render window, nor
did it initialize the interactor.  It also used two-space indentation
in some places and four-space indentation in others.

Change-Id: Ie41798554cce2d1ffe5705ec198d191d9e18cb08
parent 9afdba04
......@@ -8,7 +8,7 @@ try:
except ImportError:
try:
from PySide import QtCore, QtGui
except ImportError as err:
except ImportError:
raise ImportError("Cannot load either PyQt or PySide")
import vtk
......@@ -16,26 +16,28 @@ from vtk.qt4.QVTKRenderWindowInteractor import *
from vtk.test import Testing
class TestQVTKRenderWindowInteractor(Testing.vtkTest):
def testQVTKRenderWindowInteractor(self):
w2 = QVTKRenderWindowInteractor()
ren = vtk.vtkRenderer()
ren.SetBackground(0,0,0)
ren.SetBackground2(1,1,1)
ren.SetGradientBackground(1)
renwin = w2.GetRenderWindow()
cone = vtk.vtkConeSource()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cone.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren.AddViewProp(actor)
ren.ResetCamera()
w2.show()
if Testing.isInteractive():
QtGui.qApp.exec_()
def testQVTKRenderWindowInteractor(self):
w2 = QVTKRenderWindowInteractor()
w2.Initialize()
ren = vtk.vtkRenderer()
ren.SetBackground(0,0,0)
ren.SetBackground2(1,1,1)
ren.SetGradientBackground(1)
renwin = w2.GetRenderWindow()
renwin.AddRenderer(ren)
cone = vtk.vtkConeSource()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cone.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren.AddViewProp(actor)
ren.ResetCamera()
w2.show()
if Testing.isInteractive():
QtGui.qApp.exec_()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
......
......@@ -33,14 +33,10 @@ try:
except ImportError:
try:
from PySide import QtCore, QtGui
#PyQt4 signal/slot compatibility
QtCore.pyqtSignal = QtCore.Signal
QtCore.pyqtSlot = QtCore.Slot
except ImportError as err:
except ImportError:
raise ImportError("Cannot load either PyQt or PySide")
import vtk
import vtk
class QVTKRenderWindowInteractor(QtGui.QWidget):
......@@ -191,7 +187,7 @@ class QVTKRenderWindowInteractor(QtGui.QWidget):
#its parent thus allowing cleanup of VTK elements.
self._hidden = QtGui.QWidget(self)
self._hidden.hide()
self._hidden.destroyed.connect(self.Finalize)
self.connect(self._hidden, QtCore.SIGNAL('destroyed()'), self.Finalize)
def __getattr__(self, attr):
"""Makes the object behave like a vtkGenericRenderWindowInteractor"""
......@@ -203,7 +199,6 @@ class QVTKRenderWindowInteractor(QtGui.QWidget):
raise AttributeError, self.__class__.__name__ + \
" has no attribute named " + attr
@QtCore.pyqtSlot()
def Finalize(self):
'''
Call internal cleanup method on VTK objects
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment