Page 1 of 1
Option Menu
Posted: Wed May 08, 2019 5:17 pm
by chipsm
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.
Re: Option Menu
Posted: Thu May 09, 2019 2:38 pm
by dunbarx
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
Re: Option Menu
Posted: Thu May 09, 2019 4:40 pm
by jmburnod
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
Re: Option Menu
Posted: Thu May 09, 2019 5:50 pm
by dunbarx
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
Re: Option Menu
Posted: Thu May 09, 2019 6:05 pm
by jmburnod
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
Re: Option Menu
Posted: Thu May 09, 2019 6:33 pm
by FourthWorld
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
Re: Option Menu
Posted: Thu May 09, 2019 9:10 pm
by dunbarx
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
Re: Option Menu
Posted: Thu May 09, 2019 9:52 pm
by FourthWorld
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.
Re: Option Menu
Posted: Thu May 09, 2019 11:21 pm
by dunbarx
Richard.
All true. Its is just a matter of how much management is required, and the benefit/hassle ratio.
Craig
Re: Option Menu
Posted: Thu May 09, 2019 11:35 pm
by FourthWorld
True, but if given a handler to do it, the task becomes a short one-liner.