cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
DL723
Level II

Using another button instead of "Ok" - Modal windows

Hi,

   Just started learning scripting so please excuse the messy or redundant coding haha.  I'm trying to combine a few things I've picked up from these forums.  Basically, give the user an option of opening a file or selecting an already open file.  I've finally figured out I needed to use a Modal window to wait for the selection is made before continuing down the script.  

 

Is there a way to have the code continue when the selection is made? Instead of waiting for the user to press the "Ok" button?  So for my two options:

1. User opens a file --> continue when the file is opened

2. User selects an open file --> continue when the file is selected

 

Right now, having them press the "ok" button after the selection seems redundant.  Thanks for any help!

 

InputWindow = New Window( "Pick a file opening option (must be truncated)", <<modal, 

V List Box(
   Text Box( "Pick a Cut and Truncated Waveform" ), 
  Spacer Box( size( 1, 10 ) ), 
   Button Box( "Open a file",
    path = Pick File(
	"Select Raw Waveform data",
	"", // no default directory
	{"JMP Files|jmp;jsl;jrn", "All Files|*"},
	1,
	0,
	"" // no default file
		);
	open(path);
    	dt=current data table();   
   ),
   Spacer Box( size( 10, 1 ) ), 

   Button Box( "Select from a list",
   choose_data_table=function({},
list = {};
For( i = 1, i <= N Table(), i++,
	list[i] = Data Table( i ) << get name
);

win = New Window( "Select a data table", << Modal,
	hb = H List Box(
		Panel Box( "Choose a data table",
			dt = List Box(
				list,
				max selected( 1 ),
				chosen = Data Table( (dt << get selected)[1] );
				show (chosen);
			)),)
);
chosen);
dt=choose_data_table(); 
    	    )
  )
  ) 
);
    
1 ACCEPTED SOLUTION

Accepted Solutions
vince_faller
Super User (Alumni)

Re: Using another button instead of "Ok" - Modal windows

You could just manually make the okay button and click it with btn << Click. 

InputWindow = New Window( "Pick a file opening option (must be truncated)",
	<<modal, 
	
	V List Box(
		Text Box( "Pick a Cut and Truncated Waveform" ),
		Spacer Box( size( 1, 10 ) ),
		Button Box( "Open a file",
			path = Pick File(
				"Select Raw Waveform data",
				"", // no default directory
				{"JMP Files|jmp;jsl;jrn", "All Files|*"},
				1,
				0,
				"" // no default file
			);
			dt = Open( path ); //probably should do this instead of current data table()
			//dt = Current Data Table();
			btn_ok << Click;
		),
		Spacer Box( size( 10, 1 ) ), 

		Button Box( "Select from a list",
			choose_data_table = Function( {},
				list = {};
				For( i = 1, i <= N Table(), i++,
					list[i] = Data Table( i ) << get name
				);

				win = New Window( "Select a data table",
					<<Modal,
					hb = H List Box(
						Panel Box( "Choose a data table",
							dt = List Box(
								list,
								max selected( 1 ),
								chosen = Data Table( (dt << get selected)[1] );
								Show( chosen );
							)
						),

					)
				);
				chosen;
			);
			dt = choose_data_table();
			btn_ok << Click;
		), 
		btn_ok = Buttonbox("OK")
	)
);

But it sounds like you might not need a modal dialog.  You could just have the rest of your code execution be a function or expression and send that to each button. 

 

domorestuff = function({}, 
	print(dt);
);
InputWindow = New Window( "Pick a file opening option (must be truncated)",
	
	V List Box(
		Text Box( "Pick a Cut and Truncated Waveform" ),
		Spacer Box( size( 1, 10 ) ),
		Button Box( "Open a file",
			path = Pick File(
				"Select Raw Waveform data",
				"", // no default directory
				{"JMP Files|jmp;jsl;jrn", "All Files|*"},
				1,
				0,
				"" // no default file
			);
			dt = Open( path ); //probably should do this instead of current data table()
			//dt = Current Data Table();
			domorestuff();
		),
		Spacer Box( size( 10, 1 ) ), 

		Button Box( "Select from a list",
			choose_data_table = Function( {},
				list = {};
				For( i = 1, i <= N Table(), i++,
					list[i] = Data Table( i ) << get name
				);

				win = New Window( "Select a data table",
					<<Modal,
					hb = H List Box(
						Panel Box( "Choose a data table",
							dt = List Box(
								list,
								max selected( 1 ),
								chosen = Data Table( (dt << get selected)[1] );
								Show( chosen );
							)
						),

					)
				);
				chosen;
			);
			dt = choose_data_table();
			domorestuff();
		)
	)
);
Vince Faller - Predictum

