Skip to content

Instantly share code, notes, and snippets.

@samueljohn
Forked from fmorency/gist:2596951
Created July 11, 2012 12:35
Show Gist options
  • Select an option

  • Save samueljohn/3090097 to your computer and use it in GitHub Desktop.

Select an option

Save samueljohn/3090097 to your computer and use it in GitHub Desktop.

Revisions

  1. samueljohn revised this gist Jul 11, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions vtk-qt-demo.py
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,10 @@
    """

    try:
    from PyQt4 import QtCore, QtGui
    from PySide import QtCore, QtGui
    except ImportError:
    try:
    from PySide import QtCore, QtGui
    from PyQt4 import QtCore, QtGui
    except ImportError as err:
    raise ImportError("Cannot load either PyQt or PySide")

    @@ -43,4 +43,4 @@
    widget.show()

    # start event processing
    sys.exit(app.exec_())
    sys.exit(app.exec_())
  2. samueljohn revised this gist Jul 11, 2012. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions vtk-qt-demo.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    """
    A simple example that uses the QVTKRenderWindowInteractor
    class.
    """

    try:
  3. samueljohn renamed this gist Jul 11, 2012. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions gistfile1.py → vtk-qt-demo.py
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,17 @@
    """
    A simple example that uses the QVTKRenderWindowInteractor
    class.
    """

    #from PySide import QtGui
    from PyQt4 import QtGui
    from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
    import vtk
    import sys
    try:
    from PyQt4 import QtCore, QtGui
    except ImportError:
    try:
    from PySide import QtCore, QtGui
    except ImportError as err:
    raise ImportError("Cannot load either PyQt or PySide")

    if __name__ == '__main__':
    # every QT app needs an app
  4. @fmorency fmorency revised this gist May 4, 2012. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -9,11 +9,6 @@
    import vtk
    import sys

    def output_picked_point(caller, id, data=None):
    picker = caller.GetPicker()

    print 'Point id: %s' % picker.GetPointId()

    if __name__ == '__main__':
    # every QT app needs an app
    app = QtGui.QApplication(['QVTKRenderWindowInteractor'])
    @@ -25,7 +20,6 @@ def output_picked_point(caller, id, data=None):

    # if you dont want the 'q' key to exit comment this.
    widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())
    widget.AddObserver("EndPickEvent", output_picked_point)

    ren = vtk.vtkRenderer()
    widget.GetRenderWindow().AddRenderer(ren)
  5. @fmorency fmorency created this gist May 4, 2012.
    50 changes: 50 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    """
    A simple example that uses the QVTKRenderWindowInteractor
    class.
    """

    #from PySide import QtGui
    from PyQt4 import QtGui
    from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
    import vtk
    import sys

    def output_picked_point(caller, id, data=None):
    picker = caller.GetPicker()

    print 'Point id: %s' % picker.GetPointId()

    if __name__ == '__main__':
    # every QT app needs an app
    app = QtGui.QApplication(['QVTKRenderWindowInteractor'])

    # create the widget
    widget = QVTKRenderWindowInteractor()
    widget.Initialize()
    widget.Start()

    # if you dont want the 'q' key to exit comment this.
    widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())
    widget.AddObserver("EndPickEvent", output_picked_point)

    ren = vtk.vtkRenderer()
    widget.GetRenderWindow().AddRenderer(ren)

    cone = vtk.vtkConeSource()
    cone.SetResolution(8)

    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInputConnection(cone.GetOutputPort())

    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    ren.AddActor(coneActor)

    widget.SetPicker(vtk.vtkPointPicker())

    # show the widget
    widget.show()

    # start event processing
    sys.exit(app.exec_())