Re: dialog close signal and hiding dialog...

On Tuesday, August 12, 2003, at 12:22  PM, Matthew Weier OPhinney wrote:

I've created an options dialog for an application, and I only want to
create it once per session. I've setup the GtkDialog to capture the
'close' signal

there is no 'close' signal. i think what you meant to type was 'delete-event'.

 as well as the response signal. I've determined that
closing the window sends a response of '-4',

i apologize that the response signal doesn't use the enums, but as i've mentioned before, it's out of my control because the signal is marshaled with an int. (but i'm still embarrassed about it, as it's something of a wart on gtk2-perl.) anyway....

 and I've setup both my
close and my response callbacks to do a "$dialog->hide" on receiving
such a signal. This works fine. It's when I try and open the dialog
again that I get an error. I try to show it using "$dialog->show", but
the window appears with now widgets, and I get a segmentation fault when
I close that window.

Am I capturing the signals correctly?

nope. the delete-event gets routed through response as a certain response code, but the event continues to propagate, resulting in the destruction of the window. you simply need to bind to delete-event a signal handler that returns TRUE, to stop the propagation.

Am I trying to re-display the
dialog correctly? Or do I need to post some code...? ;-)

here's some code, fresh out of vim and a test-run. if you try this, you should be able to resize the dialog, close it, and see it reappear at the same size. if you don't see this, i want to know about it. because i set a parent, the position will not stay the same --- gtk uses center-on-parent when you set_transient_for. then again, depending on your window manager, it may not stay the same anyway. (quartzwm with apple's X11 doesn't retain my window positions, for example.)

#!/usr/bin/perl -w

use Gtk2 -init;

my $win = Gtk2::Window->new;
$win->signal_connect (delete_event => sub { Gtk2->main_quit; 1; });
my $button = Gtk2::Button->new ('click me');
$button->signal_connect (clicked => \&do_dialog, $win);
$win->add ($button);


# we'll reuse one dialog, just showing and hiding it
$dialog = undef;

sub do_dialog {
        my ($widget, $parent) = @_;

        if (not defined $dialog) {
                $dialog = Gtk2::Dialog->new ('Test', $parent, 'modal',
                                             'gtk-cancel' => 'cancel',
                                             'gtk-ok' => 'ok');
                my $label = Gtk2::Label->new ('here i am, rock you like a hurricane');
                $dialog->vbox->add ($label);

                # inhibit destruction by pretending to handle delete-event
                $dialog->signal_connect (delete_event => sub {1});
                # handle the response, and hide the window, never destroy it
                $dialog->signal_connect (response => sub {
                                my ($self, $response) = @_;
                                print "response is $response\n";

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