cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
LaserGuy
Level II

Window that Scrolls Through Images in a Folder

 

I need some help with the scripting syntax. I am using JMP 16.

 

I have the script to read through all the files in a subfolder and identify the files that has the jpg extension.

 

What I would like to do is display a Window, with a forward and backward button, that would allow the user to display the images. How would I go about creating that?

 

Any help would be appreciated.

 

folder = char(Get Default Directory()) || "images/"; //subfolder is "images"
names = Files In Directory( folder );

dtpicnames = New Table( "Filenames of Images",
	New Column( "filename", character ),
	New Column( "inspection result", character ),
	New Column( "path", character )
);
dtpicnames << move window(800, 0);

for( ii = 1, ii <= N Items(names), ii++,
	if( Ends With( names[ii], ".jpg"),
		dtpicnames << Add Rows(1);
		dtpicnames:filename = names[ii];
		dtpicnames:path = folder || names[ii];
	);
);

img = new image(dtpicnames:path[1]);
	img << scale(0.5);

w = New Window( "Image", pb = Picture Box( img ) );
w << move window(0, 0);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Window that Scrolls Through Images in a Folder

Here is a modification of your code that works on an image folder on my system

Names Default To Here( 1 );

folder = char(Get Default Directory()) || "images/"; //subfolder is "images"

names = Files In Directory( folder );

dtpicnames = New Table( "Filenames of Images",
	New Column( "filename", character ),
	New Column( "inspection result", character ),
	New Column( "path", character )
);
dtpicnames << move window( 800, 0 );

For( ii = 1, ii <= N Items( names ), ii++,
	If( Ends With( Uppercase( names[ii] ), ".JPG" ),
		dtpicnames << Add Rows( 1 );
		dtpicnames:filename = names[ii];
		dtpicnames:path = folder || "\" || names[ii];
	)
);

theRow = 1;
img = New Image( dtpicnames:path[theRow] );
img << scale( 0.1 );
	

w = New Window( "Image",
	V List Box(
		vlb = V List Box( pb = Picture Box( img ) ),
		H List Box(
			Button Box( "Up",
				If( theRow > 1,
					theRow --;
					pb << delete;
					img = New Image( dtpicnames:path[theRow] );
					img << scale( 0.1 );
					vlb << append( pb = Picture Box( img ) )
				)
			),
			Button Box( "Down",
				If( theRow < N Rows( dtpicnames ) - 1,
					theRow ++;
					pb << delete;
					img = New Image( dtpicnames:path[theRow] );
					img << scale( 0.1 );
					vlb << append( pb = Picture Box( img ) );
				)
			)
		)
	)
);
w << move window( 0, 0 );
Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: Window that Scrolls Through Images in a Folder

Here is a modification of your code that works on an image folder on my system

Names Default To Here( 1 );

folder = char(Get Default Directory()) || "images/"; //subfolder is "images"

names = Files In Directory( folder );

dtpicnames = New Table( "Filenames of Images",
	New Column( "filename", character ),
	New Column( "inspection result", character ),
	New Column( "path", character )
);
dtpicnames << move window( 800, 0 );

For( ii = 1, ii <= N Items( names ), ii++,
	If( Ends With( Uppercase( names[ii] ), ".JPG" ),
		dtpicnames << Add Rows( 1 );
		dtpicnames:filename = names[ii];
		dtpicnames:path = folder || "\" || names[ii];
	)
);

theRow = 1;
img = New Image( dtpicnames:path[theRow] );
img << scale( 0.1 );
	

w = New Window( "Image",
	V List Box(
		vlb = V List Box( pb = Picture Box( img ) ),
		H List Box(
			Button Box( "Up",
				If( theRow > 1,
					theRow --;
					pb << delete;
					img = New Image( dtpicnames:path[theRow] );
					img << scale( 0.1 );
					vlb << append( pb = Picture Box( img ) )
				)
			),
			Button Box( "Down",
				If( theRow < N Rows( dtpicnames ) - 1,
					theRow ++;
					pb << delete;
					img = New Image( dtpicnames:path[theRow] );
					img << scale( 0.1 );
					vlb << append( pb = Picture Box( img ) );
				)
			)
		)
	)
);
w << move window( 0, 0 );
Jim