grid.MakeVisible() not working for me

Stuart McGraw smcg4191 at frii.com
Wed Jan 2 12:23:40 PST 2008


This seems likely to be pilot error since it seems
it would have been noticed by now if it was wxPython
problem, but I'm not seeing it...

I create a grid with more rows than can be shown and
it displays as expected with vertical scrollbars and
displaying cell (0,0) in the top left corner.

But if I call the Grid method MakeCellVisible(0,0)(which
I presume should have no effect since the cell is already
visible), the grid is scrolled down so that only the bottom
border of the top row is visible.

Conditionalizing the call using .IsVisible(0,0) doesn't
help because it seems to return false, even though the
cell *is* visible.  Nor is problem limited to row 0, it
occurs with any row number.

As I said, I strongly suspect I am doing something wrong
and would appreciate a clue. :-)  Demo code attached.
wxPython-2.8.7.1, MS Windows-2000.
-------------- next part --------------
#/usr/bin/env python

# Demonstrates problem with Grid methods IsVisible() and
# MakeCellVisible().
#
# 1. Below IsVisible seems to return false, regardless of =

#    whether the 'wholeCellVisible' is True or False, even =

#    though cell 0,0 is visible.
#
# 2. MakeCellVisivle(0,0) causes the grid to be scrolled
#    down so that only the bottom border of row 0 is visible,
#    the main body of the row is not.
# =

# Comment oot the .IsVisible() and .MakeCellVisible() calls
# below and the grid displays normally.

import wx.grid, random

def main ():
	app =3D Application ()
	app.MainLoop ()

class Application (wx.App):
    def __init__ (self):
	wx.App.__init__(self, redirect=3D0)

    def OnInit (self):
	frame =3D Frame ("MakeCellVisible Problem")
	frame.Show (True)
	return True

class Frame (wx.Frame):
    def __init__ (self, title=3D""):
	wx.Frame.__init__ (self, None, -1, title, size=3D(300,250))
	panel =3D wx.Panel (self, -1)
	sz =3D wx.BoxSizer (wx.VERTICAL)

	self.data =3D getrows (30)
	self.grid =3D create_grid (self, self.data)
	sz.Add (self.grid, 1, wx.EXPAND)
	self.SetSizer (sz)

	############################################
	if not self.grid.IsVisible (1, 0, wholeCellVisible=3DTrue):
	    print "cell not visible"
	    self.grid.MakeCellVisible (1, 0) =

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

def create_grid (parent, data):
        grid =3D wx.grid.Grid (parent)
	grid.SetRowLabelSize (15)
	grid.SetColLabelSize (25)
	nrows, ncols =3D len(data), len(data[0])
	grid.CreateGrid (nrows, ncols)
	for r in range (nrows):
	    for c in range (ncols):
		grid.SetCellValue (r,c, str(data[r][c]))
	return grid

def getrows (count=3D1, lastid=3D[1]):
	# Provides a source of rows filled with random data,
	rv =3D []
	chars =3D list('abcdefghijk')
	for i in range (lastid[0],lastid[0]+count):
	    random.shuffle (chars)
	    rv.append ((i, random.randint (0,99),
			 ''.join(chars[:random.randint(2,len(chars))])))
	lastid[0] +=3D count
	return rv

if __name__ =3D=3D '__main__': main ()


More information about the wxpython-users mailing list