Class: Yast2::Popup

Inherits:
Object
  • Object
show all
Extended by:
Yast::I18n, Yast::UIShortcuts
Defined in:
library/general/src/lib/yast2/popup.rb

Overview

Note:

as the UI is not easy to test, it is recommended to run `examples/popup_series_tester.sh` after modifying this code, to tests common combinations of options.

Note:

for RSpec tests, `require “yast2/popup_rspec”` for easier mocking that still does argument verifications.

Class responsible for showing popups. It has a small but consistent API. Intended as a replacement for Yast::Popup module.

Constant Summary collapse

LINES_THRESHOLD =

Number of lines to switch to richtext widget for richtext: false

20
RICHTEXT_WIDTH =
60
RICHTEXT_HEIGHT =
10

Class Method Summary collapse

Class Method Details

.show(message, details: "", headline: "", timeout: 0, focus: nil, buttons: :ok, richtext: false, style: :notice) ⇒ Symbol

Show a popup, wait for a button press (or a timeout), return the button ID.

Examples:

pair of old and new API calls

Yast::Popup.Message(text)
Yast2::Popup.show(text)

Yast::Popup.MessageDetails(text, details)
Yast2::Popup.show(text, details: details)

Yast::Popup.TimedError(text, seconds)
Yast2::Popup.show(text, headline: :error, timeout: seconds)

Yast::Popup.TimedErrorAnyQuestion(headline, message, yes_button_message, no_button_message,
  focus, timeout_seconds)
Yast2::Popup.show(message, headline: headline, timeout: timeout_seconds,
  buttons: { yes: yes_button_message, no: no_button_message), focus: :yes)

Yast::Popup.TimedLongNotify(message, timeout_seconds)
Yast2::Popup.show(message, richtext: true, timeout: timeout_seconds)


75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'library/general/src/lib/yast2/popup.rb', line 75

def show(message, details: "", headline: "", timeout: 0, focus: nil, buttons: :ok, richtext: false, style: :notice)
  textdomain "base"
  buttons = generate_buttons(buttons)
  headline = generate_headline(headline)
  # add default focus button before adding details, as details should not be focussed
  focus = buttons.keys.first if focus.nil?
  add_details_button(buttons) unless details.empty?
  add_stop_button(buttons) if timeout > 0
  check_arguments!(message, details, timeout, focus, buttons)
  content_res = content(body(headline, message, richtext, timeout), buttons)

  event_loop(content_res, focus, timeout, details, style)
end