VListBox ScrollRowPages in Up direction fails on 2.9.4 and 3.0.1 MSW

Trying to programmatically scroll the VListBox up doesn’t work. Specifically the line:
print self.vlb.ScrollRowPages(-1)

(needs to be run from the demo directory, since that is where I got the file)

VListBox.py (6.53 KB)

I think I settled on a reasonable work-around for now… it isn’t perfect, but it is predictable and doesn’t skip rows (so users won’t miss out on a selection choice).

this is based on the previously posted VListBox.py demo file:

def onButtonUp(self, event):

    start = self.vlb.GetVisibleRowsBegin()

    i=start

    h=self.vlb.GetSize()[1]

    heightOfPrevPageRows = 0

    while True:

        i-=1

        heightOfPrevPageRows += self.vlb.OnMeasureItem(i)

        if heightOfPrevPageRows>h:

            i+=1

            break

    print start, i, start-i

    print self.vlb.ScrollRows(i-start)

def onButtonDown(self, event):

    numShown = self.vlb.GetVisibleRowsEnd() - self.vlb.GetVisibleRowsBegin()

    print numShown

    print self.vlb.ScrollRows(numShown-1)
···

On Friday, September 5, 2014 11:59:59 PM UTC-7, Nathan McCorkle wrote:

Trying to programmatically scroll the VListBox up doesn’t work. Specifically the line:
print self.vlb.ScrollRowPages(-1)

(needs to be run from the demo directory, since that is where I got the file)

I guess I also should have posted this too:

This method must be overridden. It should return the height

# required to draw the n'th item.

def OnMeasureItem(self, n):

    #get the current string

    text = self.GetItemText(n)

    if text is None:

        return  0xFF

    height = 0

    for line in text.split('\n'):

        w, h = super(wx.VListBox, self).GetTextExtent(line)

        height += h

    return height + 5
···

On Saturday, September 6, 2014 12:56:54 AM UTC-7, Nathan McCorkle wrote:

I think I settled on a reasonable work-around for now… it isn’t perfect, but it is predictable and doesn’t skip rows (so users won’t miss out on a selection choice).

this is based on the previously posted VListBox.py demo file:

def onButtonUp(self, event):
    start = self.vlb.GetVisibleRowsBegin()
    i=start
    h=self.vlb.GetSize()[1]
    heightOfPrevPageRows = 0
    while True:
        i-=1
        heightOfPrevPageRows += self.vlb.OnMeasureItem(i)
        if heightOfPrevPageRows>h:
            i+=1
            break
    print start, i, start-i
    print self.vlb.ScrollRows(i-start)
def onButtonDown(self, event):
    numShown = self.vlb.GetVisibleRowsEnd() - self.vlb.GetVisibleRowsBegin()
    print numShown
    print self.vlb.ScrollRows(numShown-1)

On Friday, September 5, 2014 11:59:59 PM UTC-7, Nathan McCorkle wrote:

Trying to programmatically scroll the VListBox up doesn’t work. Specifically the line:
print self.vlb.ScrollRowPages(-1)

(needs to be run from the demo directory, since that is where I got the file)

sorry that 0xFF should have been 0xFFFF (WARNING: this will only work until people start to have monitors with more than 4294967296 pixels in the vertical direction)!

···

On Saturday, September 6, 2014 1:14:54 AM UTC-7, Nathan McCorkle wrote:

I guess I also should have posted this too:

This method must be overridden. It should return the height

# required to draw the n'th item.
def OnMeasureItem(self, n):
    #get the current string
    text = self.GetItemText(n)
    if text is None:
        return  0xFF
    height = 0
    for line in text.split('\n'):
        w, h = super(wx.VListBox, self).GetTextExtent(line)
        height += h
    return height + 5

On Saturday, September 6, 2014 12:56:54 AM UTC-7, Nathan McCorkle wrote:

I think I settled on a reasonable work-around for now… it isn’t perfect, but it is predictable and doesn’t skip rows (so users won’t miss out on a selection choice).

this is based on the previously posted VListBox.py demo file:

def onButtonUp(self, event):
    start = self.vlb.GetVisibleRowsBegin()
    i=start
    h=self.vlb.GetSize()[1]
    heightOfPrevPageRows = 0
    while True:
        i-=1
        heightOfPrevPageRows += self.vlb.OnMeasureItem(i)
        if heightOfPrevPageRows>h:
            i+=1
            break
    print start, i, start-i
    print self.vlb.ScrollRows(i-start)
def onButtonDown(self, event):
    numShown = self.vlb.GetVisibleRowsEnd() - self.vlb.GetVisibleRowsBegin()
    print numShown
    print self.vlb.ScrollRows(numShown-1)

On Friday, September 5, 2014 11:59:59 PM UTC-7, Nathan McCorkle wrote:

Trying to programmatically scroll the VListBox up doesn’t work. Specifically the line:
print self.vlb.ScrollRowPages(-1)

(needs to be run from the demo directory, since that is where I got the file)

Forget I ever posted that… I didn’t like dealing with None where I hadn’t before. This is what I’m using now:

def _pageup(self):

    start = self.GetVisibleRowsBegin()

    i=start

    h=self.GetSize()[1]

    heightOfPrevPageRows = 0

    while True:

        if i==0:

            break

        i-=1

        heightOfPrevPageRows += self.OnMeasureItem(i)

        if heightOfPrevPageRows>h:

            i+=1

            break

    print start, i, start-i

    print self.ScrollRows(i-start)

def _pagedown(self):

    numShown = self.GetVisibleRowsEnd() - self.GetVisibleRowsBegin()

    print numShown

    print self.ScrollRows(numShown-1) 
···

On Saturday, September 6, 2014 1:17:52 AM UTC-7, Nathan McCorkle wrote:

sorry that 0xFF should have been 0xFFFF (WARNING: this will only work until people start to have monitors with more than 4294967296 pixels in the vertical direction)!

On Saturday, September 6, 2014 1:14:54 AM UTC-7, Nathan McCorkle wrote:

I guess I also should have posted this too:

This method must be overridden. It should return the height

# required to draw the n'th item.
def OnMeasureItem(self, n):