|
YCP UI Widget Reference
Back to the widget index
TextEntry Password
|
Input field
|
|
Description
This widget is a one line text entry field with a label above it. An initial
text can be provided.
Notice: You can and should set a keyboard shortcut within the
label. When the user presses the hotkey, the corresponding text entry widget
will get the keyboard focus.
Arguments
string
|
label
|
the label describing the meaning of the entry
|
Optional
string
|
defaulttext
|
The text contained in the text entry
|
Special Properties
string
|
Value
|
the field's contents ( the user input )
|
string
|
Label
|
label above the field
|
string
|
ValidChars
|
valid input characters
|
Options
`opt(`shrinkable)
|
make the input field very small
|
Sample Usage
`TextEntry( `id( `name ), "Enter your name:", "Kilroy" )
Examples
{
UI::OpenDialog(
`VBox(
`TextEntry("Name:"),
`PushButton("&OK")
)
);
UI::UserInput();
UI::CloseDialog();
}
|
{
// Build dialog with one text entry field and an OK button.
UI::OpenDialog(
`VBox(
`TextEntry(`id(`name), "Name:"),
`PushButton("&OK")
)
);
// Wait for user input.
UI::UserInput();
// Get the input from the text entry field.
//
// Notice: The return value of UI::UserInput() does NOT return this value!
// Rather, it returns the ID of the widget (normally the PushButton)
// that caused UI::UserInput() to return.
string name = (string) UI::QueryWidget(`id(`name), `Value);
// Close the dialog.
// Remember to read values from the dialog's widgets BEFORE closing it!
UI::CloseDialog();
// Pop up a new dialog to echo the input.
UI::OpenDialog(
`VBox(
`Label("You entered:"),
`Label(name),
`PushButton("&OK")
)
);
UI::UserInput();
UI::CloseDialog();
}
|
|
{
// Build dialog with one text entry field and an OK button.
UI::OpenDialog(
`VBox(
`TextEntry(`id(`name), "You will never see this:"),
`PushButton("&OK")
)
);
// Set an initial value for the text entry field.
UI::ChangeWidget(`id(`name), `Value, "Averell Dalton");
// Change the text entry field's label.
UI::ChangeWidget(`id(`name), `Label, "Name:");
// Wait for user input.
UI::UserInput();
// Get the input from the text entry field.
//
// Notice: The return value of UI::UserInput() does NOT return this value!
// Rather, it returns the ID of the widget (normally the PushButton)
// that caused UI::UserInput() to return.
string name = (string) UI::QueryWidget(`id(`name), `Value);
// Close the dialog.
// Remember to read values from the dialog's widgets BEFORE closing it!
UI::CloseDialog();
// Pop up a new dialog to echo the input.
UI::OpenDialog(
`VBox(
`Label("You entered:"),
`Label(name),
`PushButton("&OK")
)
);
UI::UserInput();
UI::CloseDialog();
}
|
|
{
// Build dialog with one text entry field, 4 Beatles buttons and an OK button.
UI::OpenDialog(
`VBox(
`TextEntry(`id(`name), "Name:"),
`HBox(
`PushButton(`id(`john), "&John" ),
`PushButton(`id(`paul), "&Paul" ),
`PushButton(`id(`george), "&George"),
`PushButton(`id(`ringo), "&Ringo" )),
`PushButton(`id(`ok), "&OK")
)
);
// Wait for user input.
any button = nil;
// Input loop that only the OK button will leave.
// The 4 Beatles buttons will just propose a name.
repeat
{
button = UI::UserInput();
if ( button == `john ) UI::ChangeWidget(`id(`name), `Value, "John Lennon");
else if ( button == `paul ) UI::ChangeWidget(`id(`name), `Value, "Paul McCartney");
else if ( button == `george ) UI::ChangeWidget(`id(`name), `Value, "George Harrison");
else if ( button == `ringo ) UI::ChangeWidget(`id(`name), `Value, "Ringo Starr" );
} until ( button == `ok );
UI::CloseDialog();
}
|
|
{
UI::OpenDialog(
`VBox(
`Frame("Shrinkable Textentries",
`HBox(
`TextEntry(`opt(`shrinkable), "1"),
`TextEntry(`opt(`shrinkable), "2"),
`TextEntry(`opt(`shrinkable), "3"),
`TextEntry(`opt(`shrinkable), "4")
)
),
`PushButton(`opt(`default), "&OK" )
)
);
UI::UserInput();
UI::CloseDialog();
}
|
{
// Build dialog with one text entry field and an OK button.
UI::OpenDialog(
`VBox(
`TextEntry(`id(`hex_digits), "Hex number:"),
`PushButton("&OK")
)
);
UI::ChangeWidget(`id(`hex_digits), `ValidChars, "0123456789abcdefABCDEF" );
// Wait for user input.
UI::UserInput();
// Get the input from the text entry field.
//
// Notice: The return value of UI::UserInput() does NOT return this value!
// Rather, it returns the ID of the widget (normally the PushButton)
// that caused UI::UserInput() to return.
string name = (string) UI::QueryWidget(`id(`hex_digits), `Value);
// Close the dialog.
// Remember to read values from the dialog's widgets BEFORE closing it!
UI::CloseDialog();
// Pop up a new dialog to echo the input.
UI::OpenDialog(
`VBox(
`Label("You entered:"),
`Label(name),
`PushButton("&OK")
)
);
UI::UserInput();
UI::CloseDialog();
}
|
{
UI::OpenDialog(
`VBox(
`Password("Enter password:"),
`PushButton("&OK")
)
);
UI::UserInput();
UI::CloseDialog();
}
|
{
// Build dialog with two password fields, an "OK" and a "Cancel" button.
UI::OpenDialog(
`VBox(
`Password(`id(`pw1), "Enter password:"),
`Password(`id(`pw2), "Confirm password:"),
`HBox(
`PushButton(`id(`ok), "&OK" ),
`PushButton(`id(`cancel), "&Cancel")
)
)
);
any button = nil;
string pw1 = "";
string pw2 = "";
// Input loop. Will be terminated when the same password has been
// entered in both fields or when 'Cancel' has been clicked.
repeat
{
// Wait for Input.
button = UI::UserInput();
// Get the values from both password fields.
pw1 = (string) UI::QueryWidget(`id(`pw1), `Value );
pw2 = (string) UI::QueryWidget(`id(`pw2), `Value );
if ( button != `cancel )
{
if ( pw1 == "" && pw2 == "" )
{
// Error popup if nothing has been entered.
UI::OpenDialog(
`VBox(
`Label("You must enter a password."),
`PushButton("&OK")
)
);
UI::UserInput();
UI::CloseDialog();
}
else if ( pw1 != pw2 )
{
// Error popup if passwords differ.
UI::OpenDialog(
`VBox(
`Label("The two passwords mismatch."),
`Label("Please try again."),
`PushButton("&OK")
)
);
UI::UserInput();
UI::CloseDialog();
}
}
} until ( ( pw1 != "" && pw1 == pw2 ) ||
button == `cancel );
UI::CloseDialog();
}
|
Back to the widget index
|