2000-07-15 19:51:35 +00:00
|
|
|
from wxPython.wx import *
|
|
|
|
from wxPython.lib import vtk
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
class VtkFrame(wxFrame):
|
|
|
|
"""
|
|
|
|
Simple example VTK window that contains a cone.
|
|
|
|
"""
|
|
|
|
def __init__(self, parent, id, title):
|
|
|
|
wxFrame.__init__(self, parent,id,title, size=(450, 300))
|
|
|
|
win = vtk.wxVTKRenderWindow(self, -1)
|
|
|
|
|
|
|
|
renWin = win.GetRenderWindow()
|
|
|
|
|
|
|
|
ren = vtk.vtkRenderer()
|
|
|
|
renWin.AddRenderer(ren)
|
|
|
|
cone = vtk.vtkConeSource()
|
|
|
|
coneMapper = vtk.vtkPolyDataMapper()
|
|
|
|
coneMapper.SetInput(cone.GetOutput())
|
|
|
|
coneActor = vtk.vtkActor()
|
|
|
|
coneActor.SetMapper(coneMapper)
|
|
|
|
ren.AddActor(coneActor)
|
2001-05-18 21:59:59 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
wxEVT_ADD_CONE = 25015
|
|
|
|
|
|
|
|
def EVT_ADD_CONE(win, func):
|
|
|
|
win.Connect(-1, -1, wxEVT_ADD_CONE, func)
|
|
|
|
|
2001-05-18 21:59:59 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
class AddCone(wxPyEvent):
|
|
|
|
def __init__(self):
|
|
|
|
wxPyEvent.__init__(self)
|
|
|
|
self.SetEventType(wxEVT_ADD_CONE)
|
|
|
|
|
2001-05-18 21:59:59 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
class HiddenCatcher(wxFrame):
|
|
|
|
"""
|
|
|
|
The "catcher" frame in the second thread.
|
|
|
|
It is invisible. It's only job is to receive
|
2001-05-18 21:59:59 +00:00
|
|
|
Events from the main thread, and create
|
2000-07-15 19:51:35 +00:00
|
|
|
the appropriate windows.
|
2001-05-18 21:59:59 +00:00
|
|
|
"""
|
2000-07-15 19:51:35 +00:00
|
|
|
def __init__(self):
|
2001-05-18 21:59:59 +00:00
|
|
|
wxFrame.__init__(self, None, -1, '')
|
2000-07-15 19:51:35 +00:00
|
|
|
EVT_ADD_CONE(self, self.AddCone)
|
|
|
|
|
2001-05-18 21:59:59 +00:00
|
|
|
def AddCone(self,evt):
|
2000-07-15 19:51:35 +00:00
|
|
|
add_cone()
|
2001-05-18 21:59:59 +00:00
|
|
|
|
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#---------------------------------------------------------------------------
|
2001-05-18 21:59:59 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
class SecondThreadApp(wxApp):
|
|
|
|
"""
|
|
|
|
wxApp that lives in the second thread.
|
2001-05-18 21:59:59 +00:00
|
|
|
"""
|
2000-07-15 19:51:35 +00:00
|
|
|
def OnInit(self):
|
|
|
|
catcher = HiddenCatcher()
|
|
|
|
#self.SetTopWindow(catcher)
|
|
|
|
self.catcher =catcher
|
|
|
|
return true
|
2001-05-18 21:59:59 +00:00
|
|
|
|
2000-07-15 19:51:35 +00:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2001-05-18 21:59:59 +00:00
|
|
|
def add_cone():
|
|
|
|
frame = VtkFrame(None, -1, "Cone")
|
2000-07-15 19:51:35 +00:00
|
|
|
frame.Show(true)
|
2001-05-18 21:59:59 +00:00
|
|
|
|