Re: dialog close signal and hiding dialog...



-- Matthew Weier OPhinney <matthew-lists weierophinney net> wrote
(on Tuesday, 12 August 2003, 07:22 PM -0400):
-- 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. 
<snip>
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.
<snip>
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?

Okay, I figured out what I needed to do. The dialog is actually being
called as part of another class, something like this:

    package ROX;
    sub edit_options {
        my $dialog = ROX::OptionsBox->new(...some options);
        $dialog->show; # where show is a routine in ROX::OptionsBox
    }

    package ROX::OptionsBox;
    do a bunch of stuff related to creating and manipulating dialog

The solution I discovered was to add the following to the ROX package:

    $dialog->dialog->signal_connect(
        destroy => sub {
            ... some cleanup ...
            undef $dialog;
        }
    );

($dialog->dialog is the actual GtkDialog object). As you can see, I'm
destroying the entire object I've created; it then gets recreated next
time I need the dialog. I'd _prefer_ to be able to keep it around for
later (as I'm able to do when I click the 'Ok' button and do a
$dialog->hide); however, this works, and I no longer get the
segmentation faults.

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



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