I used Glade to set up the GUI for my PHP-GTK app. Everything works fine, except for closing and re-opening a GtkDialog that gets opened when clicking a button in my main window.
In my .glade-File:
<widget class="GtkDialog" id="helpwindow">
.....
</widget>
In my .phpw-File:
<?php
function onHelpClicked()
{
global $window;
$window->get_widget('helpwindow')->show_all();
}
function onCloseHelpClicked()
{
global $window;
$window->get_widget('helpwindow')->hide_all();
}
?>
onHelpClicked() is linked to the Help button in the main window; onCloseHelpClicked() is linked to a Cancel button in the help window. Both buttons do what I expect them to do, however, when I close the help window by pushing the Esc key on the keyboard (or with the window's X button), I am not able to re-open it using the Help button - instead the app freezes and I get "Call to a member function show_all() on a non-object in ......... on line ....." (the line number is the one with show_all() in my function onHelpClicked() ).
What is the correct way to open a dialog defined in a .glade file and close it and be able to re-open it?
Well, I solved it: Simply
Well, I solved it:
Simply move the
<widget class="GtkDialog" id="helpwindow">.....
</widget>
to a separate .glade file and replace the two functions with:
<?php
function onHelpClicked()
{
$GLOBALS["helpwindow"] = new GladeXML('awks_client_help.glade');
$GLOBALS["helpwindow"]->signal_autoconnect();
$GLOBALS["helpwindow"]->get_widget('helpsubmit')->connect_simple('clicked', 'onSubmitHelpClicked', $GLOBALS["helpwindow"]->get_widget('helpmessage'));
}
function onCloseHelpClicked()
{
$GLOBALS["helpwindow"]->get_widget('helpwindow1')->destroy();
}
?>