[wxPython] Scrolling anomaly in FlexGridSizer inhibits cell editing in Grid

I have wxGrids in a wxFlexGridSizer, and this leads to a
strange problem, illustrated by the included code. In this
simple example I only use one grid, but I normally use more.
If I place the grid directly in the frame, the problem goes
away.

The problem is that when I edit field after field, I'll
eventually reach a row which is not visible. Then the
grid will scroll to make it visible, but with a FlexGridSizer
it seems to scroll a millimetre to little or something like
that.

When I try to type some text, nothing will happen. If I press
enter, I will get to the next row, but the problem will remain
the same there. In this setup, with 10 rows and a 100 pixel high
frame, I can edit five rows without vertical scrolling. Then when
I type enter it will scroll, but obviously slightly too little,
and the next three rows won't respond to my typing unless I
click on the scroll bar to get the cell completely inside the
visible area. The last two rows work as they should.

I'm using wxPython 2.3.1 under Win2k.

TIA

Magnus

#celldemo.py
#Magnus Lyckå, Thinkware AB, 2001

from wxPython.wx import *
from wxPython.grid import *

class MyFrame(wxFrame):
     def __init__(self, parent, id, title):
         wxFrame.__init__(self, parent, id, title,
                          wxPoint(100, 100), wxSize(200, 100))

     def AddGrids(self, gridArray):
         assert type(gridArray)==type([])
         self.rows = len(gridArray)
         self.cols = len(gridArray[0])
         self.sizer = wxFlexGridSizer(self.rows, self.cols, 1, 1)
         for i in range(self.cols):
             self.sizer.AddGrowableCol(i)
         for i in range(self.rows):
             self.sizer.AddGrowableRow(i)
         self.SetSizer(self.sizer)
         for row, y in zip(gridArray,range(self.rows)):
             assert type(row) == type([])
             assert len(row) == self.cols
             for grid, x in zip(row, range(self.cols)):
                 self.sizer.AddWindow(grid, 0, wxGROW>wxALIGN_CENTER_VERTICAL|wxALL, 5)
         self.sizer.Fit(self)
         self.SetAutoLayout(true)

class MyGrid(wxGrid):
     def __init__(self, parent, id, x, y):
         self.parent = parent
         wxGrid.__init__(self, parent, id, wxDefaultPosition,
                         wxSize(x, y),
                         wxWANTS_CHARS)
         self.CreateGrid(10, 4)
         self.SetColLabelSize(0)
         self.SetRowLabelSize(0)

class MyApp(wxApp):
     def OnInit(self):
         self.frame = MyFrame(NULL, -1, "This is Frame")
         g = [[self.newGrid(MyGrid)]]
         self.frame.AddGrids(g)
         self.frame.Show(true)
         self.SetTopWindow(self.frame)
         return true
     def newGrid(self, control):
         return apply(control, (self.frame, -1, 200, 100))

def main():
     app = MyApp(0)
     app.MainLoop()

if __name__ == '__main__':
     main()

···

--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

The problem is that when I edit field after field, I'll
eventually reach a row which is not visible. Then the
grid will scroll to make it visible, but with a FlexGridSizer
it seems to scroll a millimetre to little or something like
that.

I don't think the sizer is the cause of the problem, it just happens to make
the grid the right size for the problem manefest itself in this example. If
you resize the frame just a tiny bit larger then the problem either goes
away or happens on different rows, or...

I think I've found a fix that I will check in after a bit more testing.
Unfortunately I can't think of an easy workaround for you to use in the
meantime, except maybe to capture the key down events for the Enter key
similar to what is done in the demo in GridEnterHandler and in the call to
MakeCellVisible use row+1.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

Thank's Robin. I have other hurdles to handle before
the poor users are exposed to the code, so I hope your
fix will be checked in before I need it badly.

/Magnus

···

At 12:58 2001-10-22 -0700, Robin Dunn wrote:

I don't think the sizer is the cause of the problem, it just happens to make
the grid the right size for the problem manefest itself in this example. If
you resize the frame just a tiny bit larger then the problem either goes
away or happens on different rows, or...

I think I've found a fix that I will check in after a bit more testing.
Unfortunately I can't think of an easy workaround for you to use in the
meantime, except maybe to capture the key down events for the Enter key
similar to what is done in the demo in GridEnterHandler and in the call to
MakeCellVisible use row+1.

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se