Gtk2-Ex-WidgetCursor

 view release on metacpan or  search on metacpan

devel/combo.pl  view on Meta::CPAN

# Gtk2-Ex-WidgetCursor is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Gtk2-Ex-WidgetCursor.  If not, see <http://www.gnu.org/licenses/>.


# Some experimenting with Gtk2::Combo.  The main thing to do is press "busy
# shortly" and then quickly open the combo popup to see the watch cursor is
# put on there.


use strict;
use warnings;
use Gtk2 '-init';
use Gtk2::Ex::WidgetCursor;

my $toplevel = Gtk2::Window->new ('toplevel');
$toplevel->signal_connect (destroy => sub {

devel/combo.pl  view on Meta::CPAN

print "combo forall\n";
$combo->forall (sub {
                  my ($child) = @_;
                  print "  $child\n";
                });

print "list_toplevels\n";
foreach my $top (Gtk2::Window->list_toplevels) {
  print "  $top  ",$top->get_name,"\n";

  if ($top->get_name eq 'gtk-combo-popup-window') {
    foreach my $child ($top->get_children) {
      print "    $child  ",$child->get_name,"\n";
    }
  }
}

Gtk2->main;
exit 0;

devel/loading.pl  view on Meta::CPAN

# with Gtk2-Ex-WidgetCursor.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use Gtk2 -init;

my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file
  ('/usr/share/doc/libgtk2-perl-doc/examples/gtk-demo/apple-red.png');
my $width = $pixbuf->get_width;
my $height = $pixbuf->get_height;

my $popup = Gtk2::Window->new ('toplevel');
$popup->set_default_size ($width, $height);
$popup->realize;
my $win = $popup->window;
my $gc = $popup->style->bg_gc('normal');
my $pixmap = Gtk2::Gdk::Pixmap->new ($win, $width, $height, -1);
$pixmap->draw_rectangle ($gc, 1, 0,0, $width,$height); # clear
$pixmap->draw_pixbuf ($gc, $pixbuf, 0,0, 0,0, $width,$height, 'none', 0,0);
$win->set_back_pixmap ($pixmap);
$win->set_cursor (Gtk2::Gdk::Cursor->new('watch'));

$popup->show;
$popup->get_display->flush;
sleep 30;


my $window = Gtk2::Window->new;
$window->set_title ("My window");

my $label = Gtk2::Label->new ("Hello, world!");
$window->add ($label);

$popup->destroy;
$window->show_all;
Gtk2->main;

lib/Gtk2/Ex/WidgetCursor.pm  view on Meta::CPAN


#------------------------------------------------------------------------------
# Cribs on widgets using gdk_window_set_cursor directly:
#
# GtkAboutDialog  [not handled]
#     Puts "email" and "link" tags on text in the credits GtkTextView and
#     then does set_cursor on entering or leaving those.
#
# GtkCombo        [ok mostly, with a hack]
#     Does a single set_cursor for a 'top-left-arrow' on a GtkEventBox in
#     its popup when realized.  We dig that out for include_children,
#     primarily so a busy() shows the watch on the popup window if it
#     happens to be open.  Of course GtkCombo is one of the ever-lengthening
#     parade of working and well-defined widgets which Gtk says you're not
#     meant to use any more.
#
# GtkCurve        [not handled]
#     Multiple set_cursor calls according to mode and motion.  A rarely used
#     widget so ignore it for now.
#
# GtkEntry        [ok, with a hack]
#     An Entry uses a private GdkWindow subwindow 4 pixels smaller than the

lib/Gtk2/Ex/WidgetCursor.pm  view on Meta::CPAN

# $widget->Gtk2_Ex_WidgetCursor_hack_restore() returns ($win, $cursor).
# $cursor is a string cursor name to put back on $win when there's no more
# WidgetCursor objects.  Or the return is an empty list or $win undef when
# nothing to hack (in which case all windows go back to "undef" cursor).
#

# default to operate on $widget->window alone
*Gtk2::Widget::Gtk2_Ex_WidgetCursor_windows = \&Gtk2::Widget::window;
sub Gtk2::Widget::Gtk2_Ex_WidgetCursor_hack_restore { return (); }

# GtkEventBox under a GtkComboBox popup window has a 'top-left-arrow'.  It
# gets overridden by a special case in the recursive updates above, and
# hack_restore() here puts it back.
#
sub Gtk2::EventBox::Gtk2_Ex_WidgetCursor_hack_restore {
  my ($widget) = @_;
  return _widget_is_combo_eventbox($widget)
    && ($widget->window, 'top-left-arrow');
}

# GtkTextView operate on 'text' subwindow to override its insertion point

lib/Gtk2/Ex/WidgetCursor.pm  view on Meta::CPAN

                    ? $widget->window
                    : $widget->get_parent_window)
    || return; # if unrealized

  my $event = Gtk2::Gdk::Event->new ('expose');
  return grep { $event->window ($_);
                ($widget == (Gtk2->get_event_widget($event) || 0))
              } $parent_win->get_children;
}

# Return true if $widget is the Gtk2::EventBox child of a Gtk2::Combo popup
# window (it's a child of the popup window, not of the Combo itself).
#
sub _widget_is_combo_eventbox {
  my ($widget) = @_;
  my $parent;
  return ($widget->isa('Gtk2::EventBox')
          && ($parent = $widget->get_parent)  # might not have a parent
          && $parent->get_name eq 'gtk-combo-popup-window');
}


#------------------------------------------------------------------------------

# Could think about documenting this idle level to the world, maybe like the
# following, but would it be any use?
#
# =item C<$Gtk2::Ex::WidgetCursor::busy_idle_priority>
#

lib/Gtk2/Ex/WidgetCursor.pm  view on Meta::CPAN

an I/O watch on a socket, then this is not what you want, it'll turn off too
soon.  (Instead simply make a C<WidgetCursor> with a C<"watch"> and turn it
on or off at your start and end points.  See F<examples/timebusy.pl> for
that sort of thing.)

=over 4

=item C<< Gtk2::Ex::WidgetCursor->busy () >>

Show the C<"watch"> cursor (a little wristwatch) in all the application's
widget windows (toplevels, dialogs, popups, etc).  An idle handler
(C<< Glib::Idle->add >>) removes the watch automatically upon returning to
the main loop.

The X queue is flushed to set the cursor immediately, so the program can go
straight into its work.  For example

    Gtk2::Ex::WidgetCursor->busy;
    foreach my $i (1 .. 1_000_000) {
      # do much number crunching
    }



( run in 2.336 seconds using v1.01-cache-2.11-cpan-364913b4093 )