Commit 2c2504b1 authored by Timothy M. Shead's avatar Timothy M. Shead
Browse files

ENH: Add a simple PyQt Tython example

parent ac39b3a8
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import uic
from vtk import *
import sys
application = QtGui.QApplication(sys.argv)
window = uic.loadUi("gui.ui")
vertex_slider = window.findChild(QtGui.QSlider, "vertexCount")
edge_slider = window.findChild(QtGui.QSlider, "edgeCount")
source = vtkRandomGraphSource()
source.SetNumberOfVertices(vertex_slider.value())
source.SetNumberOfEdges(edge_slider.value())
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()
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()
# Setup a VTK window, but don't start an event-loop ...
view = vtkGraphLayoutView()
view.AddRepresentationFromInputConnection(source.GetOutputPort())
render_window = vtkRenderWindow()
render_window.SetSize(600, 600)
view.SetupRenderWindow(render_window)
render_window.Start()
# Start the Qt event-loop ...
application.exec_()
<ui version="4.0" >
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>382</width>
<height>156</height>
</rect>
</property>
<property name="windowTitle" >
<string>Titan / Python GUI Example</string>
</property>
<widget class="QWidget" name="centralwidget" >
<layout class="QGridLayout" >
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Vertex Count</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QSlider" name="vertexCount" >
<property name="minimum" >
<number>1</number>
</property>
<property name="maximum" >
<number>200</number>
</property>
<property name="value" >
<number>10</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Edge Count</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QSlider" name="edgeCount" >
<property name="maximum" >
<number>1000</number>
</property>
<property name="value" >
<number>50</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>382</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar" />
</widget>
<resources/>
<connections/>
</ui>
Supports Markdown
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