Re: Is it possible to stop a signal callback?
On Mon, 2007-08-06 at 10:00 +0800, Ye Wenbin wrote: > On Mon, 06 Aug 2007 01:35:41 +0800, zentara <[EMAIL PROTECTED]> wrote: > > > Have you looked at > > http://forgeftp.novell.com/gtk2-perl-study/download/ > > it will answer alot of questions. > > > I have read this document. It is really helpful. > > > > Don't use while(1) or sleep in a gui script, they cause malfunctions. > > I did not use sleep to do some work periodly. I was trying to show the > signal > callback will take a long time to finish. Maybe it need fork or using > thread. But > the problem is I don't know how to communicate with subprocess. I will try > to find it. you should look at the Gtk2-Perl FAQ: http://live.gnome.org/GTK2-Perl/FrequentlyAskedQuestions especially the 'How do I keep my GUI updating while doing a long file read?' question. ciao, Emmanuele. -- Emmanuele Bassi, W: http://www.emmanuelebassi.net B: http://log.emmanuelebassi.net ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Is it possible to stop a signal callback?
On Mon, 06 Aug 2007 01:35:41 +0800, zentara <[EMAIL PROTECTED]> wrote: > Have you looked at > http://forgeftp.novell.com/gtk2-perl-study/download/ > it will answer alot of questions. > I have read this document. It is really helpful. > > Don't use while(1) or sleep in a gui script, they cause malfunctions. I did not use sleep to do some work periodly. I was trying to show the signal callback will take a long time to finish. Maybe it need fork or using thread. But the problem is I don't know how to communicate with subprocess. I will try to find it. -- Best regards, Ye Wenbin ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Re: Is it possible to stop a signal callback?
On Sun, 05 Aug 2007 23:35:24 +0800 "Ye Wenbin" <[EMAIL PROTECTED]> wrote: >Hi, >In my application, there is a callback which may take a long time to >finish. >Is it possible to return from the callback when user really need? For >example, >code as following, can I press the button 'cancel' to stop the counting? >Is there any document about thread in Gtk2? Have you looked at http://forgeftp.novell.com/gtk2-perl-study/download/ it will answer alot of questions. >$but = Gtk2::Button->new('start'); >$but->signal_connect( > 'clicked' => sub { > my $i = 0; Don't use while(1) or sleep in a gui script, they cause malfunctions. > while ($i < 10) { > sleep( 1 ); > $i++; > print "I'm working\n"; > } > return FALSE; > } >); Try this: #!/usr/bin/perl use warnings; use strict; use Gtk2 '-init'; use Glib qw(TRUE FALSE); my $cancel = 0; my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); my $hbox= Gtk2::HBox->new(FALSE, 0); my $but; $but = Gtk2::Button->new('start'); $but->signal_connect( 'clicked' => sub { my $i = 0; # while ($i < 1000) { ## sleep( 1 ); # $i++; # print "I'm working $i\n"; my $id = Glib::Timeout->add (1000, sub{ $i++; if($i > 1000){print "done\n";$cancel = 0; return FALSE;} if($cancel==1){print "done\n";$cancel = 0; return FALSE;} print "I'm working $i\n"; }); #} return FALSE; } ); $hbox->pack_start($but, TRUE, TRUE, 5); $but = Gtk2::Button->new('Cancel'); $but->signal_connect( 'clicked' => sub { $cancel = 1; warn "Stop it\n"; } ); $hbox->pack_start($but, TRUE, TRUE, 5); $window->add($hbox); $window->show_all(); Gtk2->main; __END__ zentara -- I'm not really a human, but I play one on earth. http://zentara.net/japh.html ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list
Is it possible to stop a signal callback?
Hi, In my application, there is a callback which may take a long time to finish. Is it possible to return from the callback when user really need? For example, code as following, can I press the button 'cancel' to stop the counting? Is there any document about thread in Gtk2? use Gtk2 '-init'; use Glib qw(TRUE FALSE); my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); my $hbox= Gtk2::HBox->new(FALSE, 0); my $but; $but = Gtk2::Button->new('start'); $but->signal_connect( 'clicked' => sub { my $i = 0; while ($i < 10) { sleep( 1 ); $i++; print "I'm working\n"; } return FALSE; } ); $hbox->pack_start($but, TRUE, TRUE, 5); $but = Gtk2::Button->new('Cancel'); $but->signal_connect( 'clicked' => sub { die "Stop it\n"; } ); $hbox->pack_start($but, TRUE, TRUE, 5); $window->add($hbox); $window->show_all(); Gtk2->main; -- Best regards, Ye Wenbin ___ gtk-perl-list mailing list gtk-perl-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-perl-list