cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
mtowle419
Level II

Variable number of GraphBoxes. How can I identify which GB I'm sending clicks to?

nw = new window("graphs", vlb = v list box());
dirname = "jpegs";
set default directory(dirname);
foreach({jpeg}, files in directory(dirname), // dexter.jpg, samurai_jack.jpg, spongebob.jpg
	img = new image(jpeg);
	msg = eval insert("\!"^jpeg^\!""); 
	h = graphbox(
			<<Add Image(
				image( img ),
				bounds( top( 90 ), Left( 10 ), Bottom( 10 ), Right( 90 ) )
			),
			mouse trap(
				
				statusmsg( msg )
			)

	);
	vlb<<append( h )
	
)

The above gives me

  • 3 graphboxes
  • with three correctly rendered images,
  • but StatusMsg always sends "Spongebob.jpg". (Without the evalinsert(), just sending jpeg to StatusMsg, it throws an error.)

I want StatusMsg to give me the name of the image whose graphbox I clicked on. 

 

Basically, I can kinda sorta imagine two routes:

1. Eval and related functions? I still haven't dug into that side of JSL very deeply.

2. Xpath? Maybe log the image name in a List; index will correspond with the frame box number.

 

 

3 ACCEPTED SOLUTIONS

Accepted Solutions
hogi
Level XII

Re: Variable number of GraphBoxes. How can I identify which GB I'm sending clicks to?

Whenever a user clicks on an image, mousetrap gets the order to call 

statusmsg( variablename)

So: it will execute statusmsg( variablename), check for the current content of variablename and display it in the status bar.

 

As you noticed and tried to:
You have to force the variable to be evaluated somehow before using it in the expression.

The issue:
storing the result in another variable (msg) leaves you with the same issue - just another variable name.

 

What you want to do: 

For every image pre-evaluate the image name and trigger e.g.

statusmsg("samurai_jack.jpg")

In 90% of the cases, this pre-evaluation can be done via Eval(Eval Expr()).

For the remaining ones, use Eval(Substitute())

Expression Handling in JMP: Tipps and Trapdoors 

 

Eval (Eval Expr( h=graphbox(
			<<Add Image(
				image( img ),
				bounds( top( 90 ), Left( 10 ), Bottom( 10 ), Right( 90 ) )
			),
			mouse trap(	
				statusmsg( Expr(jpeg) )
			)

	)));

 

View solution in original post

mtowle419
Level II

Re: Variable number of GraphBoxes. How can I identify which GB I'm sending clicks to?

Lol I figured it out

 

foreach({jpeg}, files in directory(jpegs),
	img = new image(jpeg);

	h = Eval(
		Eval Expr(
			graphbox(
				<<Add Image(
					image( img ),
					bounds( top( 90 ), Left( 10 ), Bottom( 10 ), Right( 90 ) )
				),
				mouse trap(
					statusmsg( expr(jpeg) )
				)
			);
		)
	);
	vlb<<append( h )
)

It's not clear to me why `jpeg` needs the expr() and `img` doesn't, though. Both of those vars are 'born' on a per-loop basis

View solution in original post

hogi
Level XII

Re: Variable number of GraphBoxes. How can I identify which GB I'm sending clicks to?

yes ,this is a quite an issue in JSL. Unfortunately, there is no documentation which arguments get evaluated - and which arguments just  get "transferred".And sometimes it's not at all easy to find out:

Does Head evaluate its argument? 

 

I asked JMP support for an official list of functions which evaluate / don't evaluate their argument. Unfortunately, there no such list.
Another approach: use some Advanced syntax highlighting in JSL Editor - does the function evaluate it's argument? 

I hope, it will get implemented with some of the next releases ....

 

Actually, many(!!!) functions in JSL don't evaluate (some of) their arguments before using them.
This approach is extremely powerful!

 

The most prominent example of "just transferred": 

New column (.... Formula(Expression gets just transferred))

 

The same holds for Mouse Trap.
If you think about it again - it's very kind by JMP that it doesn't evaluate the argument : )
You want to change the status message whenever the user clicks on the image - not at the moment when you execute the code.

 

On the other hand: to add the image to the Window, JMP has to open the image file - and to do so: look into the variable.
NB: Sometimes, it helps to replace an argument with Eval(argument).
Sometimes.
Here: no.

View solution in original post

3 REPLIES 3
hogi
Level XII

Re: Variable number of GraphBoxes. How can I identify which GB I'm sending clicks to?

Whenever a user clicks on an image, mousetrap gets the order to call 

statusmsg( variablename)

So: it will execute statusmsg( variablename), check for the current content of variablename and display it in the status bar.

 

As you noticed and tried to:
You have to force the variable to be evaluated somehow before using it in the expression.

The issue:
storing the result in another variable (msg) leaves you with the same issue - just another variable name.

 

What you want to do: 

For every image pre-evaluate the image name and trigger e.g.

statusmsg("samurai_jack.jpg")

In 90% of the cases, this pre-evaluation can be done via Eval(Eval Expr()).

For the remaining ones, use Eval(Substitute())

Expression Handling in JMP: Tipps and Trapdoors 

 

Eval (Eval Expr( h=graphbox(
			<<Add Image(
				image( img ),
				bounds( top( 90 ), Left( 10 ), Bottom( 10 ), Right( 90 ) )
			),
			mouse trap(	
				statusmsg( Expr(jpeg) )
			)

	)));

 

mtowle419
Level II

Re: Variable number of GraphBoxes. How can I identify which GB I'm sending clicks to?

Lol I figured it out

 

foreach({jpeg}, files in directory(jpegs),
	img = new image(jpeg);

	h = Eval(
		Eval Expr(
			graphbox(
				<<Add Image(
					image( img ),
					bounds( top( 90 ), Left( 10 ), Bottom( 10 ), Right( 90 ) )
				),
				mouse trap(
					statusmsg( expr(jpeg) )
				)
			);
		)
	);
	vlb<<append( h )
)

It's not clear to me why `jpeg` needs the expr() and `img` doesn't, though. Both of those vars are 'born' on a per-loop basis

hogi
Level XII

Re: Variable number of GraphBoxes. How can I identify which GB I'm sending clicks to?

yes ,this is a quite an issue in JSL. Unfortunately, there is no documentation which arguments get evaluated - and which arguments just  get "transferred".And sometimes it's not at all easy to find out:

Does Head evaluate its argument? 

 

I asked JMP support for an official list of functions which evaluate / don't evaluate their argument. Unfortunately, there no such list.
Another approach: use some Advanced syntax highlighting in JSL Editor - does the function evaluate it's argument? 

I hope, it will get implemented with some of the next releases ....

 

Actually, many(!!!) functions in JSL don't evaluate (some of) their arguments before using them.
This approach is extremely powerful!

 

The most prominent example of "just transferred": 

New column (.... Formula(Expression gets just transferred))

 

The same holds for Mouse Trap.
If you think about it again - it's very kind by JMP that it doesn't evaluate the argument : )
You want to change the status message whenever the user clicks on the image - not at the moment when you execute the code.

 

On the other hand: to add the image to the Window, JMP has to open the image file - and to do so: look into the variable.
NB: Sometimes, it helps to replace an argument with Eval(argument).
Sometimes.
Here: no.