|
YCP UI Widget Reference
Back to the widget index
PushButton IconButton
|
Perform action on click
|
|
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.
Arguments
string
|
iconName
|
( IconButton only )
|
string
|
label
|
|
Special Properties
string
|
Label
|
the text on the PushButton
|
Options
`opt(`default)
|
makes this button the dialogs default button
|
Sample 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();
}
|
{
// Build a dialog with one icon button.
// Wait until that button is clicked,
// then close the dialog and terminate.
UI::OpenDialog(
`IconButton( "topRow_right.png", "&OK" )
);
UI::UserInput();
UI::CloseDialog();
}
|
Back to the widget index
|