Making Windows Busy



   Hi all,

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:

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);

I use the following routine to update the display when inside a callback that is busy doing some processing:

sub gtk2_update()
{

   return if (Gtk2->main_level() == 0);
   while (Gtk2->events_pending())
   {
       Gtk2->main_iteration();
   }

}

and the following to make a window busy/unbusy:

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});
   }

}

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).

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 Cooper.




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