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 collapse

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)


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

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)


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

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)


229
230
231
232
233
234
235
236
# File 'library/general/src/lib/ui/greasemonkey.rb', line 229

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

  title = Ops.get_string(args, 0, "")
  icon = 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)


185
186
187
# File 'library/general/src/lib/ui/greasemonkey.rb', line 185

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)


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

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()
    VBox(Builtins.toterm(:LeftCheckBox, tmp1))
  else
    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)


146
147
148
# File 'library/general/src/lib/ui/greasemonkey.rb', line 146

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)


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

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()
    VBox(Builtins.toterm(:LeftRadioButton, tmp1))
  else
    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)


242
243
244
245
246
247
248
249
250
251
252
# File 'library/general/src/lib/ui/greasemonkey.rb', line 242

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

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

  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
end

.transformYast::Term

Recursively apply all Greasemonkey methods on old

Parameters:

  • old (Yast::Term)

Returns:

  • (Yast::Term)


255
256
257
258
259
260
261
262
263
264
265
# File 'library/general/src/lib/ui/greasemonkey.rb', line 255

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

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

  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
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)


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

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