Commit 83c4d7cc authored by Ken Martin's avatar Ken Martin
Browse files

Prabhus python changes

parent 78344e80
......@@ -5,10 +5,6 @@ setup.py for installing the VTK-Python bindings using distutils.
Created by Prabhu Ramachandran, June 2002.
TODO:
1. Test under different OS's.
"""
import glob, sys, os
......@@ -16,6 +12,7 @@ from types import StringType
from distutils.core import setup
from distutils.util import change_root, convert_path
from distutils.command.install_data import install_data
from distutils.sysconfig import get_config_var
version = "${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION}"
......@@ -32,8 +29,8 @@ def get_libs():
"""Returns a list of libraries to be installed. """
libs = []
if os.name == 'posix':
libs = glob.glob(os.path.abspath(os.path.join(install_lib_dir,
'libvtk*Python*.so')))
libs = glob.glob(os.path.abspath(os.path.join(
install_lib_dir, 'libvtk*Python*' + get_config_var('SO'))))
else:
d = os.path.normpath(build_lib_dir)
if not os.path.isfile(os.path.join(d, 'vtkCommonPython.dll')):
......@@ -61,7 +58,7 @@ def get_scripts():
if os.path.exists(win32_bin_dir):
break
for i in ('vtkpython.exe', 'pvtkpython.exe'):
f = os.path.join(win32_bin_dir, i)
f = os.path.join(os.path.normpath(win32_bin_dir), i)
if os.path.exists(f):
scripts.append(f)
return scripts
......
......@@ -267,7 +267,7 @@ def main():
gvtk.Initialize()
gvtk.Start()
# prevents 'q' from exiting the app.
gvtk.SetExitMethod(lambda x=None: x)
gvtk.AddObserver("ExitEvent", lambda o,e,x=None: x)
# The VTK stuff.
cone = vtk.vtkConeSource()
......
"""
A simple VTK input file for PyQt, the qt bindings for python.
See http://www.trolltech.com for qt documentation, and
http://www.thekompany.com for the qt python bindings.
http://www.river-bank.demon.co.uk or http://www.thekompany.com
for the qt python bindings.
Created by David Gobbi, December 2001
Based on vtkTkRenderWindget.py
Changes by Gerard Vermeulen Feb. 2003
Win32 support
"""
"""
This class works only with the UNIX version of Qt.
It does not work under the Win32 version of Qt.
This class should work with both the UNIX version of Qt and also on
Win32.
Depending on the OpenGL graphics drivers, it may not
be possible to have more than one QVTKRenderWidget
......@@ -21,6 +25,10 @@ C++ and then wrapped to be made available through python,
similar to the vtkTkRenderWidget.
"""
# Problems on Win32:
# 1. The widget is not cleaned up properly and crashes the
# application.
import math, os, sys
from qt import *
......@@ -106,16 +114,20 @@ class QVTKRenderWidget(QWidget):
if self.__connected == 0:
size = self.size()
self._RenderWindow.SetSize(size.width(),size.height())
self._RenderWindow.SetWindowInfo(str(self.winId()))
self._RenderWindow.SetWindowInfo(str(int(self.winId())))
self.__connected = 1
def show(self):
QWidget.show(self)
self.repaint() # needed for initial contents display on Win32
def paintEvent(self,ev):
if self.isVisible():
if self.__connected == 0:
size = self.size()
self._RenderWindow.SetSize(size.width(),size.height())
self._RenderWindow.SetWindowInfo(str(self.winId()))
self._RenderWindow.SetWindowInfo(str(int(self.winId())))
self.__connected = 1
if self.__connected:
self.Render()
......
"""
A simple VTK input file for PyQt, the qt bindings for python.
See http://www.trolltech.com for qt documentation, and
http://www.thekompany.com for the qt python bindings.
http://www.river-bank.demon.co.uk or http://www.thekompany.com
for the qt python bindings.
This class is based on the vtkGenericRenderWindowInteractor and is
therefore fairly powerful. It should also play nicely with the
......@@ -9,11 +10,14 @@ vtk3DWidget code.
Created by Prabhu Ramachandran, May 2002
Based on David Gobbi's QVTKRenderWidget.py
Changes by Gerard Vermeulen Feb. 2003
Win32 support
"""
"""
This class works only with the UNIX version of Qt.
It does not work under the Win32 version of Qt.
This class works with the UNIX and Win32 versions of Qt.
Depending on the OpenGL graphics drivers, it may not
be possible to have more than one QVTKRenderWidget
......@@ -22,6 +26,11 @@ per application.
In short, this class is experimental.
"""
# To do for Win32:
# 1. More testing to assure that the widget is always cleaned up
# properly and does not crash the application.
import math, os, sys
import qt
import vtk
......@@ -32,6 +41,53 @@ class QVTKRenderWindowInteractor(qt.QWidget):
vtkGenericRenderWindowInteractor to handle the interactions. Use
GetRenderWindow() to get the vtkRenderWindow. Create with the
keyword stereo=1 in order to generate a stereo-capable window.
The user interface is summarized in vtkInteractorStyle.h:
- Keypress j / Keypress t: toggle between joystick (position
sensitive) and trackball (motion sensitive) styles. In joystick
style, motion occurs continuously as long as a mouse button is
pressed. In trackball style, motion occurs when the mouse button
is pressed and the mouse pointer moves.
- Keypress c / Keypress o: toggle between camera and object
(actor) modes. In camera mode, mouse events affect the camera
position and focal point. In object mode, mouse events affect
the actor that is under the mouse pointer.
- Button 1: rotate the camera around its focal point (if camera
mode) or rotate the actor around its origin (if actor mode). The
rotation is in the direction defined from the center of the
renderer's viewport towards the mouse position. In joystick mode,
the magnitude of the rotation is determined by the distance the
mouse is from the center of the render window.
- Button 2: pan the camera (if camera mode) or translate the actor
(if object mode). In joystick mode, the direction of pan or
translation is from the center of the viewport towards the mouse
position. In trackball mode, the direction of motion is the
direction the mouse moves. (Note: with 2-button mice, pan is
defined as <Shift>-Button 1.)
- Button 3: zoom the camera (if camera mode) or scale the actor
(if object mode). Zoom in/increase scale if the mouse position is
in the top half of the viewport; zoom out/decrease scale if the
mouse position is in the bottom half. In joystick mode, the amount
of zoom is controlled by the distance of the mouse pointer from
the horizontal centerline of the window.
- Keypress 3: toggle the render window into and out of stereo mode.
By default, red-blue stereo pairs are created. Some systems support
Crystal Eyes LCD stereo glasses; you have to invoke
SetStereoTypeToCrystalEyes() on the rendering window.
- Keypress e: exit the application.
- Keypress f: fly to the picked point
- Keypress p: perform a pick operation. The render window interactor
has an internal instance of vtkCellPicker that it uses to pick.
- Keypress r: reset the camera view along the current view
direction. Centers the actors and moves the camera so that all actors
are visible.
- Keypress s: modify the representation of all actors so that they
are surfaces.
- Keypress u: invoke the user-defined function. Typically, this
keypress will bring up an interactor that you can type commands in.
- Keypress w: modify the representation of all actors so that they
are wireframe.
"""
def __init__(self, parent=None, name=None, *args, **kw):
......@@ -88,7 +144,7 @@ class QVTKRenderWindowInteractor(qt.QWidget):
if self.__connected == 0:
size = self.size()
self._RenderWindow.SetSize(size.width(),size.height())
self._RenderWindow.SetWindowInfo(str(self.winId()))
self._RenderWindow.SetWindowInfo(str(int(self.winId())))
self.__connected = 1
self._Timer = qt.QTimer(self, 'timer handler')
......@@ -121,12 +177,16 @@ class QVTKRenderWindowInteractor(qt.QWidget):
def TimerEvent(self):
self._Iren.TimerEvent()
def show(self):
qt.QWidget.show(self)
self.repaint() # needed for initial contents display on Win32
def paintEvent(self,ev):
if self.isVisible():
if self.__connected == 0:
size = self.size()
self._Iren.SetSize(size.width(),size.height())
self._RenderWindow.SetWindowInfo(str(self.winId()))
self._RenderWindow.SetWindowInfo(str(int(self.winId())))
self._Iren.ConfigureEvent()
self.__connected = 1
if self.__connected:
......@@ -248,7 +308,7 @@ def QVTKRenderWidgetConeExample():
widget.Initialize()
widget.Start()
# if you dont want the 'q' key to exit comment this.
widget.SetExitMethod(app.quit)
widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())
ren = vtk.vtkRenderer()
widget.GetRenderWindow().AddRenderer(ren)
......@@ -266,6 +326,8 @@ def QVTKRenderWidgetConeExample():
# show the widget
widget.show()
# to make the widget display its contents on Win32
widget.resize(widget.size())
# close the application when window is closed
app.setMainWidget(widget)
# start event processing
......
......@@ -69,10 +69,11 @@ class vtkTkImageViewerWidget(Tkinter.Widget):
# stuff for window level text.
mapper = vtkTextMapper()
mapper.SetInput("none")
mapper.SetFontFamilyToTimes()
mapper.SetFontSize(18)
mapper.BoldOn()
mapper.ShadowOn()
t_prop = mapper.GetTextProperty()
t_prop.SetFontFamilyToTimes()
t_prop.SetFontSize(18)
t_prop.BoldOn()
t_prop.ShadowOn()
self._LevelMapper = mapper
......@@ -88,10 +89,11 @@ class vtkTkImageViewerWidget(Tkinter.Widget):
mapper = vtkTextMapper()
mapper.SetInput("none")
mapper.SetFontFamilyToTimes()
mapper.SetFontSize(18)
mapper.BoldOn()
mapper.ShadowOn()
t_prop = mapper.GetTextProperty()
t_prop.SetFontFamilyToTimes()
t_prop.SetFontSize(18)
t_prop.BoldOn()
t_prop.ShadowOn()
self._WindowMapper = mapper
......
......@@ -282,7 +282,7 @@ def vtkRenderWindowInteractorConeExample():
def quit(obj=root):
obj.quit()
pane.SetExitMethod(quit)
pane.AddObserver("ExitEvent", lambda o,e,q=quit: q())
ren = vtk.vtkRenderer()
pane.GetRenderWindow().AddRenderer(ren)
......
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