Yast UI
YTree Class Reference

Scrollable tree selection. More...

Detailed Description

Scrollable tree selection.

Following widget variants exist: Tree

The boolean parameter inside Item() indicates whether or not the respective tree item should be opened by default - if it has any subitems and if the respective UI is capable of closing and opening subtrees. If the UI cannot handle this, all subtrees will always be open.

Non-standard Opt() arguments: multiSelection user can select multiple items at once Non-standard Opt() arguments: immediate make :notify trigger immediately when the selected item changes Example:

# encoding: utf-8
# Simple tree example
module Yast
class Tree1Client < Client
def main
Yast.import "UI"
UI.OpenDialog(
VBox(
MinSize(
30,
10,
Tree(
Id(:dest_dir),
"Select destination directory:",
[
Item(
Id(:root),
"/",
false,
[
Item(
Id(:etc),
"etc",
[Item("opt"), Item("SuSEconfig"), Item("X11")]
),
Item(
"usr",
false,
[
"bin",
"lib",
Item("share", ["man", "info", "emacs"]),
Item(Id(:usr_local), "local"),
Item("X11R6", ["bin", "lib", "share", "man", "etc"])
]
),
Item(
Id(:opt),
"opt",
false,
["kde", "netscape", "Office51"]
),
Item("home", false),
Item(Id(:other), "<other>")
]
)
]
)
),
HBox(
PushButton(Id(:sel_opt), Opt(:hstretch), "/&opt"),
PushButton(Id(:sel_usr), Opt(:hstretch), "/&usr"),
PushButton(Id(:sel_usr_local), Opt(:hstretch), "/usr/&local")
),
PushButton(Id(:ok), Opt(:default), "&OK")
)
)
@id = nil
begin
@id = UI.UserInput
if @id == :sel_usr
UI.ChangeWidget(:dest_dir, :CurrentItem, "usr")
elsif @id == :sel_usr_local
UI.ChangeWidget(:dest_dir, :CurrentItem, :usr_local)
elsif @id == :sel_opt
UI.ChangeWidget(:dest_dir, :CurrentItem, :opt)
end
end until @id == :ok
# Get the input from the tree.
#
# 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.
@dest_dir = UI.QueryWidget(:dest_dir, :CurrentItem)
Builtins.y2debug("Selected: %1", @dest_dir)
@dest_dir = "" if @dest_dir == nil
# 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 selection.
UI.OpenDialog(
VBox(
Label(
Builtins.sformat("Selected destination directory: %1", @dest_dir)
),
PushButton(Opt(:default), "&OK")
)
)
UI.UserInput
UI.CloseDialog
nil
end
end
end
Yast::Tree1Client.new.main

Example:

# encoding: utf-8
module Yast
class Tree2Client < Client
def main
Yast.import "UI"
# Build a dialog with a tree for directory selection, three
# buttons with common values and a label that directly echoes any
# selected directory.
#
# The tree in this example uses the `notify option that makes
# UI::UserInput() return immediately as soon as the user selects a
# tree item rather than the default behaviour which waits for the
# user to activate a button.
UI.OpenDialog(
VBox(
MinHeight(
14,
Tree(
Id(:dest_dir),
Opt(:notify),
"Select destination directory:",
[
Item(
Id(:root),
"/",
true,
[
Item(
Id(:etc),
"etc",
[Item("opt"), Item("SuSEconfig"), Item("X11")]
),
Item(
"usr",
false,
[
"bin",
"lib",
Item("share", ["man", "info", "emacs"]),
Item(Id(:usr_local), "local"),
Item("X11R6", ["bin", "lib", "share", "man", "etc"])
]
),
Item(Id(:opt), "opt", true, ["kde", "netscape", "Office51"]),
Item("home"),
"work",
Item(Id(:other), "<other>")
]
)
]
)
),
HBox(
PushButton(Id(:sel_opt), Opt(:hstretch), "/&opt"),
PushButton(Id(:sel_usr), Opt(:hstretch), "/&usr"),
PushButton(Id(:sel_usr_local), Opt(:hstretch), "/usr/&local"),
PushButton(Id(:none), Opt(:hstretch), "none")
),
HBox(
Label("Current Value:"),
Label(Id(:echo), Opt(:outputField, :hstretch), "?????????")
),
PushButton(Id(:ok), Opt(:default), "&OK")
)
)
@id = nil
begin
@id = UI.UserInput
if @id == :sel_usr
UI.ChangeWidget(:dest_dir, :CurrentItem, "usr")
elsif @id == :sel_usr_local
UI.ChangeWidget(:dest_dir, :CurrentItem, :usr_local)
elsif @id == :sel_opt
UI.ChangeWidget(:dest_dir, :CurrentItem, :opt)
elsif @id == :none
UI.ChangeWidget(:dest_dir, :CurrentItem, nil)
end
UI.ChangeWidget(:echo, :Value, "")
@current_dir = UI.QueryWidget(:dest_dir, :CurrentItem)
if @current_dir != nil
UI.ChangeWidget(:echo, :Value, Builtins.sformat("%1", @current_dir))
end
Builtins.y2milestone("Items:\n%1", UI.QueryWidget(:dest_dir, :Items))
Builtins.y2milestone(
"OpenItems: %1",
UI.QueryWidget(:dest_dir, :OpenItems)
)
Builtins.y2milestone(
"Current Branch: %1",
UI.QueryWidget(:dest_dir, :CurrentBranch)
)
end until @id == :ok
# Close the dialog.
# Remember to read values from the dialog's widgets BEFORE closing it!
UI.CloseDialog
nil
end
end
end
Yast::Tree2Client.new.main

