7
votes

I'm creating an application with wxPython and VTK. There is a configuration panel (wx.Panel) on the left of screen and a VTK window on the right, also based on a wx.Panel. The panels are placed in the wxFrame's boxsizer and sized using proportional sizing as defined in the wxFormBuilder application, which is then used to generate an XRC file.

enter image description here

I am having a very specific problem with some Windows 7 machines consistently not sizing the VTK portion of the window correctly - See the white border around the VTK window in the screenshot above. I am attempting to make this VTK window a fixed 1280x720 - and it is - but there is a sizing issue with some element which is chopping of the bottom and right of the window. This bug is not present when run on Ubuntu 10.04, XP, or some builds of Windows 7 (I'm not sure what is unique about those that work and those that don't yet).

When experiencing this bug, I can interact with the white portions of the screen - clicks are correctly handled through the VTK interactor, so it's sort-of still part of my VTK scene.

The application setup is as below, where the right-hand VTK pane is the graphics_panel. The panel is set with wxEXPAND and no other flags, and all elements in my app are set to size automatically (no min, max or default size set). The only exception to this is bSizer1 (the main wxFrame sizer) which has a minimum width and height set (I'm not sure if this is the right way to go, but it seems to work okay).

panel setup

I generate XRC from wxFormBuilder and then use this in my application, where have my VTK scene set up as below:

class MyScene(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, style=wx.NO_BORDER) 
        #'parent' is main_frame (wx.Frame instance)
        self._parent = parent
        self.renderer = vtk.vtkRenderer()

        # I create and add my VTK actors here (SNIPPED)

        self._set_lighting()

        self.widget = VTKWidget(self,-1) #VTKWidget is a wxVTKRenderWindowInteractor
        self.widget.GetRenderWindow().AddRenderer(self.renderer)
        self.widget.Enable(1)
        self.widget.SetDoubleBuffered(True)

        self.Bind(wx.EVT_SIZE, self.on_size)

I have been trying to troubleshoot what element is sized what using the on_size function for MyScene, but nothing below fixes my issue. The values reported on both correctly functioning and erroneous systems are as expected.

def on_size(self, evt):
    print "---- MyScene on_size ----"
    print "Widget size:", self.widget.GetSize() #wxVTKRenderWindowInteractor
    print "Client size:", self.GetClientSize() #wxPanel.GetClientSize
    print "Parent size:", self._parent.GetSize() #wxFrame
    print "Renderer size:", self.renderer.GetSize() #vtkRenderer
    self.renderer.Clear()
    self.widget.SetSize((1280, 720))
    renWin = self.widget.get_render_window()
    renWin.SetSize(1280, 720)
    self._parent.Layout()
    self.renderer.Clear()
    renWin.SetSize(1280, 720)

On a correctly functioning system, the output is:

---- MyScene on_size ----
Widget size: (1280, 720)
Client size: (1296, 720)
Parent size: (1296, 720)
Renderer size: (1280, 720)

On a "bad" Windows 7 system as in the screenshot in this question, the output is similar:

---- MyScene on_size ----
Widget size: (1280, 720)
Client size: (1234, 728)
Parent size: (1234, 728)
Renderer size: (1280, 720) 

So in summary, I don't know which element is being sized incorrectly. The VTK renderer size is correct, as taking a VTK screenshot to file produces a 1280x720 output showing the full scene with no white clipping, and as said above I can interact with the VTK scene using the white 'clipped' portions of the screen.

Is this a VTK or WX element not being sized correctly? Can anyone give me any tips on how to troubleshoot this problem further? Which other elements should I be looking at the sizes of? How should I be hard-sizing my graphics panel to 1280x720 and letting my config panel size itself appropriately?

The issue occurs when using Python 2.7.5, VTK 5.10.1 and wxpython 2.8, but only on some Windows 7 machines.

1
Reproduce the problem with one of the wxWidgets samples. You'll get a lot more interaction.Tamer
@Tamer is there a wxWidgets example involving using a VTK window? I suspect the sizing issue is more related to the VTK side of things than the WX side.John Lyon
Can you build a minimal runnable sample which demonstrates the problem?Fenikso

1 Answers

1
votes

Like you, I'm developing an application using vtk and wxpython, this cocktail is sometime surprising ! I think your problem come from an absence of sizer. the snippet below work both on linux and windows (including 7) :

class Plotter3d(wx.Panel):

    def __init__(self, parent, *args, **kwargs):
        wx.Panel.__init__(self, parent, *args, **kwargs)      
        self.build_panel()

    def build_panel(self):
        self.viewer = wx.Panel(self)
        self.iren = wxVTKRenderWindowInteractor(self.viewer, -1, size=(500,500), flag=wx.EXPAND)
        self.iren.SetPosition((0,0))

        self.iren.Enable(1)

        # create renderer  
        self.renderer = vtk.vtkRenderer()
        self.iren.GetRenderWindow().AddRenderer(self.renderer)

        Sizer = wx.BoxSizer(wx.VERTICAL)
        Sizer.Add(self.iren, 1, wx.EXPAND, 0)

        self.viewer.SetSizer(Sizer)        
        Sizer.Fit(self.viewer)
        self.viewer.Layout() 

hope this will help you