How do I destroy window without freezing window?

View: New views
3 Messages — Rating Filter:   Alert me  

How do I destroy window without freezing window?

by Perl Whore :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

#
##### some code here #####
#
 
#
gui_warning(5);
#
 
#
##### some code here that takes time to execute #####
#
 
#
 
#
### sub routines ####
#
 
#
 
#
sub gui_warning {
#
my ($video_count) = @_;
#
 
#
 
#
my $dialog = Gtk2::Dialog->new (
#
'Warning', undef, 'modal',
#
'gtk-yes' => 'yes',
#
'gtk-no' => 'no',
#
);
#
 
#
my $hbox = Gtk2::HBox->new (FALSE, 6);
#
my $question = "This will play $video_count videos. Continue?";
#
 
#
$hbox->pack_start (Gtk2::Label->new ($question), TRUE, TRUE, 0);
#
$hbox->show_all;
#
$dialog->vbox->pack_start ($hbox, TRUE, TRUE, 0);
#
$dialog->set_default_response ('ok');
#
 
#
$dialog->signal_connect (response => sub {
#
shift;
#
my $response = shift;
#
if ($response eq 'yes'){ Gtk2->main_quit; }
#
if ($response eq 'no'){ Gtk2->main_quit; exit; }
#
});
#
$dialog->show;
#
Gtk2->main;
#
 
#
 
#
 
#
 
#
return;
#
}
#
#### end of code ####


In the above code, the window is not destroyed (Gtk2->main_quit) until the rest of the code is executed, which takes time. Instead the window stays frozen until then. How do I make it immediately kill/quit/destroy the window?

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: How do I destroy window without freezing window?

by Peter Juhasz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Sep 11, 2009 at 8:52 PM, Perl Whore <whoreperl@...> wrote:
> How do I make it immediately kill/quit/destroy the
> window?
>
>

> destroy the window

That's exactly how.

Put a $dialog->destroy; before your Gtk2->main_quit;.

By the way, if that's all the GUI you use in your program, consider
dropping Gtk2 altogether and use something more lightweight, e.g.
zenity instead.

Péter Juhász
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: How do I destroy window without freezing window?

by muppet-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Sep 11, 2009, at 2:52 PM, Perl Whore wrote:

>                 my $dialog = Gtk2::Dialog->new (

[snip]

>                 $dialog->set_default_response ('ok');
>                 $dialog->signal_connect (response => sub {
>                                 shift;
>                                 my $response = shift;
>                                 if ($response eq 'yes'){ Gtk2-
> >main_quit; }
>                                 if ($response eq 'no'){ Gtk2-
> >main_quit; exit; }
>                                 });
>                 $dialog->show;
>                 Gtk2->main;

You're not actually destroying the window.  You need to do that or the  
window doesn't go away until the process exits.  Also, you're not  
letting the main loop run to finish the destruction of the window,  
which is further fail.  Since no event loop is running, the window  
appears frozen.


But since you want to block execution until the dialog is answered, I  
think you mean to do this, instead:

         # run the dialog modally, and return when the user responds.
         my $response = $dialog->run ();

         # kill the dialog now.
         $dialog->destroy ();

         # and now act on the response.
         exit if $response eq 'no;


--
Teeter tots are shaped like marshmallows.
   -- Zella.

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list