I'm having some problems when calling GetViewStart() from within a wxGrid,
and I think it may be an error within wxPython itself. I wrote a small
program that calculates the top and bottom visible rows for a wxGrid based
on the scroll position. It works fine (within a row or two, which is fine
for my application) so long as the screen is scrolled by clicking the scroll
arrows or dragging the scroll bar. However, if I click within the scrollbar
(causing a page up or page down), I get the wrong starting coord reported
back by GetViewStart(). It seems to only think it is moving by one scroll
unit, instead of one page's worth of scroll units. It also realigns itself
properly if I start using the scroll arrows again. Is this a problem in
wxPython, or my code?
-Sean Levatino
sean@activeprime.com
from wxPython.wx import *
from wxPython.grid import *
class MyDataGrid(wxGrid):
def __init__(self,parentWindow,pos = wxDefaultPosition,size = wxDefaultSize):
wxGrid.__init__(self,parentWindow,wxNewId(),pos,size)
self.CreateGrid(100,100)
self.BeginBatch()
for row in xrange(100):
for col in xrange(100):
self.SetCellValue(row, col, "Test")
self.EndBatch()
EVT_SCROLLWIN(self, self.OnScroll)
EVT_PAINT(self, self.OnScroll)
def OnScroll(self, event):
xStart,yStart = self.GetViewStart()
xScrollSize,yScrollSize = self.GetScrollPixelsPerUnit()
w,h = self.GetClientSize()
cellHeight = self.GetDefaultRowSize()
topPixel = yStart * yScrollSize
bottomPixel = topPixel + h
topRow = (topPixel / cellHeight)
bottomRow = (bottomPixel / cellHeight) + 1
print "top:\t\t",topRow
print "bottom:\t",bottomRow
print " "
event.Skip()
class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1,"")
grid = MyDataGrid(frame)
frame.Show(true)
self.SetTopWindow(frame)
return true
app = MyApp(0)
app.MainLoop()