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
miguello
Level VI

How to hide\unhide GUI elements effectively?

I have GUI that hides or unhides some elements depending on the selector.

For now I have encapsulated all the elements that change in respective  If Box()'es, and change each on of them when ComboBox selector changes, like so:

Names Default To Here( 1 );

modeSelectorOptions = {"Mode1", "Mode2"};
gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		<< Set Function(
			Function(
				{this}, 
				Match(this << Get Selected(),
				modeSelectorOptions[1], Write("\!nMode1");IB1<< Set (1); IB2 << Set(0)/*many more when script expanded*/,
				modeSelectorOptions[2],	Write("\!nMode2");IB1<< Set (0); IB2 << Set(1)/*many more when script expanded*/,
				)
			)
		);
	),
	Button Box("All Modes", Write("Always active")),
	IB1 = If Box(1, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB2 = If Box(0, Button Box("GUI ELEMENT for Mode2", Write("Button pressed")))
	
);

NW = New Window("Test",<< Show Toolbars(0),<<ShowMenu(0), gui);

This works, but it is not very scalable.

I need to hide or unhide certain elements depending on the mode throughout the whole window with many elements. I have to encapsulate each of those changing elements in an If Box(), name it and don't forget to include it in the Match statement of the modeSelector.

It is not very scalable, especially when I move into 10-20 different elements.

 

Is there any way to, let's say, just raise a corresponding flag in Match statement, define all the IF boxes with those flags and then just give command to redraw them?

Something like this, where redrawIfBoxes is an expression that redraws all the IF boxes so that changed flag takes effect:

Names Default To Here( 1 );

modeSelectorOptions = {"Mode1", "Mode2"};
mode1Flag = 1;
mode2Flag = 0;
gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		<< Set Function(
			Function(
				{this}, 
				Match(this << Get Selected(),
				modeSelectorOptions[1], Write("\!nMode1");mode1Flag = 1;mode2Flag = 0;redrawIfBoxes,
				modeSelectorOptions[2],	Write("\!nMode2");mode1Flag = 0;mode2Flag = 1;redrawIfBoxes,
				)
			)
		);
	),
	Button Box("All Modes", Write("Always active")),
	IB1 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB2 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed")))
	
);

NW = New Window("Test",<< Show Toolbars(0),<<ShowMenu(0), gui);

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
miguello
Level VI

Re: How to hide\unhide GUI elements effectively?

For now I have it done this way:

Names Default To Here( 1 );

modeSelectorOptions = {"Mode1", "Mode2"};
mode1Flag = 1;
mode2Flag = 0;
mode1IfBoxes = {IB1, IB3, IB5};
mode2IfBoxes = {IB2, IB4, IB6};
gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		<< Set Function(
			Function(
				{this}, 
				Match(this << Get Selected(),
				modeSelectorOptions[1], Write("\!nMode1");mode1Flag = 1;mode2Flag = 0;redrawIfBoxes,
				modeSelectorOptions[2],	Write("\!nMode2");mode1Flag = 0;mode2Flag = 1;redrawIfBoxes,
				)
			)
		);
	),
	Button Box("All Modes", Write("Always active")),
	IB1 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB2 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))),
	IB3 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB4 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))),
	IB5 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB6 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed")))
	
);
redrawIfBoxes = Expr(
	mode1IfBoxes << Set (mode1Flag);
	mode2IfBoxes << Set (mode2Flag);
);

NW = New Window("Test",<< Show Toolbars(0),<<ShowMenu(0), gui);

Let me know if there is a more robust way.
With more modes redrawIfBoxes can be changed from Expression to Function to match list of IfBoxes to a specific flag without ever needing to update the function.

The only two places to update - lists of If Boxes and Match statement in selector combobox.

 

View solution in original post

jthi
Super User

Re: How to hide\unhide GUI elements effectively?

Depends on your final application and what you consider "robust" and easy to manage, but there are different options:

  • You could use if boxes
    • XPath might be helpful
    • You could also just wrap your buttons inside some container, so you would only need one if box per mode
  • You could use << Visibility("Collapse")
  • You could update button text/actions dynamically when changes happen

 

