# Demonstrate grid over-growth with wxPython 2.9.9.1 - works OK with 2.8.11.0

import wxversion
#wxversion.select("2.8")
wxversion.select("2.9")

import wx
import wx.grid
import wx.lib.inspection

NUM_ROWS = 8      # Try setting to 8, 16 and 32 in turn


#=========================================================================
# Python source originally generated by wxDesigner 
#-------------------------------------------------------------------------

ID_NUTRLIST = 12000
ID_SCROLLED = 12001

def wxd_designer( parent, call_fit = True, set_sizer = True ):
    item0 = wx.BoxSizer( wx.VERTICAL )
    
    item1 = wx.BoxSizer( wx.HORIZONTAL )
    
    item2 = wx.grid.Grid( parent, ID_NUTRLIST, wx.DefaultPosition, wx.DefaultSize, wx.WANTS_CHARS )
    item2.CreateGrid( NUM_ROWS, 4, wx.grid.Grid.SelectCells )
    item1.Add( item2, 1, wx.GROW|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5 )

    item0.Add( item1, 1, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT|wx.TOP, 0 )

    item3 = wx.BoxSizer( wx.HORIZONTAL )
    
    item4 = wx.BoxSizer( wx.VERTICAL )
    
    item5 = wx.ScrolledWindow( parent, ID_SCROLLED, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL )
    item5.SetScrollbars( 10, 10, 20, 100, 0, 0 )
    item4.Add( item5, 1, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )

    item3.Add( item4, 1, wx.GROW|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5 )

    item0.Add( item3, 1, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5 )

    if set_sizer == True:
        parent.SetSizer( item0 )
        if call_fit == True:
            item0.SetSizeHints( parent )
    
    return item0

#=========================================================================

class Apanel(wx.Panel):
    def __init__(self, parent):
        """ Panel contains two sizers holding a grid and a scrolled window.
            The available space on the panel should be shared equally
        """
        wx.Panel.__init__(self, parent, style=0)
        wxd_designer(self, call_fit=True)

class Aframe(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'Show grid size problem', size=(500,500))
        apanel=Apanel(self)


if __name__ == '__main__':
    print wx.version() 
    app = wx.PySimpleApp()
    Aframe().Show()
    # wx.lib.inspection.InspectionTool().Show() 
    app.MainLoop()


