Page 1 of 1

Scripting - popupmenu (bug(s))

Posted: 02 Nov 2011 23:38
by highend
It seems, coordinates aren't working correctly (except from x=-1, x=-2 -> cursor).

This one is working fine and shows the menu at the cursor postion:

Code: Select all

popupmenu(<get selecteditemspathnames |>, x=-1, y=-1);
This one should display the menu at x=300, y=500 but it's in the top left
corner of the screen.

Code: Select all

popupmenu(<get selecteditemspathnames |>, x=300, y=500);

Re: Scripting - popupmenu (bug(s))

Posted: 03 Nov 2011 09:23
by admin
Wrong syntax; you confused my way to show the default values with the parameters themselves. This is the way to do it:

Code: Select all

popupmenu(<get selecteditemspathnames |>, 300, 500);

Re: Scripting - popupmenu (bug(s))

Posted: 03 Nov 2011 21:11
by Stefan

Code: Select all

v10.50.0007 - 2011-11-02 19:40
    + Scripting got a new function.
      Name:   PopupMenu
      Action: Pops a menu and returns the selected item.
      Syntax: popupmenu(itemlist, [x=-1], [y=-1], [start=1], [count=-1], [flags=0], [sep_itemlist="|"], [sep_item=";"], [on_cancel=""])
        itemlist: List of items separated by sep_itemlist.
                Each item is made of a Caption and optionally a Data part, separated by sep_item: "Caption;Data"
        x:            X position; -1 to use current mouse X.
        y:            Y position; -1 to use current mouse Y.
        start:        Index of first item to show; 1 = first item.
        count:        Count of items to show; -1 = show all.
        flags:         1: Return index (instead of caption/data).
        sep_itemlist: Separates items; can have more than one char.
        sep_item:     Separates caption from data; can have more than one char.
        on_cancel:    String returned when menu is cancelled (ESC).
        return:       Data of selected item; caption if no data defined; index if flags AND 1.
      Examples:
        text popupmenu("a|-|b|c");  //- is a menu separator
        text popupmenu("a;data returned on a|-|b;data b|c;data c");
        text popupmenu(<get selecteditemspathnames |>);

Test

Code: Select all

  $a = "Execute with option x Xy XXyy";
  $b = "Execute with option K VbDFccs";
  $c = "Execute with option G BjfdUpa";
  
  //popupmenu(itemlist, x, y, start, count, flags, sep_itemlist, sep_item, [on_cancel=""])
  $r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,1,,,"nix");

  msg "You have chosen item no: $r";

  if ($r==3){msg "OK, executing sub A.";}
  if ($r==4){msg "You want sub B? OK.";}
  if ($r==5){msg "...exec sub C.";}
  if ("$r"=="nix"){msg "nothing chosen. ESC pressed or wrong clicked.";}




Problem:
on_cancel: pressing ESC-key while the dialog is visible result in nothing: // "You have chosen item no: "
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,1,,,"nix");

And so this are not executed too:
if ("$r"=="nix"){msg "nothing chosen. ESC pressed.";}
if ($r=="nix"){msg "nothing chosen. ESC pressed.";}

Or:
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,1,,,0);
if ($r==0){msg "nothing chosen. ESC pressed.";}

Only this works:
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,1,,,"");
$r = popupmenu("Choose what to execute:| |$a|$b|$c|-|Cancel",-1,-1,,,1,,);
if ($r==""){msg "nothing choosen. ESC pressed.";}



Idea:
- missing center option for X and Y: x="", y="" ==> center dialog.
Currently x="", y="" is the same as x=-1, y=-1

Re: Scripting - popupmenu (bug(s))

Posted: 07 Nov 2011 11:27
by admin
I cannot see a problem with on_cancel. :?

Centering the menu: Use <get screen width> and <get screen height> plus a little math. :wink: