[Open] Add default parameter to PopupMenu Command

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

[Open] Add default parameter to PopupMenu Command

Post by jpuziano » Wed Jan 07, 2015 6:57 pm

Hi Marcus and everyone,

The PopupMenu> command is handy, here's what we have now...
Existing Command wrote:PopupMenu>X,Y,ItemList,result

Creates and displays a simple pop up menu at the specified X,Y position and returns the index of the item selected by the user.

X and Y take a screen X,Y position
ItemList is a semi-colon delimited list of captions
result is the return value and will contain the zero based index of the item the user selected
Besides using the mouse, the user can hit the Down arrow key to select the first menu item, again for the second and so on... and then hit the Enter key to register their choice.

Sometimes I'd like to pre-select the default because in certain situations it is highly predictable what choice they will make however I have no way to do that.

Now if someone can MacGyver up a way to accomplish this, that would be fantastic and appreciated... however I propose the simple addition of an optional default parameter as shown below...
Proposed enhancement wrote:PopupMenu>X,Y,ItemList,result[,default]

Creates and displays a simple pop up menu at the specified X,Y position and returns the index of the item selected by the user.

X and Y take a screen X,Y position
ItemList is a semi-colon delimited list of captions
result is the return value and will contain the zero based index of the item the user selected
default is an optional parameter and allows you to pre-select one of the menu items via it's zero based index
If anyone else would find this useful, please chime right in... :)
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: [Open] Add default parameter to PopupMenu Command

Post by JRL » Wed Jan 07, 2015 7:43 pm

May need to adjust wait time but this works for me.

Code: Select all

Let>ScrollDownFile=%Temp_Dir%ScrollDown.scp

DeleteFile>ScrollDownFile

/*
Data:
Wait>0.01
Press down * 3
*/

LabelToVar>Data,res
WriteLn>ScrollDownFile,wres,res

RunProgram>%command_Line% %ScrollDownFile%

Let>ItemList=1;2;3;4;5;6

PopupMenu>100,100,ItemList,result

DeleteFile>ScrollDownFile

**BREAKPOINT**

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Re: [Open] Add default parameter to PopupMenu Command

Post by jpuziano » Thu Jan 08, 2015 1:20 am

That works for me as well... and I'll use it until (if and when) the parameter get added.

Thanks JRL, much appreciated!
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: [Open] Add default parameter to PopupMenu Command

Post by JRL » Thu Jan 08, 2015 3:48 pm

I discovered that the reliability of the placement of the "Press down" function to act on the popup menu is uncertain when the menu is not called via a Macro Scheduler dialog. In other words, if one creates a script using the code I posted above, opens Windows Explorer and double clicks on the script: The popup menu will open, then the press downs will occur in the Windows Explorer window rather than on the popup menu. So this script includes a dialog. There is a "Menu" button in the dialog and when the menu button is pressed, the popup menu will open with the specified menu item selected.

This new script is designed to work and execute its dynamic script whether the script is run from the editor, the main menu, from Windows Explorer or as an executable.



Code: Select all

///////////////////////////// Start /////////////////////////////
Let>ScrollDownFile=%Temp_Dir%ScrollDown.scp

//"If>Script" test determines whether or not an executable is being used.
//This test should alway be located at the beginning of the script.
If>Script={"Script"}
Dialog>Dialog1
object Dialog1: TForm
  BorderIcons = [biSystemMenu]
  Caption = 'Give Me a Menu'
  object MSButton1: tMSButton
    Left = 191
    Top = 114
    Width = 75
    Height = 25
    Caption = 'Menu'
    Default = True
  end
end
EndDialog>Dialog1
  AddDialogHandler>Dialog1,MSButton1,OnClick,Process
Show>Dialog1,
Else
  //If the executable is being used to run the dynamic script, we only run these two lines
  Include>ScrollDownFile
  Exit>0
EndIf
////////////////////////////// End //////////////////////////////



SRT>Process
  //Delete in case the dynamic script file already exists
  DeleteFile>ScrollDownFile

//The dynamic script
//Note: The Label should not be indented as the spaces become part of the label name
/*
Data:
//Wait>0.01
Press down * 3
*/
  
  //Write the dynamic script to a file
  LabelToVar>Data,res
  WriteLn>ScrollDownFile,wres,res

  ///////////////////////////// Start /////////////////////////////
  //These 10 lines of code along with the "If>Script" test above, allows
  //a dynamic script to work from the editor, from the main menu, from
  //a double clicked script file or from a double clicked executable.
  UpperCase>Command_Line,Command_Line
  Separate>Command_Line,.EXE",~vMshedTest
  Separate>~vMshedTest_1,\,~vTest
  Let>~vMacSchedTest=~vTest_%~vTest_Count%

  If>~vMacSchedTest={"MSCHED"}
    StringReplace>~vMshedTest_1,",,~vMacSchedTest
    RunProgram>%~vMacSchedTest%.EXE %ScrollDownFile%
  Else
    RunProgram>"%Script_File%" /Script=%ScrollDownFile%
  EndIf
  ////////////////////////////// End //////////////////////////////
  
  //The popup menu
  Let>ItemList=0;1;2;3;4;5;6
  PopupMenu>100,100,ItemList,result
  
  //Delete the dynamic script after use.
  DeleteFile>ScrollDownFile
  
  //View the popup menu result as the button caption
  SetDialogProperty>Dialog1,MSButton1,Caption,result
END>Process

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts