Torsten Schönfeld > Gtk2-1.180 > xs/GtkMessageDialog.xs

Download:
Gtk2-1.180.tar.gz

Annotate this POD

CPAN RT

New  4
Open  4
View Bugs
Report a bug
Source   Latest Release: Gtk2-1.203

SYNOPSIS ^

  #
  # A modal dialog.  Note that the message is a printf-style format.
  #
  $dialog = Gtk2::MessageDialog->new ($main_application_window,
                                      'destroy-with-parent',
                                      'question', # message type
                                      'yes-no', # which set of buttons?
                                      "Pay me $%.2f?", $amount);
  $response = $dialog->run;
  if ($response eq 'yes') {
      send_bill ();
  }
  $dialog->destroy;

  #
  # A non-modal dialog.
  #
  $dialog = Gtk2::MessageDialog->new ($main_application_window,
                                      'destroy-with-parent',
                                      'question', # message type
                                      'ok-cancel', # which set of buttons?
                                      "Self-destruct now?");
  # react whenever the user responds.
  $dialog->signal_connect (response => sub {
             my ($self, $response) = @_;
             if ($response eq 'ok') {
                     do_the_thing ();
             }
             $self->destroy;
  });
  $dialog->show_all;

DESCRIPTION ^

Gtk2::MessageDialog is a dialog with an image representing the type of message (Error, Question, etc.) alongside some message text. It's simply a convenience widget; you could construct the equivalent of Gtk2::MessageDialog from Gtk2::Dialog without too much effort, but Gtk2::MessageDialog saves typing and helps create a consistent look and feel for your application.

The easiest way to do a modal message dialog is to use $dialog->run, which automatically makes your dialog modal and waits for the user to respond to it. You can also pass in the GTK_DIALOG_MODAL flag when creating the MessageDialog.