[vtkusers] VTK with Python and wxWidgets

Brian Wainscott brian at lstc.com
Fri Jan 14 20:10:03 EST 2005


I posted this question to the wxPython lists, and they suggested I ask 
you, so if anyone here can point me to information it would be greatly 
appreciated.

When I import vtkpython in my working wxPython code, strange things 
happen....

Details about my system/setup:

I'm running on a Linux Suse 9.0 system with these wx rpms installed:

python-wxGTK-doc-2.4.2.4-85
python-wxGTK-2.4.2.4-138
wxGTK-2.4.2.4-138
wxGTK-gl-2.4.2.4-138
python-wxGTK-examples-2.4.2.4-85

I know newer versions of wx are out, but these are what was already on 
my system.  I can uninstall them and upgrade from source if there is 
reason to believe that will fix anything.

I'm using vtk 4.4.

Problem: importing vtkpython in my wxPython app causes all the wxWidgets 
to act wrong.  My buttons and slider loose all their graphic elements 
(except their text strings), and I get a lot of runtime errors like this:

(test.py:28388): GdkPixbuf-CRITICAL **: file gdk-pixbuf.c: line 357 
(gdk_pixbuf_get_pixels): assertion `pixbuf != NULL' failed

If I comment out the line "import vtkpython" then it runs fine!  Here is 
my sample app for this problem:

#!/usr/bin/python
from wxPython.wx import *
#
# This app runs fine as it is, but if I uncomment either of the
# following two lines then the button and slider decorations disappear
# (EVERYTHING except the text labels), and I get a lot of errors like
# (test.py:28388): GdkPixbuf-CRITICAL **: file gdk-pixbuf.c: line 357
#  (gdk_pixbuf_get_pixels): assertion `pixbuf != NULL' failed
#
#
# from vtkpython import *
# import vtkpython


#---------------------------------------------------------------------------


class Test(wxPanel):
     def __init__(self, parent, nbut):
         wxPanel.__init__(self, parent, -1)

         self.SetAutoLayout(True)
#
# Create buttons down top left side
#
         self.bbox=wxBoxSizer(wxVERTICAL)
         self.b = range(nbut)
         for i in range(nbut):
           self.b[i] = wxToggleButton(self, i+10, ' Item %d ' % i)
           EVT_TOGGLEBUTTON(self, self.b[i].GetId(), self.OnButton)
         for i in range(nbut):
           self.bbox.Add(self.b[i],1,wxEXPAND)
#
# Create slider along bottom
#
         self.s = wxSlider(self, 20,1,1,100,wxPyDefaultPosition,
                  wxPyDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS)
         EVT_SCROLL(self.s, self.OnScroll)
#
# Create a drawing window -- eventually vtk should live in this window
#
         self.panel = wxWindow(self, -1, wxPyDefaultPosition,
          wxPyDefaultSize,wxSIMPLE_BORDER)
#
# Pack them all together
#
         self.vbox=wxBoxSizer(wxVERTICAL)
         self.hbox=wxBoxSizer(wxHORIZONTAL)
         self.hbox.Add(self.bbox,0,wxEXPAND)
         self.hbox.Add(self.panel,1,wxEXPAND)
         self.vbox.Add(self.hbox,1,wxEXPAND)
         self.vbox.Add(self.s,0,wxEXPAND)
         self.vbox.Fit(self)
         self.SetSizer(self.vbox)

     def OnButton(self, event):
         id = event.GetId()
         but=self.b[id-self.b[0].GetId()]
         print "Toggle button %d = %d" % (id,but.GetValue())
         wxBell()
     def OnScroll(self, event):
         print "Scroll position = %d" % (self.s.GetValue())

app = wxPySimpleApp()
frame = wxFrame(None,-1,"wxRenderWindow",size=wxSize(400,400))
Test(frame,5)
frame.Show(1)
app.MainLoop()



So any suggestions, places to look, WORKING wxPython/VTK examples, etc 
would be greatly appreciated.

-- 
Brian Wainscott |  "That man is no fool who gives what he cannot keep
brian at lstc.com  |   to gain what he cannot lose."  -- Jim Elliot



More information about the vtkusers mailing list