Example:

# encoding: utf-8
module Yast
class Tree3Client < Client
def main
Yast.import "UI"
# Build a dialog with a tree for directory selection, three
# buttons with common values and a label that directly echoes any
# selected directory.
#
# The tree in this example uses the `notify option that makes
# UI::UserInput() return immediately as soon as the user selects a
# tree item rather than the default behaviour which waits for the
# user to activate a button.
UI.OpenDialog(
MinWidth(
50,
VBox(
Tree(
Id(:dest_dir),
Opt(:notify),
"Select destination directory:",
[
Item(
"/",
true,
[
Item("etc", [Item("opt"), Item("SuSEconfig"), Item("X11")]),
Item(
"usr",
false,
[
"bin",
"lib",
Item("share", ["man", "info", "emacs"]),
Item("local"),
Item("X11R6", ["bin", "lib", "share", "man", "etc"])
]
),
Item("opt", true, ["kde", "netscape", "Office51"]),
Item("home"),
"work",
Item("<other>")
]
)
]
),
HBox(
PushButton(Id(:sel_opt), Opt(:hstretch), "/&opt"),
PushButton(Id(:sel_usr), Opt(:hstretch), "/&usr"),
PushButton(Id(:sel_usr_local), Opt(:hstretch), "/usr/&local")
),
HBox(
HWeight(2, Label("Current Item:")),
HWeight(5, Label(Id(:echoItem), Opt(:outputField, :hstretch), ""))
),
HBox(
HWeight(2, Label("Current Branch:")),
HWeight(
5,
Label(Id(:echoBranch), Opt(:outputField, :hstretch), "")
)
),
HBox(
HWeight(2, Label("Current Path:")),
HWeight(5, Label(Id(:echoPath), Opt(:outputField, :hstretch), ""))
),
PushButton(Id(:ok), Opt(:default), "&OK")
)
)
)
@id = nil
begin
@id = UI.UserInput
if @id == :sel_usr
UI.ChangeWidget(Id(:dest_dir), :CurrentItem, "usr")
elsif @id == :sel_usr_local
UI.ChangeWidget(Id(:dest_dir), :CurrentItem, "local")
elsif @id == :sel_opt
UI.ChangeWidget(Id(:dest_dir), :CurrentItem, "opt")
elsif @id == :dest_dir
@current_dir = UI.QueryWidget(:dest_dir, :CurrentItem)
if @current_dir != nil
UI.ChangeWidget(
Id(:echoItem),
:Value,
Builtins.sformat("%1", @current_dir)
)
end
@current_branch = Convert.convert(
UI.QueryWidget(:dest_dir, :CurrentBranch),
:from => "any",
:to => "list <string>"
)
if @current_branch != nil
UI.ChangeWidget(
:echoBranch,
:Value,
Builtins.sformat("%1", @current_branch)
)
@current_path = Builtins.mergestring(@current_branch, "/")
if Ops.greater_than(Builtins.size(@current_path), 2)
# Remove duplicate "/" at start
@current_path = Builtins.substring(
@current_path,
1,
Ops.subtract(Builtins.size(@current_path), 1)
)
end
UI.ChangeWidget(
:echoPath,
:Value,
Builtins.sformat("%1", @current_path)
)
end
end
end until @id == :ok
# Close the dialog.
# Remember to read values from the dialog's widgets BEFORE closing it!
UI.CloseDialog
nil
end
end
end
Yast::Tree3Client.new.main

