Module: UI::Greasemonkey

Extended by:
Yast::UIShortcuts
Includes:
Yast::UIShortcuts
Defined in:
library/general/src/lib/ui/greasemonkey.rb

Overview

UI layout helpers.

These started out in the Expert Partitioner in yast2-storage. The use case is reusing pieces of this legacy code in the new yast2-partitioner. That is why the API and the implementation look old.

Constant Summary

Builtins =
Yast::Builtins
Convert =
Yast::Convert
Ops =
Yast::Ops

Class Method Summary collapse

Class Method Details

.ComboBoxSelected(old) ⇒ Yast::Term

Examples:

term(
  :ComboBoxSelected,
  Id(:wish), Opt(:notify), "Wish",
  [
    Item(Id(:time), "Time"),
    Item(Id(:love), "Love"),
    Item(Id(:money), "Money")
  ],
  Id(:love)
)
  ->
ComboBox(
  Id(:wish), Opt(:notify), "Wish",
  [
    Item(Id(:time), "Time", false),
    Item(Id(:love), "Love", true),
    Item(Id(:money), "Money", false)
  ]
)

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'library/general/src/lib/ui/greasemonkey.rb', line 127

def ComboBoxSelected(old)
  args = Builtins.argsof(old)

  tmp = Builtins.sublist(args, 0, Ops.subtract(Builtins.size(args), 2))
  items = Ops.get_list(args, Ops.subtract(Builtins.size(args), 2), [])
  id = Ops.get_term(args, Ops.subtract(Builtins.size(args), 1), Id())

  items = Builtins.maplist(items) do |item|
    Item(Ops.get(item, 0), Ops.get(item, 1), Ops.get(item, 0) == id)
  end

  Builtins.toterm(:ComboBox, Builtins.add(tmp, items))
end

.FrameWithMarginBox(old) ⇒ Yast::Term

Examples:

term(:FrameWithMarginBox, "Title", "arg1", "arg2")
   ->
Frame("Title", MarginBox(1.45, 0.45, "arg1", "arg2"))

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


95
96
97
98
99
100
101
102
# File 'library/general/src/lib/ui/greasemonkey.rb', line 95

def FrameWithMarginBox(old)
  title = Ops.get_string(old, 0, "error")
  args = Builtins.sublist(Builtins.argsof(old), 1)
  Frame(
    title,
    Builtins.toterm(:MarginBox, Builtins.union([1.45, 0.45], args))
  )
end

.IconAndHeading(old) ⇒ Yast::Term

Examples:

term(:IconAndHeading, "title", "icon")
  ->
Left(
  HBox(
    Image("/usr/share/YaST2/theme/current/icons/22x22/apps/icon", ""),
    Heading("title")
  )
)

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


231
232
233
234
235
236
237
238
239
240
241
# File 'library/general/src/lib/ui/greasemonkey.rb', line 231

def IconAndHeading(old)
  args = Builtins.argsof(old)

  title = Ops.get_string(args, 0, "")
  icon = Ops.add(
    Ops.add(Yast::Directory.icondir, "22x22/apps/"),
    Ops.get_string(args, 1, "")
  )

  Left(HBox(Image(icon, ""), Heading(title)))
end

.LeftCheckBox(old) ⇒ Yast::Term

Examples:

term(:LeftCheckBox, Id(...), "args")
  ->
Left(CheckBox(Id(...), "args"))

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


187
188
189
# File 'library/general/src/lib/ui/greasemonkey.rb', line 187

def LeftCheckBox(old)
  Left(Builtins.toterm(:CheckBox, Builtins.argsof(old)))
end

.LeftCheckBoxWithAttachment(old) ⇒ Yast::Term

NOTE that it does not expand the nested Greasemonkey term LeftCheckBox! #transform does that.

Examples:

term(:LeftCheckBoxWithAttachment, "foo", "bar", "contents")
  ->
VBox(
  term(:LeftCheckBox, "foo", "bar"),
  HBox(HSpacing(4), "contents")
)

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'library/general/src/lib/ui/greasemonkey.rb', line 203

