[vtkusers] events freeze X using vtk with wxPython

John Hunter jdhunter at ace.bsd.uchicago.edu
Fri Nov 16 14:53:59 EST 2001


I am using wxPython's vtk to make a vtk rendering window in my wx
application.  I have just started using vtk in the last couple of
days.  

Whenever I do something to the window that triggers an event (resize,
click, move), the application often freezes, and freezes X along with
it.

I wonder if this is because VTK's event handling and wx's event
handling are clashing.  Is there some guidance about how to integrate
the two?

I have had this problem both with the wxVTKRenderingWindow demo (makes
a cone) that ships with wxPython and some code I am working with based
on the Viewer.py example that comes with vtk3.2.

I have experienced the same problem with vtk3.2 and VTK 4.0.  I am
working with the CVS version of wxWindows/wxPython under RHL 7.1.

Any suggestions?

Thanks, 
John Hunter


Sample Code:

import os
from wxPython.wx import *
from vtkpython import vtkImageReader, vtkImageViewer
from wxPython.lib import vtk

VTK_DATA = os.environ['VTK_DATA']

class MyApp(wxApp):
     def OnInit(self):
         frame = MyFrame(None, -1, "John's VTK")
         frame.Show(true)
         self.SetTopWindow(frame)
         return true

class MyFrame(wxFrame):
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                         size=(450, 300),                  
                         style=wxDEFAULT_FRAME_STYLE|
                         wxNO_FULL_REPAINT_ON_RESIZE)
                          
        vtkwin = vtk.wxVTKRenderWindow(self, -1)
        
        # Image pipeline
        reader = vtkImageReader()
        reader.SetDataByteOrderToLittleEndian()
        reader.SetDataExtent(0,255,0,255,1,93)
        reader.SetFilePrefix(VTK_DATA + "/fullHead/headsq")
        reader.SetDataMask(0x7fff)

        viewer = vtkImageViewer()
        viewer.SetInput(reader.GetOutput())
        viewer.SetZSlice(14)
        viewer.SetColorWindow(2000)
        viewer.SetColorLevel(1000)
        viewer.SetPosition(50,50)

        ren = viewer.GetRenderer()
        vtkwin.GetRenderWindow().AddRenderer(ren)
        ren.AddActor(viewer.GetActor2D())

        EVT_LEFT_DOWN(self, self.pan)
    def pan(self, event):
        print 'You clicked'
    
app = MyApp(0)
app.MainLoop()







More information about the vtkusers mailing list