Class: UI::Dialog

Inherits:
Object
  • Object
show all
Includes:
EventDispatcher, Yast::I18n, Yast::Logger, Yast::UIShortcuts
Defined in:
library/general/src/lib/ui/dialog.rb

Overview

Base class for dialogs in Yast. Includes useful modules and provides glue between them

Examples:

simple OK/cancel dialog

class OKDialog < UI::Dialog
  def initialize
    super
    textdomain "example"
  end

  def dialog_content
    HBox(
      PushButton(Id(:ok), _("OK")),
      PushButton(Id(:cancel), _("Cancel"))
    )
  end

  def ok_handler
    finish_dialog(:ok)
    log.info "OK button pressed"
  end
end

# run dialog
OKDialog.run

Direct Known Subclasses

InstallationDialog

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EventDispatcher

#cancel_handler, #event_loop, #finish_dialog, #user_input

Constructor Details

#initializeDialog


45
46
47
# File 'library/general/src/lib/ui/dialog.rb', line 45

def initialize
  Yast.import "UI"
end

Class Method Details

.runObject

Runs dialog and return value of last handler from EventDispatcher


41
42
43
# File 'library/general/src/lib/ui/dialog.rb', line 41

def self.run
  new.run
end

Instance Method Details

#close_dialogObject (protected)


70
71
72
# File 'library/general/src/lib/ui/dialog.rb', line 70

def close_dialog
  Yast::UI.CloseDialog
end

#create_dialogObject (protected)


61
62
63
64
65
66
67
68
# File 'library/general/src/lib/ui/dialog.rb', line 61

def create_dialog
  dialog_opts = dialog_options
  if dialog_opts
    Yast::UI.OpenDialog(dialog_opts, dialog_content)
  else
    Yast::UI.OpenDialog(dialog_content)
  end
end

#dialog_contentYast::Term (protected)

Abstract method to specify content of dialog.

Raises:

  • (NoMethodError)

    if not implemented

See Also:


83
84
85
# File 'library/general/src/lib/ui/dialog.rb', line 83

def dialog_content
  raise NoMethodError, "Missing implementation for abstract method dialog content for #{self}"
end

#dialog_optionsYast::Term? (protected)

Optional abstract method to specify options for dialog.


77
# File 'library/general/src/lib/ui/dialog.rb', line 77

def dialog_options; end

#runObject


49
50
51
52
53
54
55
56
57
# File 'library/general/src/lib/ui/dialog.rb', line 49

def run
  raise "Failed to create dialog. See logs" unless create_dialog

  begin
    event_loop
  ensure
    close_dialog
  end
end