Class: Yast::IconClass

Inherits:
Module
  • Object
show all
Defined in:
library/general/src/modules/Icon.rb

Instance Method Summary collapse

Instance Method Details

#ErrorYast::Term

Returns UI term `Image() widget with an error-icon.

Returns:

  • (Yast::Term)

    error-icon



139
140
141
# File 'library/general/src/modules/Icon.rb', line 139

def Error
  Image("error", {})
end

#Image(icon_type, options) ⇒ Object

Returns Image() term defined by parameters. ReturnsEmpty() if the current UI doesn't support images.

Structure:

options = $[
   "id" : any_icon_id,
   "label" : (string) icon_label, // (used if icon is missing)
   "margin_left" : 0,  // HSpacing on the left
   "margin_right" : 5, // HSpacing on the right
 ]

Examples:

Icon::Image ("warning", $["id":`my_warning, "label":_("My Warning")])
  -> `Image (`id (`my_warning), "/usr/share/YaST2/theme/current/icons/32x32/apps/msg_warning.png", "My Warning")
Icon::Image ("info", $["margin_left":1, "margin_right":2])
  -> `HBox (
    `HSpacing (1),
    `Image (`id ("icon_id_info"), "/usr/share/YaST2/theme/current/icons/32x32/apps/msg_info.png", "info"),
    `HSpacing (2)
  )

Parameters:

  • icon_type (String)

    (one of known types or just an image name without a 'png' suffix) Known icon types are "warning", "info", and "error"

  • options (Hash{String => Object})


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'library/general/src/modules/Icon.rb', line 89

def Image(icon_type, options)
  options = deep_copy(options)
  LazyInit()

  return Empty() if !@has_image_support

  icon_id = Ops.get(options, "id")
  icon_id = Builtins.sformat("icon_id_%1", icon_type) if icon_id.nil?

  icon_label = Ops.get_string(options, "label", icon_type)

  icon_name = Ops.get(@icons_map, icon_type) ? Ops.get(@icons_map, icon_type, "") : icon_type

  this_image = term(:Image, Id(icon_id), icon_name, icon_label)

  # left and/or right margin defined
  if Ops.get_integer(options, "margin_left", 0) != 0 ||
      Ops.get_integer(options, "margin_right", 0) != 0
    ret = HBox(
      HSpacing(Ops.get_integer(options, "margin_left", 0)),
      this_image,
      HSpacing(Ops.get_integer(options, "margin_right", 0))
    )

    deep_copy(ret)
    # no margin defined
  else
    deep_copy(this_image)
  end
end

#InfoYast::Term

Returns UI term `Image() widget with an info-icon.

Returns:

  • (Yast::Term)

    info icon



146
147
148
# File 'library/general/src/modules/Icon.rb', line 146

def Info
  Image("info", {})
end

#LazyInitObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'library/general/src/modules/Icon.rb', line 42

def LazyInit
  return if !@has_image_support.nil?

  display_info = UI.GetDisplayInfo
  @has_image_support = Ops.get_boolean(
    display_info,
    "HasImageSupport",
    false
  )

  @icons_map = {
    "warning"  => "dialog-warning",
    "info"     => "dialog-information",
    "error"    => "dialog-error",
    "question" => "dialog-question"
  }

  nil
end

#mainObject



33
34
35
36
37
38
39
40
# File 'library/general/src/modules/Icon.rb', line 33

def main
  Yast.import "UI"

  textdomain "base"

  @has_image_support = nil
  @icons_map = {}
end

#Simple(icon_type) ⇒ Object

Function calls Icon::Image with default options

Parameters:

See Also:



125
126
127
# File 'library/general/src/modules/Icon.rb', line 125

def Simple(icon_type)
  Image(icon_type, {})
end

#WarningYast::Term

Returns UI term `Image() widget with a warning-icon.

Returns:

  • (Yast::Term)

    warning icon



132
133
134
# File 'library/general/src/modules/Icon.rb', line 132

def Warning
  Image("warning", {})
end