Name

PushButton, IconButton — Perform action on click

Synopsis

PushButton ( string iconName ,
  string label );
 
IconButton ( string iconName ,
  string label );
 

Parameters

string iconName

(IconButton only)

string label

Options

default

makes this button the dialogs default button

helpButton

automatically shows topmost `HelpText

okButton

assign the [OK] role to this button (see ButtonBox)

cancelButton

assign the [Cancel] role to this button (see ButtonBox)

applyButton

assign the [Apply] role to this button (see ButtonBox)

customButton

override any other button role assigned to this button

Description

A PushButton is a button with a text label the user can press in order to activate some action. If you call UserInput() and the user presses the button, UserInput() returns with the id of the pressed button.

You can (and should) provide keybord shortcuts along with the button label. For example "& Apply" as a button label will allow the user to activate the button with Alt-A, even if it currently doesn't have keyboard focus. This is important for UIs that don't support using a mouse.

An IconButton is pretty much the same, but it has an icon in addition to the text. If the UI cannot handle icons, it displays only the text, and the icon is silently omitted.

Icons are (at the time of this writing) loaded from the theme directory, /usr/share/YaST2/theme/current.

If a button has `opt(`helpButton) set, it is the official help button of this dialog. When activated, this will open a new dialog with the topmost help text in this dialog (the topmost widget that has a property `HelpText) in a pop-up dialog with a local event loop. Note that this is not done during UI::PollInput() to prevent the application from blocking as long as the help dialog is open.

Since a help button is handled internally by the UI, UI::UserInput() and related will never return this button's ID.

Usage

 	`PushButton( `id( `click ), `opt( `default, `hstretch ), "Click me" )
 

Examples

          {
    // Build a dialog with one button.
    // Wait until that button is clicked,
    // then close the dialog and terminate.

    UI::OpenDialog(
		   `PushButton( "&OK" )
		   );

    UI::UserInput();
    UI::CloseDialog();
}

        
          {
    // Build dialog with three buttons.
    // "Cancel" is the default button, i.e. pressing "Return" will
    // activate it.
    
    UI::OpenDialog(
		   `HBox(
			 `PushButton( `id(`ok),			    "&OK"     ),
			 `PushButton( `id(`cancel), `opt(`default), "&Cancel" ),
			 `PushButton( `id(`help),	   	    "&Help"   )
			 )
		   );

    // Wait for user input. The value returned is the ID of the widget
    // that makes UI::UserInput() terminate, i.e. the respective button ID.
    any button_id = UI::UserInput();
    
    // Close the dialog.
    UI::CloseDialog();


    // Process the input.
    string button_name = "";
    if 		( button_id == `ok 	) 	button_name = "OK";
    else if	( button_id == `cancel	) 	button_name = "Cancel";
    else if	( button_id == `help 	) 	button_name = "Help";

    // Pop up a new dialog to display what button was clicked.
    UI::OpenDialog(
		   `VBox(
			 `Label( "You clicked button \"" + button_name + "\"."),
			 `PushButton( `opt(`default), "&OK" )
			 )
		   );
    UI::UserInput();
    UI::CloseDialog();
}


        
          // PushButton with icons (relative path)
{
	UI::OpenDialog (
		`VBox (
			`Heading( "YaST2 Mini Control Center" ),
			`IconButton (`id ("keyboard "), "yast-keyboard.png", "Keyboard"),
			`IconButton (`id ("mouse"    ), "yast-mouse.png",    "Mouse"),
			`IconButton (`id ("timezone" ), "yast-timezone.png", "Time zone"),
			`IconButton (`id ("lan"      ), "yast-lan.png",      "Network"),
			`IconButton (`id ("sw_single"), "yast-software.png", "Software")
			)
		);

	any ret = nil;

	do
	{
	    ret =  UI::UserInput();

	    if (ret != `cancel)
	    {
	        UI::OpenDialog (`Label ("Running " +  (string) ret + "..."));
	        sleep (4000);
	        UI::CloseDialog();
	    }

	} while ( ret != `cancel);

	UI::CloseDialog();
}