Discussion:
VListBox ScrollRowPages in Up direction fails on 2.9.4 and 3.0.1 MSW
Nathan McCorkle
2014-09-06 06:59:58 UTC
Permalink
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)
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-06 07:56:54 UTC
Permalink
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)
Post by Nathan McCorkle
Trying to programmatically scroll the VListBox up doesn't work.
print self.vlb.ScrollRowPages(-1)
(needs to be run from the demo directory, since that is where I got the
file)
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-06 08:14:53 UTC
Permalink
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
Post by Nathan McCorkle
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).
start = self.vlb.GetVisibleRowsBegin()
i=start
h=self.vlb.GetSize()[1]
heightOfPrevPageRows = 0
i-=1
heightOfPrevPageRows += self.vlb.OnMeasureItem(i)
i+=1
break
print start, i, start-i
print self.vlb.ScrollRows(i-start)
numShown = self.vlb.GetVisibleRowsEnd() -
self.vlb.GetVisibleRowsBegin()
print numShown
print self.vlb.ScrollRows(numShown-1)
Post by Nathan McCorkle
Trying to programmatically scroll the VListBox up doesn't work.
print self.vlb.ScrollRowPages(-1)
(needs to be run from the demo directory, since that is where I got the
file)
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-06 08:17:52 UTC
Permalink
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)!
Post by Nathan McCorkle
# This method must be overridden. It should return the height
# required to draw the n'th item.
#get the current string
text = self.GetItemText(n)
return 0xFF
height = 0
w, h = super(wx.VListBox, self).GetTextExtent(line)
height += h
return height + 5
Post by Nathan McCorkle
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).
start = self.vlb.GetVisibleRowsBegin()
i=start
h=self.vlb.GetSize()[1]
heightOfPrevPageRows = 0
i-=1
heightOfPrevPageRows += self.vlb.OnMeasureItem(i)
i+=1
break
print start, i, start-i
print self.vlb.ScrollRows(i-start)
numShown = self.vlb.GetVisibleRowsEnd() -
self.vlb.GetVisibleRowsBegin()
print numShown
print self.vlb.ScrollRows(numShown-1)
Post by Nathan McCorkle
Trying to programmatically scroll the VListBox up doesn't work.
print self.vlb.ScrollRowPages(-1)
(needs to be run from the demo directory, since that is where I got the
file)
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nathan McCorkle
2014-09-06 08:24:09 UTC
Permalink
Post by Nathan McCorkle
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)!
Post by Nathan McCorkle
# This method must be overridden. It should return the height
# required to draw the n'th item.
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)
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...