def LeftCheckBoxWithAttachment(old)
  args = Builtins.argsof(old)

  tmp1 = Builtins.sublist(args, 0, Ops.subtract(Builtins.size(args), 1))
  tmp2 = Ops.get(args, Ops.subtract(Builtins.size(args), 1))

  if tmp2 == Empty() # rubocop:disable Style/GuardClause
    return VBox(Builtins.toterm(:LeftCheckBox, tmp1))
  else
    return VBox(
      Builtins.toterm(:LeftCheckBox, tmp1),
      HBox(HSpacing(4), tmp2)
    )
  end
end

.LeftRadioButton(old) ⇒ Yast::Term

Examples:

term(:LeftRadioButton, Id(...), "args")
  ->
Left(RadioButton(Id(...), "args"))

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


148
149
150
# File 'library/general/src/lib/ui/greasemonkey.rb', line 148

def LeftRadioButton(old)
  Left(Builtins.toterm(:RadioButton, Builtins.argsof(old)))
end

.LeftRadioButtonWithAttachment(old) ⇒ Yast::Term

NOTE that it does not expand the nested Greasemonkey term LeftRadioButton! #transform does that.

Examples:

term(:LeftRadioButtonWithAttachment, "foo", "bar", "contents")
  ->
VBox(
  term(:LeftRadioButton, "foo", "bar"),
  HBox(HSpacing(4), "contents")
)

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'library/general/src/lib/ui/greasemonkey.rb', line 164

def LeftRadioButtonWithAttachment(old)
  args = Builtins.argsof(old)

  tmp1 = Builtins.sublist(args, 0, Ops.subtract(Builtins.size(args), 1))
  tmp2 = Ops.get(args, Ops.subtract(Builtins.size(args), 1))

  if tmp2 == Empty() # rubocop:disable Style/GuardClause
    return VBox(Builtins.toterm(:LeftRadioButton, tmp1))
  else
    return VBox(
      Builtins.toterm(:LeftRadioButton, tmp1),
      HBox(HSpacing(4), tmp2)
    )
  end
end

.Transform(old) ⇒ Yast::Term

Recursively apply all Greasemonkey methods on old

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


247
248
249
250
251
252
253
254
255
256
257
258
# File 'library/general/src/lib/ui/greasemonkey.rb', line 247

def Transform(old)
  s = Builtins.symbolof(old)

  handler = Greasemonkey.method(s) if @handlers.include?(s)
  return Transform(handler.call(old)) if !handler.nil?

  new = Builtins::List.reduce(Builtins.toterm(s), Builtins.argsof(old)) do |tmp, arg|
    arg = Transform(Convert.to_term(arg)) if Ops.is_term?(arg)
    Builtins.add(tmp, arg)
  end
  new
end

.transformYast::Term

Recursively apply all Greasemonkey methods on old

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


261
262
263
264
265
266
267
268
269
270
271
272
# File 'library/general/src/lib/ui/greasemonkey.rb', line 261

def Transform(old)
  s = Builtins.symbolof(old)

  handler = Greasemonkey.method(s) if @handlers.include?(s)
  return Transform(handler.call(old)) if !handler.nil?

  new = Builtins::List.reduce(Builtins.toterm(s), Builtins.argsof(old)) do |tmp, arg|
    arg = Transform(Convert.to_term(arg)) if Ops.is_term?(arg)
    Builtins.add(tmp, arg)
  end
  new
end

.VStackFrames(old) ⇒ Yast::Term

Wrap terms in a VBox with small vertical spacings in between.

Examples:

term(
  :VStackFrames,
  Frame("f1"),
  Frame("f2"),
  Frame("f3")
)
  ->
VBox(
  Frame("f1"),
  VSpacing(0.45),
  Frame("f2"),
  VSpacing(0.45),
  Frame("f3")
)

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'library/general/src/lib/ui/greasemonkey.rb', line 73

def VStackFrames(old)
  frames = Convert.convert(
    Builtins.argsof(old),
    from: "list",
    to:   "list <term>"
  )

  new = VBox()
  Builtins.foreach(frames) do |frame|
    new = Builtins.add(new, VSpacing(0.45)) if Builtins.size(new) != 0
    new = Builtins.add(new, frame)
  end
  new
end