View solution in original post

3 REPLIES 3
vince_faller
Super User (Alumni)

Re: Using another button instead of "Ok" - Modal windows

You could just manually make the okay button and click it with btn << Click. 

InputWindow = New Window( "Pick a file opening option (must be truncated)",
	<<modal, 
	
	V List Box(
		Text Box( "Pick a Cut and Truncated Waveform" ),
		Spacer Box( size( 1, 10 ) ),
		Button Box( "Open a file",
			path = Pick File(
				"Select Raw Waveform data",
				"", // no default directory
				{"JMP Files|jmp;jsl;jrn", "All Files|*"},
				1,
				0,
				"" // no default file
			);
			dt = Open( path ); //probably should do this instead of current data table()
			//dt = Current Data Table();
			btn_ok << Click;
		),
		Spacer Box( size( 10, 1 ) ), 

		Button Box( "Select from a list",
			choose_data_table = Function( {},
				list = {};
				For( i = 1, i <= N Table(), i++,
					list[i] = Data Table( i ) << get name
				);

				win = New Window( "Select a data table",
					<<Modal,
					hb = H List Box(
						Panel Box( "Choose a data table",
							dt = List Box(
								list,
								max selected( 1 ),
								chosen = Data Table( (dt << get selected)[1] );
								Show( chosen );
							)
						),

					)
				);
				chosen;
			);
			dt = choose_data_table();
			btn_ok << Click;
		), 
		btn_ok = Buttonbox("OK")
	)
);

But it sounds like you might not need a modal dialog.  You could just have the rest of your code execution be a function or expression and send that to each button. 

 

domorestuff = function({}, 
	print(dt);
);
InputWindow = New Window( "Pick a file opening option (must be truncated)",
	
	V List Box(
		Text Box( "Pick a Cut and Truncated Waveform" ),
		Spacer Box( size( 1, 10 ) ),
		Button Box( "Open a file",
			path = Pick File(
				"Select Raw Waveform data",
				"", // no default directory
				{"JMP Files|jmp;jsl;jrn", "All Files|*"},
				1,
				0,
				"" // no default file
			);
			dt = Open( path ); //probably should do this instead of current data table()
			//dt = Current Data Table();
			domorestuff();
		),
		Spacer Box( size( 10, 1 ) ), 

		Button Box( "Select from a list",
			choose_data_table = Function( {},
				list = {};
				For( i = 1, i <= N Table(), i++,
					list[i] = Data Table( i ) << get name
				);

				win = New Window( "Select a data table",
					<<Modal,
					hb = H List Box(
						Panel Box( "Choose a data table",
							dt = List Box(
								list,
								max selected( 1 ),
								chosen = Data Table( (dt << get selected)[1] );
								Show( chosen );
							)
						),

					)
				);
				chosen;
			);
			dt = choose_data_table();
			domorestuff();
		)
	)
);
Vince Faller - Predictum
David_Burnham
Super User (Alumni)

Re: Using another button instead of "Ok" - Modal windows

Modal windows are designed to force a user to click OK before execution continues.  Alternatively, you can have a non-modal window and put attach a script to either a button or a display box that allows selections.  In the example below, execution continues immediately a selection is made:

Names Default To Here(1);
lst = {"Item 1","Item 2","Item 3","Item 4"};
nw = New Window("Selection",
	Border Box(top(20),bottom(20),left(20),right(20),
		V List Box(
			Text Box("Select an item from the list:"),
			lb = List Box(lst,<<SetMaxSelected(1),<<SetScript(doSelect()))
		)
	)
);

doSelect = Function({},{Default Local},
	lstSelected = lb << Get Selected;
	selected = lstSelected[1];
	nw << Close Window;
	show(selected);
	// continue your code here
)

 

-Dave
DL723
Level II

Re: Using another button instead of "Ok" - Modal windows

Hi,

  Thanks for the replies.  Ah, I think everybody is correct in I didn't need it to be modal.  That was the first solution I found to getting my table to stay defined after the selection was made and the script moved past the window selection.

 

Either way, the self click worked for what I had written, already.  But I'll try the straight forward way of using functions.  Thanks again.