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