[pygtk] Anyone have any example code for manually handling
scrolling
Doug Quale
quale1 at charter.net
Sat Aug 14 06:11:17 WST 2004
Steve McClure <smcclure at racemi.com> writes:
> I'm using PyGtk 0.6.9 and I'm populating a CList with records from a
> database. However there might be quite a few, let's say thousands and
> and at least one object is instantiated for each row so it can be quite
> slow. I want to just load data based on which portion of the list is
> visible in a scrolled window. Anyone have pointers on where I find out
> the first and last visible rows and how to calculate the proper values
> to set the scroll bar adjustment to properly indicate the relative size?
Here's the briefest of hints; it might get you started.
I don't think you need to worry about which rows are visible. Watch
the adjustment associated with the scrollbar and append more rows to
the CList when it's scrolled to the end.
def on_scrolling(adjustment):
"""Add more rows to the model when scrolling off the end of the TreeView.
Connect this function to the \'value_changed\' signal of the
appropriate vertical scrollbar adjustment.
"""
# Add 1.0 to the comparison value to make sure we don't get
# bitten by rounding. This really shouldn't be a problem, but
# better safe than sorry. Also it helps if the last line is
# only partially visible.
## FIXME: consider going to a percentage calculation like 4/5.
if adjustment.value + adjustment.page_size + 1.0 >= adjustment.upper:
... add more rows to the list ...
Connect to the 'value-changed' signal of the scrollbar:
sb.connect('value-changed', on_scrolling)
More information about the pygtk
mailing list