Class: Yast2::Feedback

Inherits:
Object
  • Object
show all
Includes:
Yast::UIShortcuts
Defined in:
library/general/src/lib/yast2/feedback.rb

Overview

Class to show some feedback when doing time consuming operation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.show(message, headline: "") {|feedback| ... } ⇒ Object

Shows a feedback popup while the given block is running.

Parameters:

  • message (String)

    message to show. The only mandatory argument.

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

    popup headline. If "", no headline is shown.

Yields:

  • runs time consuming operation

Yield Parameters:

Returns:

  • the result of the block



16
17
18
19
20
21
22
23
24
# File 'library/general/src/lib/yast2/feedback.rb', line 16

def show(message, headline: "", &block)
  feedback = new
  feedback.start(message, headline: headline)
  begin
    block.call(feedback)
  ensure
    feedback.stop
  end
end

Instance Method Details

#start(message, headline: "") ⇒ Object

Starts showing feedback. Finish it with #stop. Non-block variant of #show.

Parameters:

  • message (String)

    message to show

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

    sets popup headline. String is shown. If empty string is passed no headline is shown.



38
39
40
41
42
43
# File 'library/general/src/lib/yast2/feedback.rb', line 38

def start(message, headline: "")
  check_params!(message, headline)

  res = Yast::UI.OpenDialog(content(message, headline))
  raise "Failed to open dialog, see logs." unless res
end

#stopObject

Stops showing feedback. Use together with ##start.

Raises:

  • (RuntimeError)

    when feedback was not started or another dialog is open on top of it.

See Also:

  • Yast2::Feedback.{Feedback{Feedback.show}


48
49
50
51
52
# File 'library/general/src/lib/yast2/feedback.rb', line 48

def stop
  raise "Trying to stop feedback, but dialog is not feedback dialog" if !Yast::UI.WidgetExists(Id(MESSAGE_ID))

  Yast::UI.CloseDialog
end

#update(message, headline: "") ⇒ Object

Updates feedback message. Headline can be modified only if initial feedback have non-empty feedback.

Parameters:

  • message (String)

    message to show. The only mandatory argument.

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

    headline to show. Only if original feedback have headline.

Raises:

  • ArgumentError when headline is not empty, but original feedback have it empty.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'library/general/src/lib/yast2/feedback.rb', line 59

def update(message, headline: "")
  check_params!(message, headline)

  if !headline.empty?
    if Yast::UI.WidgetExists(Id(HEADLINE_ID))
      Yast::UI.ChangeWidget(Id(HEADLINE_ID), :Value, headline)
    else
      raise ArgumentError,
        "Headline is not empty for feedback, but original feedback does not have it."
    end
  end
  Yast::UI.ChangeWidget(Id(MESSAGE_ID), :Value, message)
  Yast::UI.RecalcLayout
end