X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7b9da2077d0975db6c965a85c91d5aca671ab5e3..5e9ff6adaa0982b43f6fd2b50d72e3639cd521d2:/utils/wxPython/lib/vtk.py diff --git a/utils/wxPython/lib/vtk.py b/utils/wxPython/lib/vtk.py index 66c1c4dfbb..eab82b5dc0 100644 --- a/utils/wxPython/lib/vtk.py +++ b/utils/wxPython/lib/vtk.py @@ -28,15 +28,24 @@ import math #---------------------------------------------------------------------- -class wxVTKRenderWindow(wxWindow): +class wxVTKRenderWindow(wxScrolledWindow): def __init__(self, parent, id, position=wxDefaultPosition, size=wxDefaultSize, style=0): - wxWindow.__init__(self, parent, id, position, size, style) + wxScrolledWindow.__init__(self, parent, id, position, size, style) self.renderWindow = vtkRenderWindow() - hdl = self.GetHandle() - self.renderWindow.SetWindowInfo(str(hdl)) + if wxPlatform != '__WXMSW__': + # We can't get the handle in wxGTK until after the widget + # is created, the window create event happens later so we'll + # catch it there + EVT_WINDOW_CREATE(self, self.OnCreateWindow) + else: + # but in MSW, the window create event happens durring the above + # call to __init__ so we have to do it here. + hdl = self.GetHandle() + self.renderWindow.SetWindowInfo(str(hdl)) + EVT_LEFT_DOWN (self, self.SaveClick) EVT_MIDDLE_DOWN(self, self.SaveClick) @@ -44,7 +53,7 @@ class wxVTKRenderWindow(wxWindow): EVT_LEFT_UP (self, self.Release) EVT_MIDDLE_UP (self, self.Release) EVT_RIGHT_UP (self, self.Release) - EVT_MOTION(self, self.MouseMotion) + EVT_MOTION (self, self.MouseMotion) def GetRenderer(self): @@ -60,6 +69,14 @@ class wxVTKRenderWindow(wxWindow): dc = wxPaintDC(self) self.renderWindow.Render() + def OnCreateWindow(self, event): + hdl = self.GetHandle() + self.renderWindow.SetWindowInfo(str(hdl)) + + def OnEraseBackground(self, event): + pass + + def SaveClick(self, event): self.prev_x, self.prev_y = event.GetPositionTuple() @@ -109,49 +126,3 @@ class wxVTKRenderWindow(wxWindow): - -if __name__ == '__main__': - class TestFrame(wxFrame): - def __init__(self, parent): - wxFrame.__init__(self, parent, -1, "VTK Test", size=(450,450)) - - rw = wxVTKRenderWindow(self, -1) - - # Get the render window - renWin = rw.GetRenderWindow() - - # Next, do the VTK stuff - ren = vtkRenderer() - renWin.AddRenderer(ren) - cone = vtkConeSource() - cone.SetResolution(80) - coneMapper = vtkPolyDataMapper() - coneMapper.SetInput(cone.GetOutput()) - coneActor = vtkActor() - coneActor.SetMapper(coneMapper) - ren.AddActor(coneActor) - coneMapper.GetLookupTable().Build() - - # Create a scalar bar - scalarBar = vtkScalarBarActor() - scalarBar.SetLookupTable(coneMapper.GetLookupTable()) - scalarBar.SetTitle("Temperature") - scalarBar.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport() - scalarBar.GetPositionCoordinate().SetValue(0.1, 0.01) - scalarBar.SetOrientationToHorizontal() - scalarBar.SetWidth(0.8) - scalarBar.SetHeight(0.17) - ren.AddActor2D(scalarBar) - - - - class TestApp(wxApp): - def OnInit(self): - f = TestFrame(None) - self.SetTopWindow(f) - f.Show(true) - return true - - app = TestApp(0) - app.MainLoop() -