Example:

# encoding: utf-8
# Tree with icons
module Yast
class TreeIconsClient < Client
def main
Yast.import "UI"
UI.OpenDialog(
VBox(
Heading("YaST2 Mini Control Center"),
Tree(
Id(:mod),
"Modules",
[
Item(
Id("country"),
term(:icon, "yast-language.png"),
"Localization",
true,
[
Item(
Id("keyboard"),
term(:icon, "yast-keyboard.png"),
"Keyboard"
),
Item(
Id("timezone"),
term(:icon, "yast-timezone.png"),
"Time zone"
)
]
),
Item(Id("mouse"), term(:icon, "yast-mouse.png"), "Mouse"),
Item(Id("lan"), term(:icon, "yast-lan.png"), "Network"),
Item(
Id("sw_single"),
term(:icon, "yast-software.png"),
"Software"
)
]
),
PushButton(Id(:ok), Opt(:default), "&OK")
)
)
UI.UserInput
UI.CloseDialog
nil
end
end
end
Yast::TreeIconsClient.new.main

Example:

# encoding: utf-8
# Example showing how to replace Tree items
module Yast
class TreeReplaceItemsClient < Client
def main
Yast.import "UI"
@pizza_list = [
"Pizza Napoli",
"Pizza Funghi",
"Pizza Salami",
"Pizza Hawaii"
]
@pasta_list = ["Spaghetti", "Rigatoni", "Tortellini"]
@veggie_toppings = [
"Cheese",
"Mushrooms",
"Pepperoni",
"Rucola",
"Tomatoes"
]
@meat_toppings = ["Ham", "Salami", "Tuna"]
@menu = [
Item(Id(:pizza_branch), "Pizza", true, @pizza_list),
Item(Id(:pasta_branch), "Pasta", true, @pasta_list)
]
@toppings = [
Item(Id(:meat_branch), "Meat", true, @meat_toppings),
Item(Id(:veggie_branch), "Veggie", true, @veggie_toppings)
]
UI.OpenDialog(
VBox(
Tree(Id(:listing), "Daily &Specials:", @menu),
HBox(
PushButton(Id(:menu), "&Menu"),
PushButton(Id(:toppings), "&Toppings"),
PushButton(Id(:empty), "&None")
),
PushButton(Id(:ok), "&OK")
)
)
@button = nil
begin
@button = Convert.to_symbol(UI.UserInput)
UI.ChangeWidget(:listing, :Items, @menu) if @button == :menu
UI.ChangeWidget(:listing, :Items, @toppings) if @button == :toppings
UI.ChangeWidget(:listing, :Items, []) if @button == :empty
end while @button != :ok
@order = Convert.to_string(UI.QueryWidget(:listing, :CurrentItem))
UI.CloseDialog
#
# Show the result
#
UI.OpenDialog(
VBox(
Label(Builtins.sformat("Your order: %1", @order)),
PushButton(Opt(:default), "&OK")
)
)
UI.UserInput
UI.CloseDialog
nil
end
end
end
Yast::TreeReplaceItemsClient.new.main

Example:

# encoding: utf-8
# Advanced example of using the Wizard widget.
#
# Note: YCP applications are discouraged from using the Wizard widget directly.
# Use the Wizard module instead.
module Yast
class Wizard4Client < Client
def main
Yast.import "UI"
if !UI.HasSpecialWidget(:Wizard)
Builtins.y2error(
"This works only with UIs that provide the wizard widget!"
)
return
end
@help_text = "<p>This is a help text.</p>" +
"<p>It should be helpful.</p>" +
"<p>If it isn't helpful, it should rather not be called a <i>help text</i>.</p>"
UI.OpenDialog(
Opt(:defaultsize),
Wizard(
Opt(:treeEnabled),
:back,
"&Back",
:abort,
"Ab&ort",
:next,
"&Next"
)
)
# UI::DumpWidgetTree();
UI.WizardCommand(
term(
:SetDialogIcon,
"/usr/share/YaST2/theme/current/icons/22x22/apps/YaST.png"
)
)
UI.WizardCommand(
term(:SetDialogHeading, "Welcome to the YaST2 installation")
)
UI.WizardCommand(term(:SetHelpText, @help_text))
UI.WizardCommand(term(:AddTreeItem, "", "First Toplevel Item", "tl1"))
UI.WizardCommand(term(:AddTreeItem, "", "Second Toplevel Item", "tl2"))
UI.WizardCommand(term(:AddTreeItem, "", "Third Toplevel Item", "tl3"))
UI.WizardCommand(term(:AddTreeItem, "tl1", "First Sublevel", "1-1"))
UI.WizardCommand(term(:AddTreeItem, "tl1", "Second Sublevel", "1-2"))
UI.WizardCommand(term(:AddTreeItem, "tl1", "Third Sublevel", "1-3"))
UI.WizardCommand(term(:AddTreeItem, "tl2", "First Sublevel", "2-1"))
UI.WizardCommand(term(:AddTreeItem, "tl2", "Second Sublevel", "2-2"))
UI.WizardCommand(term(:AddTreeItem, "tl2", "Third Sublevel", "2-3"))
UI.WizardCommand(term(:AddTreeItem, "1-2", "First 3rd level ", "3rd 1"))
UI.WizardCommand(term(:AddTreeItem, "1-2", "Second 3rd level ", "3rd 2"))
UI.WizardCommand(term(:AddTreeItem, "1-2", "Item without ID", ""))
UI.WizardCommand(term(:SelectTreeItem, "3rd 1"))
UI.WizardCommand(term(:AddMenu, "&File", "file-menu"))
UI.WizardCommand(term(:AddMenu, "&Edit", "edit-menu"))
UI.WizardCommand(term(:AddMenu, "&Options", "opt-menu"))
UI.WizardCommand(term(:AddMenuEntry, "file-menu", "&New", "file-new"))
UI.WizardCommand(term(:AddMenuEntry, "file-menu", "&Open", "file-open"))
UI.WizardCommand(
term(:AddSubMenu, "file-menu", "Open &Recent", "file-recent")
)
UI.WizardCommand(term(:AddMenuEntry, "file-menu", "&Save", "file-save"))
UI.WizardCommand(
term(:AddMenuEntry, "file-menu", "Save &As", "file-save-as")
)
UI.WizardCommand(
term(:AddMenuEntry, "file-recent", "/tmp/test1", "recent-test1")
)
UI.WizardCommand(
term(:AddMenuEntry, "file-recent", "/tmp/test2", "recent-test2")
)
UI.WizardCommand(term(:AddMenuEntry, "edit-menu", "C&ut", "edit-cut"))
UI.WizardCommand(term(:AddMenuEntry, "edit-menu", "C&opy", "edit-copy"))
UI.WizardCommand(term(:AddMenuEntry, "edit-menu", "&Paste", "edit-paste"))
UI.WizardCommand(
term(:AddMenuEntry, "opt-menu", "&Settings", "opt-settings")
)
UI.WizardCommand(term(:AddMenuSeparator, "opt-menu"))
UI.WizardCommand(
term(
:AddMenuEntry,
"opt-menu",
"Activate &Hypersonic Transducer",
"frank-n-furter"
)
)
while true
@event = UI.WaitForEvent
Builtins.y2milestone("Got event: %1", @event)
break if Ops.get(@event, "ID") == :abort
Builtins.y2milestone(
"Tree selection: %1",
UI.QueryWidget(Id(:wizard), :CurrentItem)
)
end
UI.CloseDialog
nil
end
end
end
Yast::Wizard4Client.new.main

A tree widget provides a selection from a hierarchical tree structure. The semantics are very much like those of a SelectionBox. Unlike the SelectionBox, however, tree items may have subitems that in turn may have subitems etc.

Each item has a label string, optionally preceded by an ID. If the item has subitems, they are specified as a list of items after the string.

The tree widget will not perform any sorting on its own: The items are always sorted by insertion order. The application needs to handle sorting itself, if desired.

Note: The Qt version of the Wizard widget also provides a built-in tree with an API that is (sometimes) easier to use.


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