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
\test_gtk.pl 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,
Matt
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.