Skip to content

Commit

Permalink
new generation of popup library
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Nov 10, 2017
1 parent f38c87b commit 14495c1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
42 changes: 42 additions & 0 deletions library/general/example/popup_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require "yast"

require "yast2/popup"

Yast.import "UI"

include Yast::UIShortcuts

def code(params)
"Yast2::Popup.show(#{params})"
end

content = VBox(
InputField(Id(:params), Opt(:notify), "Popup Params:"),
VSpacing(1),
InputField(Id(:code), Opt(:disable), "Code to run:"),
VSpacing(1),
PushButton(Id(:call), "Show")
)

Yast::UI.OpenDialog(content)
loop do
ret = Yast::UI.UserInput
case ret
when :params
value = Yast::UI.QueryWidget(:params, :Value)
Yast::UI.ChangeWidget(:code, :Value, code(value))
when :cancel
break
when :call
begin
value = Yast::UI.QueryWidget(:params, :Value)
eval (code(value))
rescue => e
Yast2::Popup.show("Failed with #{e.message}")
end
end
end

Yast::UI.CloseDialog

nil
1 change: 1 addition & 0 deletions library/general/example/popup_tester.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Y2DIR=$(dirname "$0")/../src /sbin/yast2 $(dirname "$0")/popup_params.rb
6 changes: 5 additions & 1 deletion library/general/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ ylib2_DATA = \
lib/ui/text_helpers.rb \
lib/ui/widgets.rb

EXTRA_DIST = $(module_DATA) $(client_DATA) $(scrconf_DATA) $(agent_SCRIPTS) $(ydata_DATA) $(fillup_DATA) $(ylib_DATA) $(ylib2_DATA)
ylib3dir = "${yast2dir}/lib/yast2"
ylib3_DATA = \
lib/yast2/popup.rb

EXTRA_DIST = $(module_DATA) $(client_DATA) $(scrconf_DATA) $(agent_SCRIPTS) $(ydata_DATA) $(fillup_DATA) $(ylib_DATA) $(ylib2_DATA) $(ylib3_DATA)


include $(top_srcdir)/Makefile.am.common
38 changes: 38 additions & 0 deletions library/general/src/lib/yast2/popup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Yast2
class Popup
class << self
# Shows popup and return which symbol of pressed button
# @param message [String] message to show
# @param details [String, nil] hidden details that can be shown, if nil do not show
# @param headline [Symbol, String] sets popup headline. String is shown and there is
# predefined sets of symbols for common headlines. Set contain `:error`, `:warning`
# @param timeout [Integer] how long wait till autoclose dialog. 0 means wait forever.
# @param buttons [Hash<Symbol, String>, Symbol] specified which buttons popup will have.
# it can be hash in format button_id => button_text, showed in same order as in hash.
# The second option is symbol that specify one of predefined set of buttons.
# Current set of predefined buttons are `:ok`, `:yes_no`, `:ok_cancel`
# @param focus [Symbol, nil] what button focus.
# Also it is button which is returned if timeout exceed.
# if it is nil, then choose the first button. See buttons parameter.
# @param richtext [Boolean] if use richtext widget.
# Useful when report contain richtext tags or is long, so it have to be scrollable.
#
# @example 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)
def show(message, details: nil, headline: "", timeout: 0, focus: nil, buttons: :ok, richtext: false)
end
end
end

0 comments on commit 14495c1

Please sign in to comment.