menu builder help please
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
menu builder help please
Hi Guys,
I'm experimenting with the menu builder for my app. So far it looks straightforward even though I can't find much documentation on the tool. I've built a format menu with the following structure
Fonts
Typeface
Size
10
11
12
Style
Bold
Italic
Underline
My question is how do I get Typeface to display all the fonts on my system? I found some sample code and managed to populate an option menu called "cb_font" with all the fonts but can't get the top menu where I have the word typeface replaced with all the fonts. I'm calling this script on the open card handler as I read its best practice to load this menu up on startup.
createFontMenu
--Insert script for Font menu item here
get the fontNames ## list of installed fonts
sort lines of it
put it into button "Typeface"
--set the text of button "cb_font" to it
end createFontMenu
Many thanks as always
Jalz
I'm experimenting with the menu builder for my app. So far it looks straightforward even though I can't find much documentation on the tool. I've built a format menu with the following structure
Fonts
Typeface
Size
10
11
12
Style
Bold
Italic
Underline
My question is how do I get Typeface to display all the fonts on my system? I found some sample code and managed to populate an option menu called "cb_font" with all the fonts but can't get the top menu where I have the word typeface replaced with all the fonts. I'm calling this script on the open card handler as I read its best practice to load this menu up on startup.
createFontMenu
--Insert script for Font menu item here
get the fontNames ## list of installed fonts
sort lines of it
put it into button "Typeface"
--set the text of button "cb_font" to it
end createFontMenu
Many thanks as always
Jalz
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: menu builder help please
Hi.
The menuBuilder seems like a great tool, and it is. But it also is haunted.
Buttons are containers, and there is nothing special, particularly, about those buttons, except for certain properties> It is a stack property (the menuBar) that makes these grouped buttons act like a menu. You likely already know this.
Anyway, what you have started out to do should work fine. What are you seeing?
Craig Newman
The menuBuilder seems like a great tool, and it is. But it also is haunted.
Buttons are containers, and there is nothing special, particularly, about those buttons, except for certain properties> It is a stack property (the menuBar) that makes these grouped buttons act like a menu. You likely already know this.
Anyway, what you have started out to do should work fine. What are you seeing?
Craig Newman
Re: menu builder help please
Hi Craig,
Thanks for your explanation regarding menus, buttons, containers. Yes I read this in some of the other posts and articles. I've got scripts executing from my format menu, but I'm still confused on how to populate a specific menu item. The menu I am trying to populate is Format. The menu Item is Font and a submenu called Typeface (which is what I want replaced with the fonts from the system).
The code I am using seems to be erroring with a "no such object" error on line - put it into button "Typeface"
I've tried putting it in "Font|Typeface" and "Font" for the button name to no avail.
I've added a sample file of the type of structure I am using
Jalz
Thanks for your explanation regarding menus, buttons, containers. Yes I read this in some of the other posts and articles. I've got scripts executing from my format menu, but I'm still confused on how to populate a specific menu item. The menu I am trying to populate is Format. The menu Item is Font and a submenu called Typeface (which is what I want replaced with the fonts from the system).
The code I am using seems to be erroring with a "no such object" error on line - put it into button "Typeface"
I've tried putting it in "Font|Typeface" and "Font" for the button name to no avail.
I've added a sample file of the type of structure I am using
Jalz
- Attachments
-
- menutest.livecode.zip
- (3.17 KiB) Downloaded 208 times
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: menu builder help please
I think I know what you are asking.
In a new stack, use the menu builder to create a new menu. Add another menu and name it "test". Make a new field and place this into it:
In the message box:
I believe that the code section will not copy correctly. Each "space" in the indented lines is in fact a tab. You may need to reconstruct this.
If you have trouble with the formatting, take this:
Replace "X" with tab in the above text, and use that. Experiment with the tags that create submenus. Try to make three-level submenus.
Craig
In a new stack, use the menu builder to create a new menu. Add another menu and name it "test". Make a new field and place this into it:
Code: Select all
Choice1/|1
Choice2/|2
choice2a/|3
choice3/|4
Choice4/|5
Choice5/|6
Choice6/|7
Code: Select all
put fld 1 into btn "test"
If you have trouble with the formatting, take this:
Code: Select all
Choice1/|1
XChoice2/|2
Xchoice2a/|3
choice3/|4
Choice4/|5
XChoice5/|6
Choice6/|7
Craig
Re: menu builder help please
Thank you Craig,
Your instructions on new stack work bang on when I have a menu item (e.g. test). I'm trying to populate a submenu called "font", so I think all I need to get right is the button name of the submenu. How does the menu allocate names to containers that are 3 levels down. hope that makes sense?
All the best
Jalz
Your instructions on new stack work bang on when I have a menu item (e.g. test). I'm trying to populate a submenu called "font", so I think all I need to get right is the button name of the submenu. How does the menu allocate names to containers that are 3 levels down. hope that makes sense?
All the best
Jalz
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: menu builder help please
Hi.
But in any case, to load the fonts, say, you should be able to pack the "item" of interest with that list, by careful parsing of the example.
Craig
There is only one button. It is the contents of that button, set up with the tab character and the tags "/" and "|" that create the hierarchy of menuItems and subMenuItems. I will still leave this to you as homework. Play with the "test" sample.all I need to get right is the button name of the submenu.
But in any case, to load the fonts, say, you should be able to pack the "item" of interest with that list, by careful parsing of the example.
Craig
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: menu builder help please
Hi Craig
Great to see a trick to produce hierarchical menus. I get the multi-level menus but I am afraid I have failed the "homework" test and can't work out:
Kaveh
Great to see a trick to produce hierarchical menus. I get the multi-level menus but I am afraid I have failed the "homework" test and can't work out:
- what the / and | signify
- How to get the menu item that I want in the selectedtext of the button – I am getting "Option/|1" etc as the selectedText
- I can see hierarchy in a Pulldown menu button but not in an Option menu
Kaveh
Kaveh
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: menu builder help please
Hi.
There are differences between the four types of "menu" buttons, and not all of them support subMenus. The most straightforward is the pullDown. I would start there. Name it "B1"
Place the following into the text of btn "B1":
And then in the button script:
The contents of the button, which can be seen to be numbered, line by line, are denoted by the number after the "|". It is this value that matters.
Now select something from the pulldown. Note that in a hierarchal menuItem, you must select a submenu item, whereas in an "ordinary" menuItem (like "choice3") you can simply select the menuItem.
What you get back needs processing. If you select the subMenu "choice2a", you will get back "1|3". The "1" is the main menuItem, and the "3" is the line containing your actual choice. So you can, again in the button script:
Now this all can be simplified, which is another way of saying I am not sure I know what I am talking about. In that same button, load this from the message box:
and this into its script:
You get the main menuItem, a "|" and the subMenuItem. You can extract the submenuItem as before.
Now add an extra tab:
You do not get a second submenu to the menu "AA". You need those tags as set up as in the first example.
I think.
Experiment. That is what I do, and you also might look into the user guide, page 187 or so.
Craig
There are differences between the four types of "menu" buttons, and not all of them support subMenus. The most straightforward is the pullDown. I would start there. Name it "B1"
Place the following into the text of btn "B1":
Code: Select all
Choice1/|1
Choice2/|2
Choice2a/|3
Choice3/|4
Choice4/|5
Choice5/|6
Choice6/|7
Code: Select all
on menuPick pItemName
answer pItemName
end menuPick
Now select something from the pulldown. Note that in a hierarchal menuItem, you must select a submenu item, whereas in an "ordinary" menuItem (like "choice3") you can simply select the menuItem.
What you get back needs processing. If you select the subMenu "choice2a", you will get back "1|3". The "1" is the main menuItem, and the "3" is the line containing your actual choice. So you can, again in the button script:
Code: Select all
on menuPick pItemName
set the itemDel to "|"
put item 2 of pItemName into tLine
set the itemDel to "/"
answer item 1 of line tLine of me
end menuPick
Code: Select all
put "AA" & return & tab & "BB" & return & "CC" & return & "DD" into btn "btn1"
Code: Select all
on menuPick PItemName
answer pItemName
end menuPick
Now add an extra tab:
Code: Select all
put "AA" & return & tab & "BB" & tab & "XX" & return & "CC" & return & "DD" into btn "btn1"
I think.
Experiment. That is what I do, and you also might look into the user guide, page 187 or so.
Craig
-
- Livecode Opensource Backer
- Posts: 508
- Joined: Sun Dec 18, 2011 7:23 pm
- Location: London
- Contact:
Re: menu builder help please
Thanks for taking the time, Craig. I am working on another part but will come back and use your excellent text here and report back.
Kaveh