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
LABEL_MINWIDTH =

Minimum width for auto wrapped labels. This value is used when the label has longer lines.

60

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)

Parameters:

  • message (String)

    message to show. The only mandatory argument.

  • details (String) (defaults to: "")

    details that will be shown in another popup on pressing a "Details..." button. ("" -> no button)

  • headline (String, :error, :warning) (defaults to: "")

    sets popup headline. A String is shown as is ("" -> no headline shown). :error and :warning produce the corresponding translated string. Note: a Symbol means just predefined strings, not affecting popup style.

  • timeout (Integer) (defaults to: 0)

    how many seconds until autoclosing. 0 means forever.

  • buttons (Hash<Symbol, String>, Symbol) (defaults to: :ok)

    buttons shown.

    • Explicit way: a Hash button_id => button_text, shown in source code order. Beware that symbols starting with :__ are reserved.
    • Shorthand way: a Symbol, one of:
      • :ok -> { ok: Label.OKButton}
      • :continue_cancel -> { continue: Label.ContinueButton, cancel: Label.CancelButton }
      • :yes_no -> { yes: Label.YesButton, no: Label.NoButton }
  • focus (Symbol, nil) (defaults to: nil)

    which button gets the focus. Also it is the button which is returned if the timeout is exceeded. nil means the first button. See buttons parameter.

  • richtext (Boolean) (defaults to: false)

    whether to interpret richtext tags in message. If it it true, then always Richtext widget is used. If it is false, for short text Label widget is used and for long text Richtext widget is used, but richtext tags are not interpreted.

  • style (:notice, :important, :warning) (defaults to: :notice)

    popup dialog styling. :notice is common one, :important is brighter and :warning is style when something goes wrong. See Yast::UI.OpenDialog options :infocolor and :warncolor.

Returns:

  • (Symbol)

    symbol of pressed button. If timeout appear, then button set in focus parameter is returned. If user click on 'x' button in window then :cancel symbol is returned.



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'library/general/src/lib/yast2/popup.rb', line 79

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