Re: cancel gtk_main_quit and return to the main window





There are some subtle differences involving
delete_event
destroy
Gtk2->main_quit;
exit
return 1 or 0 from callbacks
etc, etc.

the problem is, as far as I understand it, that I create a gtk obejct from
glade. when I hit the [x] button on the window (window1::gtk_main_quit )
the gtk widget ($Gtk2->{Gtk2Main}) related to this window seems to die. I
want to cancel it so I call a function quit which returns true if data is
saved and false if data is modified but not stored.
Doesn't really matter, but when it receives false from quit() and I call
show an empty gray window appears.


So if you could post your code, or a small working example to demo the
problem, someone could set it right.


Basically I was thinking to recreate the window (using destroy and new), but
destroying the first window/gtk object it destroys also the notebook as
being part of the widget (window1), so I was thinking to put the notebook
into a separate widget and pack it into the window ... eventually I didn't
really know how to do it and may be there is a standard way, what I've
tried didn't work, and google or whatever couldn't help ... so I asked the
community now and hope you can just opint me to a good document I can read,
thanks!

so basically the question is how can I keep a (glade) widget alive after
gtk_main_quit is called. I've seen people recreateing the widget but then
how should I fill up the interface with the data I have ... there should be
a standard way

here is some code


...
...
   my $Gtk2 = {}; #ref to hold gtk items
   $Gtk2->{Gtk2Main}       = Gtk2::GladeXML->new( 'ui.glade' );
   $Gtk2->{MainWindow}     = $Gtk2->{Gtk2Main}->get_widget('window1');
   $Gtk2->{Gtk2Main}->signal_autoconnect_from_package('window1');
   $Gtk2->{Notebook}       = $Gtk2->{Gtk2Main}->get_widget('notebook1');

   $Gtk2->{Gtk2SaveAllWin} = Gtk2::GladeXML->new(  'ui.glade'  );
   $Gtk2->{SaveAllWindow}  =
$Gtk2->{Gtk2SaveAllWin}->get_widget('dialog_Quit_SaveAll');
  
$Gtk2->{Gtk2SaveAllWin}->signal_autoconnect_from_package('dialog_Quit_SaveAll');

...
...
...

sub window1::gtk_main_quit  {
        # TODO: recreate the SaveAllWindow on destroy
  if ( ! quit() ) {
        $Gtk2->{MainWindow}->show();
        $Gtk2->{SaveAllWindow}->hide();
        return FALSE;
  } else {
    Gtk2->main_quit();
    return TRUE;
  }
}

sub dialog_Quit_SaveAll::on_SaveAll_Cancel_clicked {
        # this is working as expected
        $Gtk2->{SaveAllWindow}->hide();
        $Gtk2->{MainWindow}->show();
        return;
}
# 
sub dialog_Quit_SaveAll::on_SaveAll_Quit_clicked {
        # this is working as expected too
        Gtk2->main_quit;
        return;
}

sub window1::on_MenuFileQuit_activate {
        # this is working as expected also, I think
  return quit();
}

sub dialog_Quit_SaveAll::on_dialog_Quit_SaveAll_destroy {
        # TODO: recreate the SaveAllWindow on destroy   
        $Gtk2->{SaveAllWindow}->hide();
        $Gtk2->{MainWindow}->show();
return;
}


sub quit {
        if ( check_unsaved() ) {
                $Gtk2->{MainWindow}->hide();
                $Gtk2->{SaveAllWindow}->show();
                return FALSE;
        } else {
                return TRUE;
        }
}






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