[vtkusers] multiple vtk windows using wxPython.

Richard A Rowe rar109 at york.ac.uk
Thu Apr 5 14:33:49 EDT 2007


Dear vtk users,

I have recently moved on to using wxPython from Tkinter to create my GUI. 
I was not sure if it was possible to create more than one vtkRenderWindow
within a tk Window. Also I believe there are many more widgets availble
using wxPython. 

I've managed to get a simple application going displaying a menubar, status
bar and wx.Panel along with a vtk window complete with a rendered cone 
example in it. However, when I try to increase the number of 
wxVTKRenderWindows OR wxVTKRenderWindowInteractors I discover that
the second window does not render properly and that there is not interaction.

My efforts are posted below. Please could someone give me an clue as to 
where I'm going wrong? 

Any help would be much appreciated. 

Kind regards,

Richard Rowe.

import wx
import vtk
from vtk.wx.wxVTKRenderWindowInteractor import wxVTKRenderWindowInteractor

ID_ABOUT = 101
ID_EXIT = 110

class MainWindow(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY,title,size = (600,600),
        style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
       
        self.CreateStatusBar()
        #--------- Setting up the menu.
        filemenu = wx.Menu()
        filemenu.Append(ID_ABOUT, "&About", "Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(ID_EXIT, "E&xit", "Terminate program")
        #---------- Creating the menu.
        menubar = wx.MenuBar()
        menubar.Append(filemenu, "&File")
        self.SetMenuBar(menubar)
        #--------- Setting menu event handlers.
        wx.EVT_MENU(self, ID_ABOUT, self.OnAbout)
        wx.EVT_MENU(self, ID_EXIT, self.OnExit)
        
        panel = wx.Panel(self)
        #----------- VTK
        widget = wxVTKRenderWindowInteractor(panel, -1)
        widget2 = wxVTKRenderWindowInteractor(panel, -1)

        ren = vtk.vtkRenderer()
        renWin = widget.GetRenderWindow()
        renWin.AddRenderer(ren)
        
        ren2 = vtk.vtkRenderer()
        renWin2 = widget.GetRenderWindow()
        renWin2.AddRenderer(ren2)

        cone = vtk.vtkConeSource()
        cone.SetResolution(12)
        sphere = vtk.vtkSphereSource()

        coneMapper = vtk.vtkPolyDataMapper()
        coneMapper.SetInput(cone.GetOutput())
        
        sphereMapper = vtk.vtkPolyDataMapper()
        sphereMapper.SetInput(sphere.GetOutput())

        coneActor = vtk.vtkActor()
        coneActor.SetMapper(coneMapper)
        
        sphereActor = vtk.vtkActor()
        sphereActor.SetMapper(sphereMapper)

        ren.AddActor(coneActor)
        ren.ResetCamera()
        ren.GetActiveCamera().Zoom(1.2)
        
        ren2.AddActor(coneActor)
        ren2.ResetCamera()
        ren2.GetActiveCamera().Zoom(1.2)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(widget, 1, wx.EXPAND | wx.ALL, 10)
        sizer.Add(widget2, 1, wx.EXPAND | wx.ALL, 10)
        self.SetSizer(sizer)
        self.Layout()
        
        self.Show(True)

    def OnAbout(self,event):
        d = wx.MessageDialog(self, "A simple display of vtkConeSource \n in wxPython","About Simple vtk Cone", wx.OK)
        d.ShowModal()
        d.Destroy()
    def OnExit(self,event):
        self.Close(True)

app = wx.PySimpleApp()
frame = MainWindow(None, -1, "wxPython with vtk")
app.MainLoop()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070405/e2fc7733/attachment.htm>


More information about the vtkusers mailing list