473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Pmw ScrolledCanvas: How to scroll to specific item?

Hi, I've got a ScrolledCanvas object (sc) and have identified an item
on the canvas to which I wish to scroll. I've been reading around and
experimenting but with not much success.

So far I've managed to get the item's bbox using sc.bbox(item)
And got the proportion of the canvas that's visible using sc.xview()
and sc.yview()
And established the whole canvas bbox using sc.bbox(ALL)

I've even gone on to use some rudimentary maths to work out whether I
need to scroll, then used:
sc.xview_moveto(itemX)

But this is all rather messy and I've not yet got it working.
There must be an easier way?!

Thanks!

John

Jun 5 '06 #1
1 1432
MrBlueSky wrote:
Hi, I've got a ScrolledCanvas object (sc) and have identified an item
on the canvas to which I wish to scroll. I've been reading around and
experimenting but with not much success.

So far I've managed to get the item's bbox using sc.bbox(item)
And got the proportion of the canvas that's visible using sc.xview()
and sc.yview()
And established the whole canvas bbox using sc.bbox(ALL)

I've even gone on to use some rudimentary maths to work out whether I
need to scroll, then used:
sc.xview_moveto(itemX)

But this is all rather messy and I've not yet got it working.
There must be an easier way?!

Thanks!

John


Done it! I realised that searching for the way to do this using Tk
would give me the clue.
For the benefit of any other poor soul who wants to do this, here's my
code:

def scrollToItem(self, item):
"""Work out whether the specified item is on display.
If it's not, scroll to it."""

# Bounding box for the item
xItemMin, yItemMin, xItemMax, yItemMax = self.bbox(item)

# Find out what proportion (0.0 to 1.0) of the canvas is
# currently on view
xViewMinP, xViewMaxP = self.xview()
yViewMinP, yViewMaxP = self.yview()

# Find out the full extent of the canvas
scrollRegionStr = self.component("canvas").cget("scrollregion")
scrollRegionElementsStr=scrollRegionStr.split(' ',4)
xCanvasMin = float(scrollRegionElementsStr[0])
yCanvasMin = float(scrollRegionElementsStr[1])
xCanvasMax = float(scrollRegionElementsStr[2])
yCanvasMax = float(scrollRegionElementsStr[3])
xRange = float(xCanvasMax - xCanvasMin)
yRange = float(yCanvasMax - yCanvasMin)

# Work out the canvas coordinates of the bit of the canvas
that's
# currently on view
xViewMin = float(xViewMinP)*xRange
xViewMax = float(xViewMaxP)*xRange
yViewMin = float(yViewMinP)*yRange
yViewMax = float(yViewMaxP)*yRange

if xItemMin < xViewMin:
newXViewP = float(xItemMin - xCanvasMin)/xRange
self.xview_moveto(newXViewP)
elif xItemMax > xViewMax:
newXViewP = float(xItemMax - xCanvasMin -
(xViewMax-xViewMin))/xRange
self.xview_moveto(newXViewP)

if yItemMin < yViewMin:
newYViewP = float(yItemMin - yCanvasMin)/yRange
self.yview_moveto(newYViewP)
elif yItemMax > yViewMax:
newYViewP = float(yItemMax - yCanvasMin -
(yViewMax-yViewMin))/yRange
self.xview_moveto(newYViewP)

(I'd still very much appreciate any critique of this!)

John

Jun 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nishant | last post by:
I have a combo box with a horizontal scroll bar. (Used SetHorizontalExtent) The dropdown with horizontal scroll bar works fine when I have more items in the dropdown list. However when the...
7
by: veronique rossi | last post by:
Hello, I have put a table in a scrollable DIV so that only one part of the table is visible. Now, I want that, when I scroll, the table is scrolled item by item in the table (as it is done when...
4
by: Filips Benoit | last post by:
Dear All, I have code that selects - find and select - 1 item in a large listbox. This works Ok but most of the time the selected item isn't visible without scrolling down manualy. Is this...
6
by: | last post by:
Hi all, I have a long web form on asp.net 2.0. When I go at the bottom and click on submit, a postback occurs and if there are any validation errors (no client-side checking being done), the...
1
by: dan.gass | last post by:
Hi, I am using the pmw tkinter package and having trouble getting the ScrolledCanvas widget to respond to the mouse wheel. I am running Windows XP. I've Googled it and came up empty. I...
0
by: alcurb | last post by:
I have a ListView control populated with 30 items. ListView height only allows you to see 20 rows at a time. I want to drag an item to the bottom of the list (to the last row), but ListView...
0
by: R.Nijkamp | last post by:
Hello, i was wondering if its an limitation of IE when a asp.net listbox is set disabled, then a user wont be able to scroll inside the listbox. While the user can scroll inside the listbox when...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
0
by: lekin2 | last post by:
So what the heck is going on. I have a Pmw.ScrollingCanvas and inside I put a Pmw.ScrollingText and that all works but I can't get it to scroll. I was thinking I needed an event like: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.