BookmarkSubscribeRSS Feed

Re: JMP window not closing

pen51

Occasional Contributor

Joined:

Jan 23, 2018

I'm working on a script that just does basic image editing. I have my image in one window, then clicking an "Image Options" window opens up a window with sliders for contrast and brightness. Whenever I close the image options window, it never actually closes, the window is just hidden. Hitting the "x" in the corner does nothing. I even added a "Close" button that just says << Close Window, but then it just hides it. In order to get it to close, I have to close JMP completely. Is there something I'm missing?

Names Default To Here( 1 );
img = Open( "$SAMPLE_IMAGES/windmap.png", "png" );
orig = New Image( img );
wind = New Image( orig );
slbval = 1;
slbval1 = 1;
w = New Window( "View Image",
	vlb = V List Box(
		Graph Box(
			FrameSize( 500, 500 ),
			X Scale( 0, 100 ),
			Y Scale( 0, 100 ),
			<<Add Image( image( wind ), bounds( top( 90 ), Left( 10 ), bottom( 10 ), Right( 90 ) ) )
		),
		Button Box( "Open options",
			options;
			optionswindowopen = 1;
		)
	)
);

refilter = Expr(
	wind << Set Pixels( orig << Get Pixels );
	wind << Filter( "Contrast", slbval );
	wind << Filter( "Gamma", slbval1 );
);
refilter;
optionswindowopen = 0;

options = Expr(
	imgop = New Window( "Image Options", 
		<<On Close(
			optionswindowopen = 0;
		),
		V List Box(
			tb = Text Box( "Contrast: " || Char( slbval ) ),
			Slider Box(
				0.01,
				15,
				slbval,
				tb << Set Text( "Contrast: " || Char( slbval ) );
				refilter;
				vlb << reshow;
			),
			tb1 = Text Box( "Brightness: " || Char( slbval1 ) ),
			Slider Box(
				0.01,
				5,
				slbval1,
				tb1 << Set Text( "Brightness: " || Char( slbval1 ) );
				refilter;
				vlb << reshow;
			),
			Button Box("Close",
				imgop << Close Window;
			)
		)
	)
);
 
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
stan_koprowski

Community Manager

Joined:

Aug 8, 2012

Solution

Hi @pen51,

The issue with the script is on line 32:

<<On Close( optionswindowopen = 0 );

 

The window will never close when set to 0.

If you change to 

<<On Close( optionswindowopen = 1 );

It closes as expected.

According to the scripting index if the << On Close() returns zero (0) the window is prevented from closing.

Screen Shot 2018-04-04 at 10.36.15 AM.png<<On Close

cheers,

Stan

Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

Solution

@stan_koprowski has pointed you in the right direction and you ask a good question and the answer points to a subtlety of JSL.

 

The key is to remember that everything in JSL is a function, even operators like = which is equivalent to the Assign() function. Since everything is a function, they all return something. The Assign() function returns the value being assigned.

 

So, because your OnClose() argument is an Assign() function that assigns 0, and because the Assign() function returns the value being assigned it returns 0, and because On Close() says that the window won't close if the function being called returns 0 the window will never close.

 

However, since everything is a function, the ; operator is actually the Glue() function. The Glue() function returns the result of it's last argument. So, you can workaround this by doing anything else in your On Close() script after the assignment, like just putting a 1.

 

So, this will work for you:

imgop = New Window( "Image Options", 
		<<On Close(
			optionswindowopen = 0;
                        1;
		),

 

-Jeff
8 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

This is very curious.....I played around with it, and could not find any consistant reason for the options window being able to be closed.  In fact, under JMP 14, my JMP session would not close.  I had to force an operating system close.

 

This needs to be sent to the JMP support folks....

     support@jmp.com

Jim
cwillden

Community Trekker

Joined:

May 1, 2017

lol, I had the same happen in JMP 13.  Thanks @pen51 for infecting our computers as well with your strange unintentional virus (j/k).

-- Cameron Willden
pen51

Occasional Contributor

Joined:

Jan 23, 2018

I've been in contact with JMP support, but the technician I talked to could not replicate the problem with the same script. I'm running JMP 13.1, @cwillden what are you running? I'll try to update and see if it works, but hopes are not high since @txnelson also had this problem in JMP 14. 

uday_guntupalli

Community Trekker

Joined:

Sep 15, 2014

@pen51,
         I tested this script on JMP 13.1.0 and had the same issue. 

Best
Uday
Highlighted
stan_koprowski

Community Manager

Joined:

Aug 8, 2012

Solution

Hi @pen51,

The issue with the script is on line 32:

<<On Close( optionswindowopen = 0 );

 

The window will never close when set to 0.

If you change to 

<<On Close( optionswindowopen = 1 );

It closes as expected.

According to the scripting index if the << On Close() returns zero (0) the window is prevented from closing.

Screen Shot 2018-04-04 at 10.36.15 AM.png<<On Close

cheers,

Stan

pen51

Occasional Contributor

Joined:

Jan 23, 2018

Hi Stan, the optionswindowopen is just a boolean to say whether or not the window is open. Since I'm closing the window, on On Close would set the boolean to 0. If the window is open, the boolean is 1. I would like to keep this boolean with this logic, so do you have a work around?

Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

Solution

@stan_koprowski has pointed you in the right direction and you ask a good question and the answer points to a subtlety of JSL.

 

The key is to remember that everything in JSL is a function, even operators like = which is equivalent to the Assign() function. Since everything is a function, they all return something. The Assign() function returns the value being assigned.

 

So, because your OnClose() argument is an Assign() function that assigns 0, and because the Assign() function returns the value being assigned it returns 0, and because On Close() says that the window won't close if the function being called returns 0 the window will never close.

 

However, since everything is a function, the ; operator is actually the Glue() function. The Glue() function returns the result of it's last argument. So, you can workaround this by doing anything else in your On Close() script after the assignment, like just putting a 1.

 

So, this will work for you:

imgop = New Window( "Image Options", 
		<<On Close(
			optionswindowopen = 0;
                        1;
		),

 

-Jeff
stan_koprowski

Community Manager

Joined:

Aug 8, 2012

Hi @pen51,

You could add 1 to the On Close argument.

<< On Close ( optionswindowopen = 0; 1)

This way it will return the result of the last argument; in this case 1.

cheers,

Stan