mmartin has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have a Perl script using Gtk2 to create a UI for the user. In the snippet of code below I took from my script, I create
a MessageDialog then below that is the function that gets call when someone clicks my "submit" button in my main "parent"
window called "$window".

Now I create the MessageDialog outside the function so that I can use the same MessageDialog window for a number of different
situations so I don't have to keep creating new one's over and over...

So let's say the user entered the wrong data into an entry field in my parent window, then they click submit. So then my "submit_function()"
get called and in it I check the User's input, and if the input doesn't match my REGEX then I set the Text for the dialog, then run it.

#......... #:............ # Other code above here which creates the parent window which includes + a submit button... #:............ #......... # Create a Gtk2::MessageDialog to show Errors/Warnigns in: my $dialog_msgString = ""; my $msg_dialog = Gtk2::MessageDialog->new_with_markup($window, 'modal' +, 'warning', 'ok', $dialog_msgString); $msg_dialog->signal_connect (response => sub { my ($self, $response) = @_; if ($response eq 'ok') { print "*YOU CLICKED OK\n\n"; $msg_dialog->destroy(); } }); ### This will get Executed when the 'clicked' signal is caught for the + "$submit_button": sub submit_function() { my $endTime = $entry_field->get_text(); # If the endTime does NOT match the REGEX, then... if ($endTime !~ /^[0-9]{1,}$/i) { $msg_dialog->set_markup("<span size='11000'>Warning: The time +you entered is incorrect, numbers only!</span>"); $msg_dialog->run(); } } ### This will get Executed when the 'clicked' signal is # caught for the "$cancel_button": sub cancel_function() { print "\n\n\n${BOLD_RED}*YOU CLICKED THE 'CANCEL' BUTTON!!\n\t*EXI +TING NOW....${OFF}\n\n"; exit 101; } ### When control reaches here GTK will sleep and wait for X Events Gtk2->main; 0;


Ok, so I hope I didn't leave out anything important from the script, but above is basically what's needed to know the error I think...

So what happens is when I click the submit button and the user's input didn't match the REGEX, I set_markup() for the MessageDialog then
issue the "run()" method to show the dialog. This part works fine...
But then if I still entered the incorrect data into the $entry_field and click submit again, the parent window closes and the script exits
with the error below...

        Gtk-CRITICAL **: IA__gtk_label_set_markup: assertion `GTK_IS_LABEL (label)' failed at ./test_GUI line 586.

            *Line 586 is the line with "$msg_dialog->set_markup(.....);" in the submit_function() Function.

Anyone know why I would be getting this Error ONLY on the second time it gets executed and NOT on the first call of set_markup()??
Any thoughts would be much appreciated!

Thanks in Advance,
Matt


  • Comment on Gtk2::MessageDialog Getting Error while using "set_markup()" Method
  • Download Code

Replies are listed 'Best First'.
Re: Gtk2::MessageDialog Getting Error while using "set_markup()" Method
by mmartin (Monk) on Jun 26, 2013 at 21:36 UTC
    Ahh Jeezz, sorry guys I think I figured it out..

    I think it was because I was destroying the Dialog, so when it tried to run the second time it couldn't
    because it was already destroyed...

    So if I change the line that removes the dialog and change it to hide then it doesn't exit with an error anymore!

            FROM THIS --> $msg_dialog->destroy();
            TO THIS --> $msg_dialog->hide();

    If I change it to the above I don't get the error anymore...

    I'll post back if I jumped the gun on it being solved, but otherwise thanks anayway...


    Thanks Again,
    Matt