Page 1 of 2

How to select menuitem by script ?

Posted: Sun Oct 18, 2020 5:20 pm
by jmburnod
Hi All,
I try to select a menuitem of a popup btn "bMyPopUp" by script
I discover that i can navigate among line of the menu with arrowkeys up and down.
Is there a way to do that by script ?

I tried this (comment lines doesn't work)

Code: Select all

... 
click at the loc of btn "bMyPopUp"
send "arrowkey down" to this stack
select item 2 of btn "bMyPopUp"
set the menuhistory of btn "bMyPopUp" to 2
--select menuitem 2 of btn "bMyPopUp"
--arrowkey down
--set the hilite of menuitem 2 of btn "bMyPopUp" to true
...
Best regards
Jean-Marc

Re: How to select menuitem by script ?

Posted: Sun Oct 18, 2020 6:12 pm
by FourthWorld
I don't believe it's possible to emulate the visual appearance of a sort of "ghost user" manipulating menu objects.

But you can trigger the script of any menu by dispatching a call to the menuPick handler with the name of the menu item:

Code: Select all

dispatch "menuPick" to btn "Edit" of stack "revMenubar" with "Preferences"

Re: How to select menuitem by script ?

Posted: Sun Oct 18, 2020 6:21 pm
by richmond62
FourthWorld wrote:
Sun Oct 18, 2020 6:12 pm
I don't believe it's possible to emulate the visual appearance of a sort of "ghost user" manipulating menu objects.
It might be by making a video of a real user manipulating menus and overlaying it on a stack so that it
plays while real menus fire.

Re: How to select menuitem by script ?

Posted: Sun Oct 18, 2020 9:44 pm
by dunbarx
Jean-Marc.

We have played around with the kludge where under script control you click at the loc of a menu-style button to show the menuItems. But what do you then want the handler to do once that list is visible? Select successive menuItems in turn and have the user "select" one? Would it cycle back to the top if nothing was selected?

Craig

Re: How to select menuitem by script ?

Posted: Sun Oct 18, 2020 10:28 pm
by jmburnod
Craig,
Select successive menuItems in turn and have the user "select" one? Would it cycle back to the top if nothing was selected?s fire.
Yes for fun but mainly i want to select a menuitem once the list is visible.
Jean-Marc

Re: How to select menuitem by script ?

Posted: Mon Oct 19, 2020 3:29 am
by dunbarx
Jean-Marc.

Ah. Fun.

So I made two buttons, a pullDown named "B1" and another ordinary button. In the script of the ordinary button:

Code: Select all

on mouseUp
   put item 1 of the loc of btn "B1" into x
   put item 2 of the loc of btn "B1" into v
   answer"Select what?" with "Choice 1" or "Choice 2" or "Choice 3"
   click at the loc of btn "B1"
   switch it
      case "Choice 1"
         click at x & "," & v + 20
         break
      case "Choice 2"
         answer "Choice 2"
         break
      case "Choice 3"
         click at x & "," & v + 60
         break
   end switch
end mouseUp
As expected, the handler opens the menuItems of the pulldown, but that seems to be a blocking condition. Everything stops; no messages are generated with any mouse action. The handler is halted just before the "switch" statement.

If I select "Choice 2" by hand, I get the answer dialog. If I select "Choice 1" by hand, nothing happens, because the menuItem list apparently has already been dismissed, and I am merely clicking on the card. It seems the handler "freezes" until a menuItem is manually clicked, or one clicks somewhere else entirely. At that point the handler continues. So this method does not work.

Craig

Re: How to select menuitem by script ?

Posted: Mon Oct 19, 2020 3:39 am
by dunbarx
To all.

Is this known and desirable behavior, that, similar to an answer dialog, a currently displayed menuItem list is blocking? Is this an advantage? It does prevent the kludge from working.

Is it an OS thing?
Craig

Re: How to select menuitem by script ?

Posted: Mon Oct 19, 2020 9:31 am
by jmburnod
Thanks all for advices
similar to an answer dialog
You're right,
If i put a breakpoint after " click at the loc..." then script editor doesnt open. Same result with dispatch
I used a workaround with a fld. It works but I hoped find an simpler way (for example i need to add a line "Cancel").

There is probabily good reasons to not allow what i try to do (maybe cancel is one).

Richmond:
Video is not an option for me for the same reasons about our "answer dialog" discuss.
Kind regards
Jean-Marc

Re: How to select menuitem by script ?

Posted: Mon Oct 19, 2020 2:41 pm
by dunbarx
Jean-Marc.
I used a workaround with a fld.
You mean you rolled your own, not using a menu-style button at all? Less convenient, but now you are fully in control.

Craig

Re: How to select menuitem by script ?

Posted: Tue Oct 20, 2020 2:40 am
by mwieder
Craig-

You're almost there. This will do the trick, although it won't highlight the selected line.

Code: Select all

on mouseUp
   local x, v, tChoice
   put item 1 of the loc of btn "B1" into x
   put item 2 of the loc of btn "B1" into v
   answer"Select what?" with "Choice 1" or "Choice 2" or "Choice 3"
   put it into tChoice
   send "unclick" to me in 1 second
   click at the loc of btn "B1"
   switch tChoice
      case "Choice 1"
         put "Choice 1" into msg
         break
      case "Choice 2"
         put "Choice 2" into msg
         break
      case "Choice 3"
         put "Choice 3" into msg
         break
   end switch
end mouseUp

on unclick
   click at the loc of btn "B1"
end unclick

Re: How to select menuitem by script ?

Posted: Tue Oct 20, 2020 3:29 am
by dunbarx
Mark.

Hi.

Your handler opens the menu button like mine, but then, like mine, nothing else happens. The handler stops as before; the switch line never fires.

What are you seeing?

Anyway, if a menu-style button is blocking when its menuItem list is displayed, then I think you have to roll your own, using a few other controls that together look like a pullDown, say, but do not block anything. I don't think one aspect of this would be hard to implement, that the user must essentially be prevented from doing anything at all besides either selecting a "menuItem", or clicking somewhere else that does nothing and closes the "menuItem list"

One might call this restriction a "soft" block. :wink:

Craig

Re: How to select menuitem by script ?

Posted: Tue Oct 20, 2020 5:21 am
by FourthWorld
dunbarx wrote:
Mon Oct 19, 2020 3:39 am
Is this known and desirable behavior, that, similar to an answer dialog, a currently displayed menuItem list is blocking?
Remember the olden days when menus required holding the mouse button down the whole time?

I suspect what we see today is an offshoot of that, perhaps never augmented with message support because it's so rarely needed.

Re: How to select menuitem by script ?

Posted: Tue Oct 20, 2020 8:57 am
by mwieder
Craig-

it depends on what type of menu you're using.
What I wrote there works with a pulldown menu.
The generic case for options and comboboxes as well is more complicated.

Re: How to select menuitem by script ?

Posted: Tue Oct 20, 2020 1:39 pm
by jmburnod
Thanks All
I was not clear in my first post and title of topic.
I said "select menuitem" but "hilite menuitem" is a better describe.
Here is a stack with work around I use.
demoCustomMenu.zip
(1.91 KiB) Downloaded 45 times
Jean-Marc

Re: How to select menuitem by script ?

Posted: Tue Oct 20, 2020 2:23 pm
by dunbarx
Mark.
What I wrote there works with a pulldown menu.
I always worked with a pulldown. Your offering opens the menuItem list, and then stops.

What Jean-Marc wanted was, I think:
1- Invoke the handler by, say, clicking on a button.
2- Have the user select an option from the answer dialog.
3- Have the menuItem list open from the pulldown. We have this down solid.
4- Hilite the menuItem the user selected in "2" above.

I have yet to see what Jean-Marc has done with the stack he made. Lets both check it out.

Craig