class Demo::Dialog

Public Class Methods

new() click to toggle source
Calls superclass method Demo::BasicWindow::new
# File gtk2/sample/gtk-demo/builder.rb, line 14
def initialize
  super('Interface Builder')

  available = Gtk.check_version?(2, 12, 0)
  if available
    label = Gtk::Label.new("Build an interface from XML description.")
  else
    label = Gtk::Label.new("You need GTK+ >= 2.12.0 to run this demo.")
  end
  add(label)
  return unless available

  @builder = Gtk::Builder.new
  filename = File.join(File.dirname(__FILE__), "demo.ui")
  @builder << filename
  @builder.connect_signals {|name| method(name)}
  @window = @builder["window1"]
  @window.show_all

  signal_connect("destroy") do
    @window.destroy unless @window.destroyed?
  end
end

Public Instance Methods

interactive_dialog_clicked() click to toggle source
# File gtk2/sample/gtk-demo/dialog.rb, line 89
def interactive_dialog_clicked
  dialog = Gtk::Dialog.new('Interactive Dialog',
                           self,
                           Gtk::Dialog::MODAL |
                           Gtk::Dialog::DESTROY_WITH_PARENT,
                           [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK],
                           ["_Non-stock Button", Gtk::Dialog::RESPONSE_CANCEL]
                           )

  hbox = Gtk::HBox.new(false, 0)
  hbox.set_border_width(8)
  dialog.vbox.pack_start(hbox, false, false, 0)

  stock = Gtk::Image.new(Gtk::Stock::DIALOG_QUESTION, Gtk::IconSize::DIALOG)
  hbox.pack_start(stock, false, false, 0)

  table = Gtk::Table.new(2, 2, false)
  table.set_row_spacings(4)
  table.set_column_spacings(4)
  hbox.pack_start(table, true, true, 0)
  label = Gtk::Label.new('_Entry 1', true)
  table.attach_defaults(label,
                        0, 1, 0, 1)
  local_entry1 = Gtk::Entry.new
  local_entry1.text = @entry1.text
  table.attach_defaults(local_entry1, 1, 2, 0, 1)
  label.set_mnemonic_widget(local_entry1)

  label = Gtk::Label.new('E_ntry 2', true)
  table.attach_defaults(label,
                        0, 1, 1, 2)

  local_entry2 = Gtk::Entry.new
  local_entry2.text = @entry2.text
  table.attach_defaults(local_entry2, 1, 2, 1, 2)
  label.set_mnemonic_widget(local_entry2)

  hbox.show_all
  response = dialog.run
  
  if response == Gtk::Dialog::RESPONSE_OK 
    @entry1.text = local_entry1.text
    @entry2.text = local_entry2.text
  end
  dialog.destroy
end
message_dialog_clicked() click to toggle source
# File gtk2/sample/gtk-demo/dialog.rb, line 72
    def message_dialog_clicked
      dialog = Gtk::MessageDialog.new(self,
                                      Gtk::Dialog::MODAL |
                                      Gtk::Dialog::DESTROY_WITH_PARENT,
                                      Gtk::MessageDialog::INFO,
                                      Gtk::MessageDialog::BUTTONS_OK,
                                      <<EOS)
This message box has been popped up the following
number of times:

#{@count}
EOS
      dialog.run
      dialog.destroy
      @count += 1
    end