How to 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

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

How to hide an option menu when no selection

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

As usual, I'm updating this first post with the solutions.

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. The question is how to notice that no selection was made so that the button can be hidden?

There are at various ways of closing an option menu without making a selection. Let's take all the ways I can think of, one at a time:

(1) Click on another app window. on mouseleave in the option menu script. Could also use on suspend and on suspendStack in the card script.

(2) Click somewhere else on the card. on mouseleave in the option menu script. Could also use on mouseup in the card script, and while that usually worked for me, sometimes it didn't fire.

(3) Escape key. on mouseRelease / if the keysdown = 65307... in the card script. on escapekey isn't sent when the menu is dropped. (Same for "on tabkey" as I mentioned in another thread.) on rawkeyup in the card and stack scripts doesn't fire when the menu is dropped, either.

(4) Click on title bar. on mouseLeave in the option menu script. Can't find any other messages sent in this case.

I thought of hiding the menu on idle, but I don't think I can test for whether the menu is dropped or not.
Last edited by MichaelBluejay on Wed Oct 16, 2019 4:12 pm, edited 2 times in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6456
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: 5220
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: 168
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: 6456
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: 6456
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: 6456
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

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

Re: How to hide an option menu when no selection

Post by MichaelBluejay » Wed Oct 16, 2019 4:14 pm

Code: Select all

on mouseRelease
   if the mouseLoc is within the rect of me and the keysDown = 65307 then answer "escapeKey pressed!"
end  mouseRelease
That's a great idea. I don't know why you'd limit the mouseloc, though. If you remove the mouseloc test then it traps the Escape key no matter where the mouse is. So, with this addition, there is now a solution for each of the four cases. I updated the initial post accordingly.

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

Re: How to hide an option menu when no selection

Post by jacque » Wed Oct 16, 2019 5:02 pm

MouseRelease should never be sent if the mouse is within the rect of the control. I'd think the test here would always fail.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: How to hide an option menu when no selection

Post by MichaelBluejay » Wed Oct 16, 2019 5:26 pm

It worked for me, when mouse was within rect of control.

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

Re: How to hide an option menu when no selection

Post by jacque » Wed Oct 16, 2019 6:53 pm

MichaelBluejay wrote:
Wed Oct 16, 2019 5:26 pm
It worked for me, when mouse was within rect of control.
I'm probably not picturing the setup correctly in that case.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: How to hide an option menu when no selection

Post by MichaelBluejay » Wed Oct 16, 2019 8:13 pm

You're probably picturing it correctly. The behavior surprised me too.

Option menu with this script:

Code: Select all

on mouseRelease
   if the the keysDown = 65307 then answer "escapeKey pressed!"
end  mouseRelease
1. Press mouse button on menu. (Options shown.)

2. Release button. (Choice 1 is hilited.)

3. Either move mouse off the control, or to Choice 3, or keep it on Choice 1, then press Escape. (on mouseRelease fires in all cases.)

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

Re: How to hide an option menu when no selection

Post by dunbarx » Wed Oct 16, 2019 8:44 pm

Jacque.

The optionMenu is invoked externally, with "click at the loc of btn..."

So when that happens, and the user clicks anywhere BUT within the rect of that optionMenu, mouseRelease fires. This was the intent of the OP, that the user would invoke the option, and then decide not to go there at all. Thus the "first" click is made "inside" the button, and the next click is made "outside", that is, wherever the user was when the thing opened in the first place.

Certainly if the user went inside the open menu and selected a menuItem, that message would not be sent. But then something else is in mind, and the functionality is moot.

Craig

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

Re: How to hide an option menu when no selection

Post by MichaelBluejay » Wed Oct 16, 2019 8:48 pm

Craig, I know my original post said the menu would drop programmatically, but even when I drop it with a physical click, mouseLeave fires, as I described in my previous post. Not what I expected either.

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

Re: How to hide an option menu when no selection

Post by dunbarx » Wed Oct 16, 2019 8:58 pm

Jacque.

Rereading, I now see what you are on about.

This applies only to the escapeKey. None of the other control keys do this.

Apparently, the "mouseRelease" message fires even if the cursor is within the rect, as long as the menu is open. It does not fire if closed. Does opening a menu essentially "release" the cursor? I guess so, but surely if one asks whether the mouseLoc is within the rect of the target control, one would get a "yes".

Feature or bug?

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”