Subscribe Bookmark RSS Feed

delay script execution until user input is provided?

jmpbeginner

Community Trekker

Joined:

Sep 11, 2013

the first portion of my script prompts the user to select 'Y' and 'By' variables.  It then outputs a datatable (lets call it "dt2").

the second half of the code relies on that datatable (dt2) that was generated after the user makes the selections and clicks OK.

The problem I have is that the code continues to run once the window appears and is waiting for the user input.... so the 2nd half of the code has no datatable (dt2) to use so it doesn't output anything...

i saw i can use wait( ), but this relies on a time value(in seconds), and I would like to script this so it doesnt continue until the user input is given in the first half of the code (thus generating the necessary datatable for the 2nd half of the code to execute).

thanks in advance for any help/advice!!

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz

Super User

Joined:

Jun 23, 2011

Solution

If you're using new window to collect user input, make it a modal dialog box with << modal

mywin = new window("Sample Modal Dialog Box", << modal,

      text box("This is a modal dialog box"),

      button box("OK", which_button = "OK"),

      button box("Cancel", which_button = "Cancel"),

);

print("User clicked " || which_button);

6 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

Solution

If you're using new window to collect user input, make it a modal dialog box with << modal

mywin = new window("Sample Modal Dialog Box", << modal,

      text box("This is a modal dialog box"),

      button box("OK", which_button = "OK"),

      button box("Cancel", which_button = "Cancel"),

);

print("User clicked " || which_button);

misha782

Community Trekker

Joined:

Feb 3, 2014

Im doing sometion similar and suffer from the same issue.

The modal window was my initial solution as well.. Unfortunatelly it dosent work.
When the new window openes it prevents access to the data tables (it remains on top):

4844_Untitled.gif

Is there a way to bypass the on-top default of the modal window?
Or a better idea fo implementation?

THnaks in advance.

ms

Super User

Joined:

Jun 23, 2011

I don't think you can bypass a modal dialog. But you can let user enter the limits in the modal window which are transferred to the datatable when clicking OK.

Here's an example:

dt = New Table( "test", New Column( "data", numeric ) );

New Window( "Set limits",

  <<modal,

  Table Box( String Col Box( "", {"Avg", "LCL", "UCL"} ), ncb = Number Col Edit Box( "Limits", [., ., .] ) ),

  Button Box( "OK",

  L = ncb << get;

  Eval(

  Eval Expr(

  Column( dt, "data" ) << set property( "Control Limits", {Xbar( Avg( Expr( L[1] ) ),  LCL( Expr(L[2] ) ), UCL( Expr(L[3] )) )})))

  )

);

// Check if it worked

Show( L );

dt:data << Get Property( "Control Limits" );



misha782

Community Trekker

Joined:

Feb 3, 2014

Thanks for you'r reply.

In fact this was very useful for another problem Im having, and I intend to
try you'r solution for getting data from user to solve it.

In this particular case the user will most probably have to insert a LOT of
data and the idea is he should paste it to the DT.

Currently my solution is running the scripts in 2 parts:

     1. All actions needed before user is prompted to insert data

          (data is pasted into the DT)

     2. All actions needed after data is inserted.

But we both understand this is no way to work, neither can I ask the user to
insert all the data manually it's too time consuming and inefficient.

Do you have any other ideas?

Thnaks,

Misha

ms

Super User

Joined:

Jun 23, 2011

If the data to be pasted are from within JMP, or can be opened as a table by JMP, the insertion into the data table could be scripted too.

But for your scenario, if manual interaction is inevitable because of some subjective decision has to made, I'd use a non-modal window with a "start" and a "finish" (or similar) button that competes the actions in 1 and 2, respectively.

pmroz

Super User

Joined:

Jun 23, 2011

There are a couple of ways to control non-modal windows behavior:

1. Put the tasks that you want the OK button to accomplish into an expression earlier in the code.  Then, when the user clicks OK just provide the expression.

ok_expr = expr(

    user_input = user_teb << get text();

    print("User entered " || user_input);

    mywin << close window;

);

user_input = "";

mywin = new window("Get User Input",

    hlistbox(

        text box("Enter some text: "),

        user_teb = text edit box(),

    ),

    button box("OK", ok_expr),

    button box("Cancel", mywin << close window;),

);

2. Put the OK tasks into a separate JSL file and use the include() statement to run the desired commands:

// ok_commands.jsl

    user_input = user_teb << get text();

    print("User entered " || user_input);

    mywin << close window;

// Here are the dialog box commands, in a separate file

user_input = "";

mywin = new window("Get User Input",

    hlistbox(

        text box("Enter some text: "),

        user_teb = text edit box(),

    ),

    button box("OK", include("ok_commands.jsl");),

    button box("Cancel", mywin << close window;),

);