gui.py 1.57 KB
Newer Older
1
2
3
4
5
6
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import uic
from vtk import *
import sys

7
# Create a PyQt window using a .ui file generated with Qt Designer ...
8
9
10
11
12
13
application = QtGui.QApplication(sys.argv)

window = uic.loadUi("gui.ui")
vertex_slider = window.findChild(QtGui.QSlider, "vertexCount")
edge_slider = window.findChild(QtGui.QSlider, "edgeCount")

14
# Create a simple pipeline source ...
15
16
17
18
source = vtkRandomGraphSource()
source.SetNumberOfVertices(vertex_slider.value())
source.SetNumberOfEdges(edge_slider.value())

19
# Define event-handlers that update the pipeline in response to widget events ...
20
21
22
23
24
25
26
27
28
29
30
31
def change_vertex_count(count):
  source.SetNumberOfVertices(count)
  edge_slider.setValue(source.GetNumberOfEdges())
  view.GetRenderer().ResetCamera()
  render_window.Render()

def change_edge_count(count):
  source.SetNumberOfEdges(count)
  edge_slider.setValue(source.GetNumberOfEdges())
  view.GetRenderer().ResetCamera()
  render_window.Render()

32
# Connect the GUI widgets to the event-handlers ...
33
34
35
36
QtCore.QObject.connect(vertex_slider, QtCore.SIGNAL("valueChanged(int)"), change_vertex_count)
QtCore.QObject.connect(edge_slider, QtCore.SIGNAL("valueChanged(int)"), change_edge_count)
window.show()

37
# Setup a VTK view ...
38
39
40
41
42
43
view = vtkGraphLayoutView()
view.AddRepresentationFromInputConnection(source.GetOutputPort())

render_window = vtkRenderWindow()
render_window.SetSize(600, 600)
view.SetupRenderWindow(render_window)
44
45

# This initializes the VTK window for interaction, but doesn't start an event-loop ...
46
47
48
49
50
render_window.Start()

# Start the Qt event-loop ...
application.exec_()