Option Menu

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 219
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Option Menu

Post by chipsm » Wed May 08, 2019 5:17 pm

I would like to see if and how I can stop an option-menu from changing its value based on a variable being set without disabling the Optio Menu button.
In other words, I am setting the option-Menu value elsewhere and if the user clicks on the down arrow, i want the option-menu value to remain what it is set to until I change a variable that will allow the Option-Menu to then change via a click select.
My preference is to NOT disable the button.
Clarence Martin

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option Menu

Post by dunbarx » Thu May 09, 2019 2:38 pm

Hi.

Not sure what you mean.

You can certainly set the menuHistory of a menu-style button remotely. This has nothing to do with disabling that menu button. You can simulate, under script control, the clicking on a menu-style button as well:

Code: Select all

click at the loc of btn "yourOptionButton"
Clicking on the down arrow does nothing to such a button or its menuHistory unless you tell it to.

Please give step-by-step instructions on what you are thinking/

Craig Newman

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2395
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Option Menu

Post by jmburnod » Thu May 09, 2019 4:40 pm

Hi chipsm,
option-menu value
Do you mean "label" ?
If this is the case you may use

Code: Select all

local sMYVar = "TheSame" 
on menupick pItem
   set the label of me to sMYVar
end menupick
Best regards
Jean-Marc

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option Menu

Post by dunbarx » Thu May 09, 2019 5:50 pm

Setting the label of a menu style button will indeed display that text. But it does not change the contents of the button, so the available menuItems remains the same. It is certainly may be useful sometimes to do that.

But is that what you meant? In other words, is:
i want the option-menu value to remain what it is set to
the same as
"I want the contents of the menu button to remain unchanged, but to display some other text temporarily"
Is "value" in your statement the same as the contents of the button? It is the contents, in a return delimited list, that determines the displayable choices (the menuItems) of a menu button.

So "value" (yours) is not the contents, but the text displayed?

In that case Jean-Marc makes a point, that the visible label is possible to set even though the menuItems, and therefore the menuHistory, is unchanged.

Craig

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2395
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Option Menu

Post by jmburnod » Thu May 09, 2019 6:05 pm

Hi,
I wondered in which case we could need such feature and I remember i used this to keep label "Font" in a menu instead the name font.
Not sure that was clever but I choosed this way for one kid who couldn't accept label change.
Best
Jean-Marc

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6963
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Option Menu

Post by FourthWorld » Thu May 09, 2019 6:33 pm

Code: Select all

-- Replaces the list of options in an option button
-- while preserving the selected item, if the current
-- item is present in the new list.  Note the use of 
-- lockMessages here, needed when setting menuHistory
-- to avoid triggering a menuPick message as would 
-- normally happen when menuHistory is changed.
on SetOptionText pObj, pList
   lock screen
   put the label of pObj into tLabel
   set the text of pObj to pList
   put lineoffset(tLabel, pList) into tOffset
   lock messages
   set the menuhistory of pObj to tOffset
   unlock messages
   unlock screen 
end SetOptionText
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option Menu

Post by dunbarx » Thu May 09, 2019 9:10 pm

All good stuff.

If one wants to present a "title" in a menu button, one can:

1- set the label of the button to the title independently, the button contents reserved for "working" menuItems.

2- set the first line of the contents to the desired title, and select only the remainder. One can manage to lose that first line of the contents and restore it as needed, so it does not appear in the actual dropDown.

I like # 1.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6963
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Option Menu

Post by FourthWorld » Thu May 09, 2019 9:52 pm

The challenge with using label alone is that it doesn't update the menuHistory, so the next time the user clicks on it the menu item matching the label is not selected (or on Mac, centered the control).

Using the menuHistory property also sets the label, but with the added benefit of updating the internal record of the currently-selected item, so a subsequent click presents the menu with the hilite as expected.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6238
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option Menu

Post by dunbarx » Thu May 09, 2019 11:21 pm

Richard.

All true. Its is just a matter of how much management is required, and the benefit/hassle ratio.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6963
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Option Menu

Post by FourthWorld » Thu May 09, 2019 11:35 pm

True, but if given a handler to do it, the task becomes a short one-liner.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Talking LiveCode”