aecooper has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a GTK2 Perl application and I am trying to write a routine that will make a window busy, i.e. display the busy cursor and stop all input events (keyboard and mouse clicks, but not move movement) from going to the window).
This is using Perl version 5.8.5 on WhiteBox 4 respin 1 (clone of RHAS4U3).
I include the following:
I use the following routine to update the display when inside a callback that is busy doing some processing:use strict; use Glib qw(FALSE TRUE); use Gnome2; use Gnome2::VFS -init; use Gtk2 -init; set_locale Gtk2; init Gtk2; use Gtk2::GladeXML; use Gtk2::Helper; use Gtk2::Pango; use Gtk2::SourceView; use IPC::Open3; use Monotone::AutomateStdio; use POSIX qw(:errno_h :sys_wait_h); use POSIX qw(strftime);
and the following to make a window busy/unbusy:sub gtk2_update() { return if (Gtk2->main_level() == 0); while (Gtk2->events_pending()) { Gtk2->main_iteration(); } }
This sort of works. However if the mouse cursor is moved to a widget whilst the window is busy, then the window is made unbusy, the user has to move the cursor away from the widget and then back again before it will respond to a button click (I suspect because the movement was lost along with everything else).sub make_busy($$) { my($instance, $busy) = @_; # Create and store the cursors if we haven't done so already. if (! exists($instance->{busy_cursor})) { $instance->{normal_cursor} = Gtk2::Gdk::Cursor->new("left-ptr"); $instance->{busy_cursor} = Gtk2::Gdk::Cursor->new("watch"); } # Do it. Make the application bar grab the input when the window is # busy, that way we gobble up keyboard and mouse events that could # muck up the application state. if ($busy) { $instance->{window}->window()-> set_cursor($instance->{busy_cursor}); Gtk2->grab_add($instance->{appbar}); } else { $instance->{window}->window()-> set_cursor($instance->{normal_cursor}); Gtk2->grab_remove($instance->{appbar}); } }
I have tried to interrupt the flow of events by writing my own main event loop but that didn't work very well. I'm sure there is an easy answer as it is a common thing to want to do but I can't find anything on this. Any ideas?
MTIA,
Tony.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Busy Windows Using Gtk2
by zentara (Cardinal) on Jan 25, 2008 at 16:04 UTC | |
|
Re: Busy Windows Using Gtk2
by aecooper (Acolyte) on May 16, 2009 at 18:11 UTC | |
|
Re: Busy Windows Using Gtk2
by Anonymous Monk on Jan 28, 2008 at 04:48 UTC |