Re: dialog close signal and hiding dialog...



-- Ross McFarland <rwmcfa1 neces com> wrote
(on Tuesday, 12 August 2003, 12:35 PM -0400):
Matthew Weier OPhinney said:
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 as well as the response signal. I've determined that
closing the window sends a response of '-4', 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? Am I trying to re-display the
dialog correctly? Or do I need to post some code...? ;-)

it would be my guess that all of the widgets are getting the signal to be
destroyed and you're only preventing the dialog from being, not its contents.

ignoring the fact that it never exits the following code works:

use Gtk2 '-init';
my $dialog = Gtk2::Dialog->new (
                      "Test", undef, 'modal',
                      'gtk-cancel', 'cancel',
                      'gtk-ok', 'ok');
Glib::Timeout->add( 500, sub {
              $res = $dialog->run;
              $dialog->hide;
              print "$res\n";
              $res eq 'ok';
      });
Gtk2->main;

so long as you click ok the dialog will pop up every 1/2 second. if you click
cancle it won't any more. notice that run is blocking, hide causes the dialog
to disappear. i probably should have to be as complicated as what you were
describing.

if you're not using a Gtk::Dialog then i would suggest doing so as much of
what you're trying to deal with is handled for you with them.

I am using a GtkDialog. I've got two buttons configured, a "revert"
button and an "ok" button; they are set to send the response signals
'apply' and 'ok', respectively. Right now, I've got it set so that when
the 'apply' signal is received, it resets various widgets to the state
they were in when the dialog was created. When the 'ok' signal is
received, it saves the values represented by the widgets and hides the
dialog. Re-showing the dialog in this case works perfectly.

What *DOESN'T* work is when the user closes the window without using
these buttons. I've tried capturing the 'destroy' signal, but, as you
suggest, I believe that all the widgets are being destroyed, but the
window itself hidden. The corresponding code:

    $dialog->signal_connect("destroy" => sub {
        $dialog->hide;
        ... some other stuff here for cleanup
    }

When I then try and do a "$dialog->show", I get a segmentation fault. Is
there any way to prevent the widgets in the window getting destroyed?

-- 
Matthew Weier O'Phinney
http://weierophinney.net/matthew/



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