Can't hide an option menu when no selection

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
MichaelBluejay
Posts: 112
Joined: Thu Jul 01, 2010 11:50 am

Can't hide an option menu when no selection

Post by MichaelBluejay » Sat Oct 12, 2019 7:53 pm

In my interface, clicking a line in a field shows an option menu and drops it. When the user makes a choice from the option menu, the selected item from the menu gets inserted into the field, and then the option menu is hidden. So far so good.

But if the user doesn't make a selection from the menu, then the option menu is stuck on the screen, and can't be hidden reliably.

There are at various ways of closing an option menu without making a selection. Let's take them one at a time:

(1) Click on another app window. I put hide btn "myButton" in the on suspend and on suspendStack handlers of the card script. This works reliably.

(2) Click somewhere else on the card. I put the hide code in the card's on mouseup handler. That *usually* works, but sometimes clicks in the card window don't hide the button. I can't figure out under what circumstances the button won't hide.

(3) Escape key. onescape key is supposed to be sent to the current control, but it's not sent when the menu is dropped. (Same for "on tabkey" as I mentioned in another thread.) on escapekey and on rawkeyup in the card and stack scripts doesn't fire when the menu is dropped, either.

(4) Click on title bar. Does not appear to send any messages.

I thought of hiding the menu on idle, but I don't think I can test for whether the menu is dropped or not.

So, unless anyone has any magic ideas (*cough* *klaus* *cough*), it seems I won't always be able to hide the option menu when nothing is chosen.
Last edited by MichaelBluejay on Sun Oct 13, 2019 4:53 pm, edited 1 time in total.

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

Re: Can't hide an option menu when no selection

Post by dunbarx » Sun Oct 13, 2019 3:38 pm

Michael.

You are going to be so much fun to have around.

Try this. On a new card make an option menu and a field. Put a few lines in the field and then lock it. In the field script:

Code: Select all

on mouseUp
   show btn 1 ; click at the loc of btn 1
end mouseUp
In the button script;

Code: Select all

on mouseLeave
   hide me
end mouseLeave
Click on any line in the field, as you said. Now click anywhere but within that option menu, including back in the field itself. See?

You can add a "menuPick" handler to the optionMenu to do something useful before it disappears forever.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5104
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Can't hide an option menu when no selection

Post by jacque » Sun Oct 13, 2019 4:17 pm

In the handler that displays the menu you can add a line that sends the command to hide it in a couple of seconds. See the "send" command in the dictionary. Use the "in <time>" option.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

MichaelBluejay
Posts: 112
Joined: Thu Jul 01, 2010 11:50 am

Re: Can't hide an option menu when no selection

Post by MichaelBluejay » Sun Oct 13, 2019 5:05 pm

dunbarx, on mouseleave is a good idea, and it solves most of the conditions, but not condition #3 (Escape key).

jacque, as I mentioned, the problem with a time-based method of hiding the menu is there's no way to test whether the user has the menu open or not.

In the meantime, I've made some fields that work like option menus, so that's my solution. They're superior to option menus in lots of ways: they respond to Tab, they respond to escape, I can set the background color of certain lines, and my interface can use a single field instead than an option menu + field combo.

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

Re: Can't hide an option menu when no selection

Post by dunbarx » Sun Oct 13, 2019 5:42 pm

Michael.

You are learning there is a slippery slope between being clever and making kluges. You tell me:

In the script of the optionMenu button:

Code: Select all

on mouseRelease
if the mouseLoc is within the rect of me and the keysDown = 65307 then answer "escapeKey pressed!"
end  mouseRelease
So, kluge or cleverness?

Craig

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

Re: Can't hide an option menu when no selection

Post by dunbarx » Sun Oct 13, 2019 5:48 pm

Michael.

You will have a much easier time when you learn just a little more vocabulary. Like learning any new language, this takes time and practice. To a point you made earlier, it is hard to know, unless you have a bunch of hours under your belt, where to look in the dictionary. So now every time you do go there, make sure you read ALL of the "related items". Oftentimes when you are searching a word that seems to be pertinent to your needs, you may not find the solution exactly in the place you are looking, but will find it in those related items.

You may need to go and test those one by one, but soon you will find that method produces gold.

Craig

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

Re: Can't hide an option menu when no selection

Post by dunbarx » Sun Oct 13, 2019 5:52 pm

In the meantime, I've made some fields that work like option menus, so that's my solution...
Yes rolling your own, as we like to say (after all, most of us are old, old...) allows one to make tools that have functionality far beyond the native set. If that were not possible, much of the beauty of LC would be lost.

Fortunately, just the opposite. I have made entire stacks that substitute for "deficiencies" in certain single controls.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”