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.


In reply to Busy Windows Using Gtk2 by aecooper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.