Yast UI
YInputField Class Reference

Input field. More...

Detailed Description

Input field.

Following widget variants exist: InputField TextEntry Password

Example:

# encoding: utf-8
module Yast
class InputField1Client < Client
def main
Yast.import "UI"
UI.OpenDialog(VBox(InputField("Name:"), PushButton("&OK")))
UI.UserInput
UI.CloseDialog
nil
end
end
end
Yast::InputField1Client.new.main

Example:

# encoding: utf-8
module Yast
class InputField2Client < Client
def main
Yast.import "UI"
# Build dialog with one input field field and an OK button.
UI.OpenDialog(VBox(InputField(Id(:name), "Name:"), PushButton("&OK")))
# Wait for user input.
UI.UserInput
# Get the input from the input field 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.
@name = Convert.to_string(UI.QueryWidget(Id(:name), :Value))
Builtins.y2warning("Name: %1", @name)
# 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
nil
end
end
end
Yast::InputField2Client.new.main

Example:

# encoding: utf-8
module Yast
class InputField3Client < Client
def main
Yast.import "UI"
# Build dialog with one input field field and an OK button.
UI.OpenDialog(
VBox(
InputField(Id(:name), "You will never see this:"),
PushButton("&OK")
)
)
# Set an initial value for the input field field.
UI.ChangeWidget(Id(:name), :Value, "Averell Dalton")
# Change the input field field's label.
UI.ChangeWidget(Id(:name), :Label, "Name:")
# Wait for user input.
UI.UserInput
# Get the input from the input field 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.
@name = Convert.to_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
nil
end
end
end
Yast::InputField3Client.new.main

Example:

# encoding: utf-8
module Yast
class InputField4Client < Client
def main
Yast.import "UI"
# Build dialog with one input field field, 4 Beatles buttons and an OK button.
UI.OpenDialog(
VBox(
InputField(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.
@button = nil
begin
@button = UI.UserInput
if @button == :john
UI.ChangeWidget(Id(:name), :Value, "John Lennon")
elsif @button == :paul
UI.ChangeWidget(Id(:name), :Value, "Paul McCartney")
elsif @button == :george
UI.ChangeWidget(Id(:name), :Value, "George Harrison")
elsif @button == :ringo
UI.ChangeWidget(Id(:name), :Value, "Ringo Starr")
end
end until @button == :ok
UI.CloseDialog
nil
end
end
end
Yast::InputField4Client.new.main

Example:

# encoding: utf-8
module Yast
class InputField5Client < Client
def main
Yast.import "UI"
UI.OpenDialog(
VBox(
Frame(
"Shrinkable Textentries",
HBox(
InputField(Opt(:shrinkable), "1"),
InputField(Opt(:shrinkable), "2"),
InputField(Opt(:shrinkable), "321"),
InputField(Opt(:shrinkable), "4")
)
),
PushButton(Opt(:default), "&OK")
)
)
UI.UserInput
UI.CloseDialog
nil
end
end
end
Yast::InputField5Client.new.main

Example:

# encoding: utf-8
module Yast
class InputField6Client < Client
def main
Yast.import "UI"
# Build dialog with one input field field and an OK button.
UI.OpenDialog(
VBox(InputField(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 input field 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.
@name = Convert.to_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
nil
end
end
end
Yast::InputField6Client.new.main

Example:

# encoding: utf-8
module Yast
class Password1Client < Client
def main
Yast.import "UI"
UI.OpenDialog(VBox(Password("Enter password:"), PushButton("&OK")))
UI.UserInput
UI.CloseDialog
nil
end
end
end
Yast::Password1Client.new.main

Example:

# encoding: utf-8
module Yast
class Password2Client < Client
def main
Yast.import "UI"
# 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"))
)
)
@button = nil
@pw1 = ""
@pw2 = ""
begin
# Wait for Input.
@button = UI.UserInput
# Get the values from both password fields.
@pw1 = Convert.to_string(UI.QueryWidget(Id(:pw1), :Value))
@pw2 = Convert.to_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
elsif @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
end
end
end until @pw1 != "" && @pw1 == @pw2 || @button == :cancel
UI.CloseDialog
nil
end
end
end
Yast::Password2Client.new.main

Example:

# encoding: utf-8
module Yast
class InputFieldSetInputMaxLengthClient < Client
def main
Yast.import "UI"
UI.OpenDialog(
VBox(
InputField(Id(:input), "Input Field", "pizza, pasta, pronta"),
IntField(Id(:field), "Limit characters to...", -1, 100, -1),
PushButton(Id(:butt), "limit input"),
PushButton(Id(:exitButton), "Exit")
)
)
@ret = nil
@ret = UI.UserInput
while @ret != :exitButton
@chars = Convert.to_integer(UI.QueryWidget(Id(:field), :Value))
UI.ChangeWidget(:input, :InputMaxLength, @chars)
@ret = UI.UserInput
end
UI.CloseDialog
nil
end
end
end
Yast::InputFieldSetInputMaxLengthClient.new.main

This widget is a one line text entry field with a label above it. An initial text can be provided.

Note
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.
Bug compatibility mode: If used as TextEntry(), Opt(:hstretch) is automatically added (with a warning in the log about that fact) to avoid destroying dialogs written before fixing a geometry bug in the widget. The bug had caused all TextEntry widgets to be horizontally stretchable, so they consumed all the horizontal space they could get, typically making them as wide as the dialog. When used with the new name InputField(), they use a reasonable default width. You can still add Opt(:hstretch), of course.

The documentation for this class was generated from the following file: