Class: MittensUi::Alert

Inherits:
Object
  • Object
show all
Defined in:
lib/mittens_ui/alert.rb

Instance Method Summary collapse

Constructor Details

#initialize(message, options = {}) ⇒ Alert

Returns a new instance of Alert.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mittens_ui/alert.rb', line 3

def initialize(message, options={})
  dialog_options = {
    title: options[:title] || "Alert",
    parent: $app_window,
    flags: [:modal, :destroy_with_parent],
    :buttons => [[Gtk::Stock::OK, :none]]
  }.freeze

  @alert_dialog = Gtk::Dialog.new(dialog_options)
  @alert_dialog.set_transient_for($app_window)
  @alert_dialog.set_default_width(420)
  @alert_dialog.set_default_height(200)
  @alert_dialog.set_modal(true)
  @alert_dialog.set_resizable(false)

  message_label = Gtk::Label.new(message)
  message_label.set_margin_top(36)

  dialog_box = @alert_dialog.content_area
  dialog_box.add(message_label)
end

Instance Method Details

#renderObject



25
26
27
28
29
# File 'lib/mittens_ui/alert.rb', line 25

def render
  @alert_dialog.show_all
  response = @alert_dialog.run
  response == :none ? @alert_dialog.destroy : @alert_dialog.destroy
end