Subscribe Bookmark RSS Feed

Re: How to detect if a caption box has been closed?

shaira

Contributor

Joined:

May 4, 2017

Hi!

I have a script that loops through the cells of the data and does some data processing.

To give the user an idea of what cell it is currently processing, I add this line:

Caption("Processing "||Char(i)||" out of "||Char(Nrows(dtmed))||" Cells...");

Anyway, if I close the caption, the script just proceeds to the next iteration. What I want is for the script to terminate if the user closes the caption box. Maybe there is some function that will give me the status of the caption box if it were closed?

 

Anyway, last resort is this thread:

https://community.jmp.com/t5/Discussions/Jsl-How-can-i-stop-a-script-with-a-button/td-p/6787

Although, I am apprehensive of having two windows (one caption box and one window box) just to have an escape button.

 

Thanks for the help.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ian_jmp

Staff

Joined:

Jun 23, 2011

Solution

Looks like you can't send messages to 'Caption()' to manipulate it.

Adapting what's in the other thread, you could try something like:

NamesDefaultToHere(1);

nw = NewWindow("Stop script",
	tb = TextBox("Press 'Run'... \!n"),
	bb1 = ButtonBox("Run", runScript),
	bb2 = ButtonBox("Cancel", stopFlag = 1),
);
nw << setWindowSize(150, 120);

runScript = 
Expr(
	bb1 << enable(0);
	stopFlag = 0;
	for(i=1,i<=100, i++,
		Wait(1);
		if(stopFlag,
			// Stop . . .
			nw << closeWindow;
			Print("Stopped after "||Char(i)||" seconds.");
			Stop(),
			// Else update display . . .
			tb << setText("Counted for "||Char(i)||" seconds.")
			);
	);
	nw <<closeWindow;
);
4 REPLIES
Highlighted
ian_jmp

Staff

Joined:

Jun 23, 2011

Solution

Looks like you can't send messages to 'Caption()' to manipulate it.

Adapting what's in the other thread, you could try something like:

NamesDefaultToHere(1);

nw = NewWindow("Stop script",
	tb = TextBox("Press 'Run'... \!n"),
	bb1 = ButtonBox("Run", runScript),
	bb2 = ButtonBox("Cancel", stopFlag = 1),
);
nw << setWindowSize(150, 120);

runScript = 
Expr(
	bb1 << enable(0);
	stopFlag = 0;
	for(i=1,i<=100, i++,
		Wait(1);
		if(stopFlag,
			// Stop . . .
			nw << closeWindow;
			Print("Stopped after "||Char(i)||" seconds.");
			Stop(),
			// Else update display . . .
			tb << setText("Counted for "||Char(i)||" seconds.")
			);
	);
	nw <<closeWindow;
);
shaira

Contributor

Joined:

May 4, 2017

Thanks! Let me check how I can adapt this to my current script. :)
shaira

Contributor

Joined:

May 4, 2017

@ian_jmp

I made it like this:

CheckBlock=Expr (
                  stattb<<setText("Checking input");
                  //Expressions
                 );
SplineBlock=Expr (
                  stattb<<setText("Running spline fit");
                  //Expressions
                  );

LinearBlock=Expr (
                   stattb<<setText("Running linear fit");
                    //Expressions
                  );

nw = NewWindow("Script Title",
	tb = TextBox("Click (X) icon to abort"),
	bb0 = ButtonBox("Check & Initialize", CheckBlock;),	  
	bb1 = ButtonBox("Fit Spline", SplineBlock),
	bb2 = ButtonBox("Fit Linear")", LinearBlock),
	stattb = TextBox ("");
);
nw << setWindowSize(300, 200);

Somehow, the Cancel button isn't doing its job, I think I placed it wrong within the script.

Hm, unfortunately, abnormal abort by (X) button leaves plenty of invisible data tables.

Still checking how to deal with it.

 

Thanks for the help.

ian_jmp

Staff

Joined:

Jun 23, 2011

You could consider using 'OnClose()' to do the housekeeping so long as you are keeping track of the tables:

NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
nw = NewWindow("Using 'On Close'", << onClose(onCloseBlock), TextBox("Close Me"));
onCloseBlock = 
Expr(
	Print("Closing table "||(dt << getName));
	Close(dt, NoSave);
);