class Interphase::Dialog

A base class representing a simple, blank dialog box.

Public Class Methods

new(instance = nil, **options, &block) click to toggle source

Construct a new blank dialog box.

Calls superclass method Interphase::Widget::new
# File lib/interphase/widgets/dialog.rb, line 9
def initialize(instance = nil, **options, &block)
  super(instance || Gtk::Dialog.new, **options, &block)

  options['buttons']&.map { |btn| add_button(*btn) }
end

Public Instance Methods

action_to_integer(action) click to toggle source

Converts an #add_button action symbol to the GTK RESPONSE integer which it represents.

action

The action symbol to convert. Should be one of the valid values of action to #add_button.

# File lib/interphase/widgets/dialog.rb, line 19
def action_to_integer(action)
  valid_actions =
    %i[none reject accept delete ok cancel close yes no apply help]

  throw ArgumentError, 'Invalid button action' \
    unless valid_actions.include? action

  # Map :delete to its GTK equivalent
  action = :delete_event if action == :delete

  Gtk::Dialog.const_get("RESPONSE_#{action.to_s.upcase}")
end
add_button(text, action) click to toggle source

Adds a button to the dialog box.

text

The text to display on the button.

action

The action which occurs when this button is clicked. Must be one of: :none, :reject, :accept, :delete, :ok, :cancel, :close, :yes, :no, :apply, :help.

# File lib/interphase/widgets/dialog.rb, line 37
def add_button(text, action)
  gtk_instance.add_button(text, action_to_integer(action))
  nil
end
run() click to toggle source

Run this dialog box. This call will block execution until the dialog is closed. Consider using +Window#in_background+ if blocking is not desired. You should usually call destroy after this method, otherwise the dialog will remain even after selecting an option.

# File lib/interphase/widgets/dialog.rb, line 46
def run
  gtk_instance.run
end