Re: Glade dialogs or Gtk2::MessageDialog




Martin Junius said:
in an application using a Glade GUI I need to add some error message and
confirmation dialogs.

What's the canonical way to do this? Designing the dialogs in glade?
Advantages? Or simply using Gtk2::Dialog and Gtk2::MessageDialog? In
particular MessageDialog seems way easier for output of a quick message.

Use MessageDialog for alerts, and for simple text-only questions.  It's much
easier, and far more consistent with both your own app and the platform.  For
more complicated dialogs it's whatever you like (but use the Dialog base, not
a plain Window).

I usually put together convenient one-liners for my apps (and in a library
common to others) to keep things consistent and compact.


(cut & paste)

  sub confirm {
      my ($parent, $question, $verb, $default) = @_;
      my $dialog = Gtk2::MessageDialog->new ($parent, [], 'question', 'none',
                                             $question);
      $dialog->add_buttons ("Don't $verb" => 'reject',
                            "$verb" => 'accept');
      $dialog->set_default_response ($default || 'reject');
      my $response = $dialog->run;
      $dialog->destroy;
      return 'accept' eq $response;
  }

...

  $main_window->signal_connect (destroy => sub { Gtk2->main_quit });
  $main_window->signal_connect (delete_event => sub {
      my ($win) = @_;
      # return TRUE to inhibit destruction of the window.
      return ! confirm ($win, "Are you sure you want to quit?", "Quit");
  });



-- 
muppet <scott at asofyet dot org>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]