Not necessarily they way I would do it, but this is just here to give some potential ideas

Names Default To Here( 1 );

mode_options = {"Mode1", "Mode2"};

gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		<< Set Function(Function({this},
			this << Inval;
			selection = Contains(mode_options, this << Get Selected);
			ibs << Set(0);
			ibs[selection] << Set(1);
			this << Update Window;
		));
	),
	Button Box("All Modes", Write("Always active")),
	If Box(0, 
		V List Box(
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))
		)
	),
	If Box(0, 
		V List Box(
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))
		)
	)
);

ibs = gui << Xpath("//IfBox");

// JMP things
modeSelector << Set(2, Run Script(0));
modeSelector << Set(1, Run Script(1));

nw = New Window("Test",<< Show Toolbars(0),<<ShowMenu(0), gui);

Write();
-Jarmo

View solution in original post

2 REPLIES 2
miguello
Level VI

Re: How to hide\unhide GUI elements effectively?

For now I have it done this way:

Names Default To Here( 1 );

modeSelectorOptions = {"Mode1", "Mode2"};
mode1Flag = 1;
mode2Flag = 0;
mode1IfBoxes = {IB1, IB3, IB5};
mode2IfBoxes = {IB2, IB4, IB6};
gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		<< Set Function(
			Function(
				{this}, 
				Match(this << Get Selected(),
				modeSelectorOptions[1], Write("\!nMode1");mode1Flag = 1;mode2Flag = 0;redrawIfBoxes,
				modeSelectorOptions[2],	Write("\!nMode2");mode1Flag = 0;mode2Flag = 1;redrawIfBoxes,
				)
			)
		);
	),
	Button Box("All Modes", Write("Always active")),
	IB1 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB2 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))),
	IB3 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB4 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))),
	IB5 = If Box(mode1Flag, Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))), 
	IB6 = If Box(mode2Flag, Button Box("GUI ELEMENT for Mode2", Write("Button pressed")))
	
);
redrawIfBoxes = Expr(
	mode1IfBoxes << Set (mode1Flag);
	mode2IfBoxes << Set (mode2Flag);
);

NW = New Window("Test",<< Show Toolbars(0),<<ShowMenu(0), gui);

Let me know if there is a more robust way.
With more modes redrawIfBoxes can be changed from Expression to Function to match list of IfBoxes to a specific flag without ever needing to update the function.

The only two places to update - lists of If Boxes and Match statement in selector combobox.

 

jthi
Super User

Re: How to hide\unhide GUI elements effectively?

Depends on your final application and what you consider "robust" and easy to manage, but there are different options:

  • You could use if boxes
    • XPath might be helpful
    • You could also just wrap your buttons inside some container, so you would only need one if box per mode
  • You could use << Visibility("Collapse")
  • You could update button text/actions dynamically when changes happen

 

Not necessarily they way I would do it, but this is just here to give some potential ideas

Names Default To Here( 1 );

mode_options = {"Mode1", "Mode2"};

gui = V List Box(
	modeSelector = ComboBox(modeSelectorOptions, 
		<< Set Function(Function({this},
			this << Inval;
			selection = Contains(mode_options, this << Get Selected);
			ibs << Set(0);
			ibs[selection] << Set(1);
			this << Update Window;
		));
	),
	Button Box("All Modes", Write("Always active")),
	If Box(0, 
		V List Box(
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode1", Write("Button pressed"))
		)
	),
	If Box(0, 
		V List Box(
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed")),
			Button Box("GUI ELEMENT for Mode2", Write("Button pressed"))
		)
	)
);

ibs = gui << Xpath("//IfBox");

// JMP things
modeSelector << Set(2, Run Script(0));
modeSelector << Set(1, Run Script(1));

nw = New Window("Test",<< Show Toolbars(0),<<ShowMenu(0), gui);

Write();
-Jarmo