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



177
178
179
# File 'library/general/src/modules/Icon.rb', line 177

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

#IconPath(icon_type) ⇒ Object

Returns path to an image

Icon::IconPath (“warning”) -> “/usr/share/YaST2/theme/current/icons/32x32/apps/msg_warning.png”

Parameters:

See Also:

  • for details


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'library/general/src/modules/Icon.rb', line 80

def IconPath(icon_type)
  LazyInit()

  icon_path = nil

  if Ops.get(@icons_map, icon_type)
    icon_path = Ops.add(
      @icon_32x32_path,
      Ops.get(@icons_map, icon_type, "")
    )
  else
    icon_path = Ops.add(Ops.add(@icon_32x32_path, icon_type), ".png")
    Builtins.y2debug(
      "Image '%1' is not defined, using '%2'",
      icon_type,
      icon_path
    )
  end

  icon_path
end

#Image(icon_type, options) ⇒ Object

Returns `Image() term defined by parameters. Returns `Empty() 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})


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'library/general/src/modules/Icon.rb', line 129

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)

  this_image = term(:Image, Id(icon_id), IconPath(icon_type), 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))
    )

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

#InfoYast::Term

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

Returns:

  • (Yast::Term)

    info icon



184
185
186
# File 'library/general/src/modules/Icon.rb', line 184

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

#LazyInitObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'library/general/src/modules/Icon.rb', line 47

def LazyInit
  return if !@has_image_support.nil?

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

  @icon_32x32_path = Ops.add(
    Directory.themedir,
    "/current/icons/32x32/apps/"
  )

  @icons_map = {
    "warning"  => "msg_warning.png",
    "info"     => "msg_info.png",
    "error"    => "msg_error.png",
    "question" => "msg_question.png"
  }

  nil
end

#mainObject



35
36
37
38
39
40
41
42
43
44
45
# File 'library/general/src/modules/Icon.rb', line 35

def main
  Yast.import "UI"

  textdomain "base"

  Yast.import "Directory"

  @has_image_support = nil
  @icons_map = {}
  @icon_32x32_path = nil
end

#Simple(icon_type) ⇒ Object

Function calls Icon::Image with default options

Parameters:

See Also:



163
164
165
# File 'library/general/src/modules/Icon.rb', line 163

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

#WarningYast::Term

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

Returns:

  • (Yast::Term)

    warning icon



170
171
172
# File 'library/general/src/modules/Icon.rb', line 170

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