wx.grid.Grid refresh problem

Hi all,
I am working a wxPython GUI application and have encountered this weird issue. I am using wxPython 2.8.9.2.

basically, the widget hierarchy is like this:

Panel (BoxSizer_Vertical) --> StaticText1

–> BoxSizer_Horizontal --> Spacer

–> wx.grid.Grid

–> BoxSizer_Vertical1 --> Button1

–> TextControl1

–> Button2

–> Spacer

I would like to make the elements align center in BoxSizer_Horizontal just under Panel’s BoxSizer_Vertical, but I really can’t find a way to do that…

(If you know a way how to do that, please let me know as well.)

Therefore I add the Spacers under BoxSizer_Horizontal and force them to have proportion flag = 1, while Grid and BoxSizer_Vertical1 have proportion flag = 0.

This way, the Spacers would push the contents to the middle and achieve the align center effect.

This seems to work fine for the layout when I run the program, except the Grid is out of position like this:

However, when I focus on the Grid, then it layouts / display correctly:

I’ve tried to call BoxSizer_Horizontal.Layout() after adding the Grid; also tried to refresh / update the Grid after the parent sizers layout, but still has this weird problem…

Does Anyone has any ideas on what’s going on here?

Below is my code snippets for this panel, thanks for your help!!!

class PanelAdjustHexapod ( ScrolledPanelBase ):

def __init__( self, parent, alignObj ):

	self.alignObj = alignObj

	ScrolledPanelBase.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.TAB_TRAVERSAL )

	bSizerPanel = wx.BoxSizer( wx.VERTICAL )

	self.staticTextHexapodAdjustment = wx.StaticText( self, wx.ID_ANY, u"Hexapod Adjustment", wx.DefaultPosition, wx.DefaultSize, 0 )

	self.staticTextHexapodAdjustment.Wrap( -1 )

	self.staticTextHexapodAdjustment.SetFont( wx.Font( 18, 70, 90, 92, False, wx.EmptyString ) )

	bSizerPanel.Add( self.staticTextHexapodAdjustment, 0, wx.ALIGN_CENTER|wx.ALL, 5 )

	bSizerAdjustGrid = wx.BoxSizer( wx.HORIZONTAL )

	bSizerAdjustGrid.AddSpacer( (20, 20), 1, wx.ALL|wx.EXPAND, 5 )
···

####################

	# adjustment grid

	####################

	labels = ["Compensator", "Solve Adjustment", "Include", "Move"]

	dataTypes = [gridlib.GRID_VALUE_STRING, gridlib.GRID_VALUE_FLOAT+':6,6', gridlib.GRID_VALUE_BOOL, gridlib.GRID_VALUE_FLOAT+':6,6']

	self.adjustHexapodGrid = CustomDataGrid(self, labels, dataTypes)

	self.setupAdjustGrid()                                                                           # fill the data

	self.adjustHexapodGrid.SetColLabelSize(30)

	self.adjustHexapodGrid.AutoSize()

	bSizerAdjustGrid.Add( self.adjustHexapodGrid, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

	bSizerAdjustGridControl = wx.BoxSizer( wx.VERTICAL )

	self.buttonIncludeAll = wx.Button( self, wx.ID_ANY, u"Include", wx.DefaultPosition, wx.DefaultSize, 0 )

	bSizerAdjustGridControl.Add( self.buttonIncludeAll, 0, wx.ALL, 5 )

	self.textCtrlFactor = wx.TextCtrl( self, wx.ID_ANY, u"1.0", wx.DefaultPosition, wx.DefaultSize, 0 )

	bSizerAdjustGridControl.Add( self.textCtrlFactor, 0, wx.ALL, 5 )

	self.buttonFactor = wx.Button( self, wx.ID_ANY, u"Set Factor", wx.DefaultPosition, wx.DefaultSize, 0 )

	bSizerAdjustGridControl.Add( self.buttonFactor, 0, wx.ALL, 5 )

	bSizerAdjustGridControl.Layout()

	bSizerAdjustGrid.Add( bSizerAdjustGridControl, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.EXPAND, 5 )

	bSizerAdjustGrid.AddSpacer( ( 20, 20), 1, wx.ALL|wx.EXPAND, 5 )

	bSizerAdjustGrid.Layout()

	bSizerPanel.Add( bSizerAdjustGrid, 0, wx.ALIGN_CENTER|wx.EXPAND|wx.ALL, 5 )

	self.SetSizer( bSizerPanel )

	self.Layout()

	self.SetupScrolling()

	bSizerPanel.Fit(self)

Charlie Chen wrote:

Hi all,
I am working a wxPython GUI application and have encountered this weird
issue. I am using wxPython 2.8.9.2.

Which is 4.5 years old, which is ancient in software years. Any particular reason you haven't updated?

This seems to work fine for the layout when I run the program, except
the Grid is out of position like this:

However, when I focus on the Grid, then it layouts / display correctly:

I've tried to call BoxSizer_Horizontal.Layout() after adding the Grid;
also tried to refresh / update the Grid after the parent sizers layout,
but still has this weird problem...
Does Anyone has any ideas on what's going on here?

There can sometimes be cases on Windows where a repaint can be optimized away when a window is resized or moved if the system thinks that it already has the correct image of the window. Usually that is fine but once in a while things like this can happen, especially during start up when things are being moved and sized a lot during the initial show and layout. However if that was the case and if the sizer is not misbehaving then I would expect the refresh to have worked. Did you try calling the Panel's refresh?

Using the WIT will probably help you diagnose this further. http://wiki.wxpython.org/Widget_Inspection_Tool

Below is my code snippets for this panel, thanks for your help!!!

http://wiki.wxpython.org/MakingSampleApps

If you can duplicate the problem with 2.9.5 in a small sample then I can take a closer look at it. If you can't duplicate it there then you should upgrade to 2.9.5. :slight_smile:

-- Robin Dunn
Software Craftsman