Getting a Number Range from 1 to X
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Getting a Number Range from 1 to X
Hello
After my script gets the page number of the last page of a PDF, I need a script that (1) generates the range of numbers from 1 to the total number of pages and then (2) sets the text of an menu button to those numbers as a list, e.g., if the total pages of an PDF is 3, the script sets the text of an pulldown menu as follows:
The purpose is to enable the user to go to a particular page of a PDF. If I have the range of numbers, I know how to set the text, but am frustrated in finding the script that gets the numbers. I am thinking a repeat loop and an array are used but am asking for confirmation and perhaps a tip if not the actual script. Thanks for your replies.
Monty
After my script gets the page number of the last page of a PDF, I need a script that (1) generates the range of numbers from 1 to the total number of pages and then (2) sets the text of an menu button to those numbers as a list, e.g., if the total pages of an PDF is 3, the script sets the text of an pulldown menu as follows:
The purpose is to enable the user to go to a particular page of a PDF. If I have the range of numbers, I know how to set the text, but am frustrated in finding the script that gets the numbers. I am thinking a repeat loop and an array are used but am asking for confirmation and perhaps a tip if not the actual script. Thanks for your replies.
Monty
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Getting a Number Range from 1 to X
Hi.
Make two buttons. One is an ordinary button, and the other is, say a popup button which you will name "pages". In the script of the ordinary button:
Now this needs tweaking, for example, what do you want the popup to "show" as its name before it is loaded? And you will want to modify how the max page number is gleaned from your other handlers. That sort of thing.
Craig
Make two buttons. One is an ordinary button, and the other is, say a popup button which you will name "pages". In the script of the ordinary button:
Code: Select all
on mouseUp
ask "How many pages?"
if it is an integer then
repeat with y = 1 to it
put y into line y of temp
end repeat
put temp into btn "pages"
end if
end mouseUp
Craig
Re: Getting a Number Range from 1 to X
Gonna take a stab in the dark on this one, as I haven't used the pdf viewer in livecode.
In theory, I guess, you want a dropdown menu that automatically fills with number from 1 to the number of pages in your pdf, which when clicked on, takes you to the page...
First, how are you viewing the pdf? XPDFViewer? or in the revBrowser? I am sure each has their limitations...
What I would do, without exact scripting, is this:
Have the pdf being displayed somehow.
Have a option menu button on screen. Call it "Pages"
When the pdf is opened (loaded into viewer, etc), have a part of the script that opens the pdf that asks how many pages there are in the pdf (In xPDFViewer, it might be something like
Or something similar in revBrowser
Put that number into a script that generates a container that has all of the numbers from 1 to (the number of pages you just found out)
such as:
(much borrowed from Craig's post, but a different way if Craig's way doesn't generate the proper list. I am sure his way will do it, and his is a simpler way!)
All you'll need to do is work out how to get your number of pages, and that may be determined by how you are viewing it...
then, in your menu button "Pages", have a script like this:
I ran that code through a sample stack that just shifted number from one box to the menu and the menu pick to another box, and it worked fine.
The only thing left is to work through pdf viewing.
Hope that helps. Any more info you can supply will help to fill in the blanks.
In theory, I guess, you want a dropdown menu that automatically fills with number from 1 to the number of pages in your pdf, which when clicked on, takes you to the page...
First, how are you viewing the pdf? XPDFViewer? or in the revBrowser? I am sure each has their limitations...
What I would do, without exact scripting, is this:
Have the pdf being displayed somehow.
Have a option menu button on screen. Call it "Pages"
When the pdf is opened (loaded into viewer, etc), have a part of the script that opens the pdf that asks how many pages there are in the pdf (In xPDFViewer, it might be something like
Code: Select all
XPDFViewer_Get(viewerName, property)
--i.e.--
XPDFViewer_Get(PDF, pageCount)
Put that number into a script that generates a container that has all of the numbers from 1 to (the number of pages you just found out)
such as:
Code: Select all
put {the number of pages} into tNumberOfPages
if tNumberOfPages is an integer then
repeat with y=1 to tNumberOfPages
put cr & y after temp
end repeat
delete line 1 of temp --removes leading blank line--
put temp into button "pages"
end if
All you'll need to do is work out how to get your number of pages, and that may be determined by how you are viewing it...
then, in your menu button "Pages", have a script like this:
Code: Select all
on menuPick theItem
if theItem is an integer then
--script to go to page theItem of pdf. Will be determined by how you're viewing the pdf
end if
end menuPick
The only thing left is to work through pdf viewing.
Hope that helps. Any more info you can supply will help to fill in the blanks.
Re: Getting a Number Range from 1 to X
Thank you Craig and Xero
Craig, your script worked. I did not think of the command "put temp into butn" as creating the list of numbers in the button, and I overlooked the use of the chunk line in the repeat loop.
Xero, to answer your question, I am using the PDF browser that comes with the Business License. It is much easier to manipulate than XPDF, and unlike the former two, I don't see how the browser widget allows programmatic navigation to a particular page.
Monty
Craig, your script worked. I did not think of the command "put temp into butn" as creating the list of numbers in the button, and I overlooked the use of the chunk line in the repeat loop.
Xero, to answer your question, I am using the PDF browser that comes with the Business License. It is much easier to manipulate than XPDF, and unlike the former two, I don't see how the browser widget allows programmatic navigation to a particular page.
Monty
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Getting a Number Range from 1 to X
Monty.
The contents of a button (which is a container just like a field) and in particular a menu-style button, FORMS the menuItems for that button. You can load them by hand from the inspector, of course, or, under script control.
The text property of such a button is the same as the "contents" of that button
One small issue, which I mentioned, is how you choose to use the selection, and to show it or not. So the name of the button is one thing, and the menuItem selection is another. Each of the several styles of menu buttons works a little differently. So experiment.
Craig
The contents of a button (which is a container just like a field) and in particular a menu-style button, FORMS the menuItems for that button. You can load them by hand from the inspector, of course, or, under script control.
The text property of such a button is the same as the "contents" of that button
One small issue, which I mentioned, is how you choose to use the selection, and to show it or not. So the name of the button is one thing, and the menuItem selection is another. Each of the several styles of menu buttons works a little differently. So experiment.
Craig