Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Perl Gtk2 - ->destroy() is Not Causing the Script to Exit

by mmartin (Monk)
on May 02, 2014 at 18:41 UTC ( #1084835=perlquestion: print w/ replies, xml ) Need Help??
mmartin has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Perl: Strawberry Perl 5.18 (*on Windows XP)

A few months ago I wrote a very large GUI program using Perl Gtk2 which still seems to be working just fine. But I'm now
creating a MUCH smaller GUI script that I really just want to display a Popup window to ask the User Yes Or No. If they select
"No" then the script SHOULD exit. I don't remember ever having this issue in my last GUI program, but it was a while ago now and
I'm pretty confused by this error, and why the script won't exit.

Here is my Gtk2 code. At first I just created a MessageDialog object with 'undef' as its parent but I was getting errors. The error
wasn't specifically towards the parent window, but I decided to create a $window object (*toplevel) anyway and I just don't ever
issue the "->show_all" function to display it...
#!/usr/bin/perl use strict; use warnings; use Gtk2 -init; use Glib qw/TRUE FALSE/; my $window = Gtk2::Window->new('toplevel'); $window->signal_connect(destroy => sub {Gtk2->main_quit;}); #<---ERROR ### $window->show_all; my $msg_dialog = Gtk2::MessageDialog->new_with_markup($window, 'modal' +, 'error', 'yes-no', "Would you like to retry the connection?"); $msg_dialog->set_title("No Connection Found"); $msg_dialog->set_destroy_with_parent(TRUE); $msg_dialog->signal_connect (response => sub { my ($self, $response) = @_; if ($response eq 'yes') { $msg_dialog->hide(); my_function("yes"); } elsif ($response eq 'no') { $msg_dialog->destroy(); $window->destroy; } }); $msg_dialog->run(); Gtk2->main; 0;

So when I execute the script, the MessageDialog opens just fine and I click the "No" button and I get the following error:

Gtk-CRITICAL **: gtk_main_quit: assertion `main_loops != NULL' failed at C:\Documents and Settings\Administrator\My Documents \ line 10.

Also, when the error gets displayed in the console window, the script basically just hangs until I do a Ctrl-C...

Anyone have any idea why this isn't working, am I missing something here?
Any thoughts or suggestions would be much appreciated, I'm not sure what else to try.

Thanks in Advance,

Comment on Perl Gtk2 - ->destroy() is Not Causing the Script to Exit
Download Code
Re: Perl Gtk2 - ->destroy() is Not Causing the Script to Exit
by mmartin (Monk) on May 02, 2014 at 20:19 UTC
    Humm... Well that's strange. If I remove the "signal_connect" statement for the $window object and leave everything else
    exactly how it is, the error goes away and it seems to be working just fine now. Anyone else think that's strange...?

    Since the issue SEEMS to be resolved I'm satisified with that, but I'm curious to know if anyone knows why I am getting that
    error with that line present. Was it deprecated or something like that..? I know I have that line in my other GUI program I
    mentioned in my OP and never saw that error... Weird!


Re: Perl Gtk2 - ->destroy() is Not Causing the Script to Exit
by sam_bakki (Pilgrim) on May 08, 2014 at 10:22 UTC

    Hi mmartin

    The below code also would fix your problem.

    $window->signal_connect(destroy => sub {Gtk2->main_quit() if (Gtk2->ma +in_level()); exit 0;}); #<---ERROR

    Thanks & Regards,
    Bakkiaraj M
    My Perl Gtk2 technology demo project - , contributions are welcome.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1084835]
Front-paged by GotToBTru
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-09-17 19:44 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (97 votes), past polls