PyGridTableBase can't automatically resize when grid is update by Grid.AutoSize().

I think Grid.AutoSize() resize grid when grid is update. But it doesn't work.
This code is that test menu on Menubar click to update grid. Updated grid's
column size is not match SetColSize.
Maybe my code is wrong. Please tell me it.

#!/usr/bin/env python2.7
# coding: UTF-8

import wx
import wx.grid as wxgrid

class GridTable(wxgrid.PyGridTableBase):

    def __init__(self, update=None):
        wxgrid.PyGridTableBase.__init__(self)

        self.cols_labels = ['0', '1', '2', '3']
        self.data = [['0', '1', '2', '3'], ['4', '5', '6', '7'], ['8', '9',
'10', '11'], ['12', '13', '14', '15']]

        self.update = update

    def GetNumberRows(self):
        return 4

    def GetNumberCols(self):
        return 4

    def GetValue(self, row, col):
        if self.update is None:
            return self.data[row][col]
        else:
            return self.update[row][col]

    def GetColLabelValue(self, col):
        return self.cols_labels[col]

    def GetRowLabelValue(self, row):
        return row

class Viewer(wx.Panel):

    def __init__(self, *args, **kwags):
        wx.Panel.__init__(self, *args, **kwags)

        self.grid = wxgrid.Grid(self)
        self.table = GridTable()
        self.grid.SetTable(self.table)

        self.grid.SetColSize(0, 50)
        self.grid.SetColSize(1, 50)
        self.grid.SetColSize(2, 50)
        self.grid.SetColSize(3, 50)
        self.grid.Refresh()

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.grid, 1, wx.EXPAND)
        self.SetSizerAndFit(sizer)

    def update(self):
        self.data = [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'], ['i', 'j',
'k', 'l'], ['m', 'n', 'o', 'p']]
        self.grid.ClearGrid()
        self.table = GridTable(self.data)
        self.grid.SetTable(self.table)
        self.grid.AutoSize()
        # self.grid.AutoSizeColumns()

class MainWindow(wx.Frame):

    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.CreateStatusBar() # a Statusbar in the bottom of the window

        # setting up the menu.
        file_menu = wx.Menu()
        file_menu.Append(wx.ID_OPEN, '&Test', 'Test')

        # creating the menubar.
        menu_bar = wx.MenuBar()
        menu_bar.Append(file_menu, "&File")
        self.SetMenuBar(menu_bar) # adding the MenuBar to the Frame
content.
        self.Connect(wx.ID_OPEN, -1, wx.wxEVT_COMMAND_MENU_SELECTED,
self.open)

        sizer = wx.BoxSizer(wx.VERTICAL)
        self.viewer = Viewer(self)
        sizer.Add(self.viewer, 1, wx.EXPAND)

    def open(self, event):
        self.viewer.update()

if __name__ == '__main__':
    app = wx.App(False)
    frame = MainWindow(None, title='test', size=(300, 300))
    frame.Show()
    app.MainLoop()

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/PyGridTableBase-can-t-automatically-resize-when-grid-is-update-by-Grid-AutoSize-tp5724750.html
Sent from the wxPython-users mailing list archive at Nabble.com.