Help with pop-up menu/choice button, please.
Dennis Brown
see3d at writeme.com
Fri Jul 29 16:14:57 EDT 2005
Alex,
I wanted the same sort of thing. What I decided was the best
solution was to use a field instead of a button. I have just one
"PopUp Menu" button that I load with the list and pop it up at the
location of the field. Since everything is under the control of my
PopUpParams script below, I could check for the contents of the
choices and just skip the popup part if only one choice existed. I
have not edited my script for your example, because you could do a
better job of that than I could. I am sure you could modify it to
work with buttons also.
Dennis
ON PopUpParams fieldParams1 --set a parameter field to the user
selection
local selected1,it
--fieldParams1 is a param list formatted as returned in
ScreenParams() above
--a popup menu is displayed on top of the field clicked on by
the user
-- a single popup button is used for everything by changing its
menus
--the selected entry is then placed into the field and saved in
the set properties of the field
--USAGE:
--called from a mouseDown handler in a locked field: PopUpParams
priceParams(1)
--
#1 create the text for the popup menu btn
--
REPEAT for each line line1 in fieldParams1
put item 1 of line1 &cr after it
END repeat
set the text of btn "PopUp Menu" to it
#2 put the selection into the field
set the menuHistory of btn "PopUp Menu" to 2 --blank line, no
change
popup button "PopUp Menu" at bottomLeft of the target
get the menuHistory of btn "PopUp Menu"
put line it of fieldParams1 into selected1
replace comma with cr in selected1
IF (selected1 <> empty) AND (selected1 <> the text of the
target) AND (it<>2)
THEN --changing settings
put selected1 into the target
get the short name of the target --e.g. SL5
put "F" into char 2 of it --e.g. SF5
IF exists( fld it )
THEN --set the default value into the input field
put line 6 of selected1 into fld it
set the dataP[SetNum()] of fld it to fld it
END if
--
IF line 7 of selected1 is not empty --color the text
THEN set the textColor of the target to item (line 7 of
selected1) of colorListK
IF line 8 of selected1 is not empty
THEN set the backColor of the target to item (line 8 of
selected1) of colorListK
--
#3 save as current setting and pW[]
set the dataP[SetNum()] of the target to selected1
END if
UpdateParams
END PopUpParams
FUNCTION PriceParams option1 --returns the parameters for all
selected execution prices in the UI
--option1 is an optional parameter which specifies additional
sets of options are to be returned
--if it is empty, the screens to be returned will be based on
the indicator type function
--USAGE:
--The user can select different execution prices in the list for
initial and ending trades
--The selected price name and the next items will be loaded into
the field in separate lines
--Only the first line will be visible, but all the other
parameters will be saved as part of the set:
--
Name,Screen#,MinValue,MaxValue,Decimals,Default,textcolor#,bkgColor#
-- Price# identifies the option for switch cases, global array
index, and priceList1.
-- MinValue,MaxValue is for input checking
-- Decimals is for formatting the field
-- Default value for input field
-- textColor#,bkgColor# is index into a list of colors
--
local list1
get "Select Exe Price,0,0,0,0,,3,0,"&cr&cr
IF AlgorType()&option1 is among the items of
"1100,1101,1110,1111,1990,1991" --all indicator types
THEN put "510,511,512,513,514,515,516,517" into list1 --all
execution prices (start trade)
IF AlgorType()&option1 is among the items of
"11001,11011,11101,11111,19901,19911" --all indicator types+stop
THEN put "510,513,516,517" into list1 --execuution prices for
stop trade
--
IF 510 is among the items of list1 THEN get it&"D1Typ +,510,-.
50,.50,2,0,2,1," &cr --Use Typ tomarrow
IF 511 is among the items of list1 THEN get it&"D0Typ +,511,-.
50,.50,2,0,2,1," &cr --Use Typ today
IF 512 is among the items of list1 THEN get it&"IF D0Typ +,512,-.
50,.50,2,0,2,1," &cr --Use Typ today IF avail tomarrow
IF 513 is among the items of list1 THEN get it&"IF D0Typ!D1C +,
513,-.50,.50,2,0,2,1," &cr --Use Typ today IF avail tomarrow else close
IF 514 is among the items of list1 THEN get it&"D0Close +,514,-.
50,.50,2,0,2,1," &cr --Use close today
IF 515 is among the items of list1 THEN get it&"IF D0Close +,
515,-.50,.50,2,0,2,1," &cr --Use close today IF avail tomarrow
IF 516 is among the items of list1 THEN get it&"IF D0Close!D1C +,
516,-.50,.50,2,0,2,1," &cr --Use close today IF avail tomarrow else
close
IF 517 is among the items of list1 THEN get it&"D1Open +,517,-.
50,.50,2,0,2,1," &cr --Use open tomarrow
return it
END PriceParams
On Jul 29, 2005, at 1:56 PM, Alex Tweedly wrote:
>
> This cannot be as hard as I'm making it ..... so I'll follow the
> excellent advice from the list of not struggling over a simple
> issue for more than an hour and ask for help. Though I am about
> 4 hours late .... :-(
>
> Easy bit:
> I want to have a button, that acts like a pop-up button - i.e. when
> I click on it, up pops a list of choices and I can select one - or
> I can click outside the list of options and get a "cancel"
> indication back. When a choice is made, I do the appropriate action.
> This is what I get with a "pop-up menu" selected from the IDE's
> tool palette.
>
> Hard part:
> Sometimes, there is only one valid choice; in that case, I'd like
> to go ahead with the appropriate action immediately - don't present
> a menu, just do the action.
>
> I can put in a handler for the mouseDown to the pop-up button - but
> can't find a way to avoid it popping up.
>
> I tried putting in another button, and having its mouseDown take
> the action - either just doing it, or sending mouseDown to the pop-
> up button - but apparently; sending a mouseDown isn't enough to
> trigger the pop-up.
>
> (I tried a large number of other things, but I'm not going to
> embarrass myself by listing them all ....)
>
> Am I just missing some easy way ?
>
> --
> Alex Tweedly http://www.tweedly.net
>
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.338 / Virus Database: 267.9.6/59 - Release Date:
> 27/07/2005
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list