Re: Change Mouse Cursor
- From: Peter Dennis <peter edwin dennis gmail com>
- To: Mario Kemper <mario kemper googlemail com>
- Cc: gtk-perl-list gnome org
- Subject: Re: Change Mouse Cursor
- Date: Fri, 5 Nov 2010 21:33:36 +1100
Thanks very much Mario.
I was sure I had seen in a tutorial somewhere that it is possible to
connect an event to two different callbacks but I must be mistaken.
On 5 November 2010 21:08, Mario Kemper <mario kemper googlemail com> wrote:
The problem is that you connect the button_press_event to two different
callbacks. I've changed your code in order make things work as you have
described.
sub connect_signals
{
# Respond to mouse button presses
$scrwin->signal_connect(button_press_event => \&button_press_event);
$scrwin->signal_connect(button_release_event => \&change_cursor,
'left_ptr');
}
sub button_press_event
{
my ($widget, $event) = @_;
if ($event->button == 1)
{
print join ' ', $event->coords,"\n";
}
&change_cursor($widget, $event, 'hand1');
return TRUE;
}
sub change_cursor
{
my ($widget, $event, $ctype) = @_;
my $cursor = Gtk2::Gdk::Cursor->new ($ctype);
if ($event->button == 1)
{
$widget->window->set_cursor($cursor);
}
return TRUE;
}
Regards
Mario
Am Freitag, den 05.11.2010, 19:54 +1100 schrieb Zettai Muri:
Hi All,
Was wondering if I could get some help. I am currently trying to
change the mouse cursor to a hand on a 'button_press_event'. I was
hoping to change it to a hand for future grabbing and dragging of a
canvas but can't even get the cursor to change so the dragging
question will have to wait.
Please find attached the simple glade file I am using that contains a
scrolled window and a viewport into which I'm putting a canvas which
at this stage is unused.
Below is the code I am using:
#!/usr/bin/perl
package main;
use strict;
use Glib qw/TRUE FALSE/;
use Goo::Canvas;
use Gtk2 -init;
# Read in glade file with gui
our $builder = Gtk2::Builder->new;
$builder->add_from_file("GooTest.glade");
# Get main window from widget tree.
my $main_window = $builder->get_object('window1') || die "Can't find window.\n";
my $scrwin = $builder->get_object('scrolledwindow1') || die "Can't
find scrolled window.\n";
my $canvas = Goo::Canvas->new();
$scrwin->add_with_viewport($canvas);
$canvas->show;
&connect_signals;
# Quit when user clicks on the close button/alt-f4 etc.
$main_window->signal_connect (destroy => sub { Gtk2->main_quit; });
# Maximise window
#$main_window->maximize;
# Run main loop.
Gtk2->main;
sub connect_signals
{
# Respond to mouse button presses
$scrwin->signal_connect(button_press_event => \&button_press_event);
$scrwin->signal_connect(button_press_event => \&change_cursor);
}
sub button_press_event
{
my ($widget, $event) = @_;
if ($event->button == 1)
{
print join ' ', $event->coords,"\n";
}
return TRUE;
}
sub change_cursor
{
my ($widget, $event) = @_;
my $cursor = Gtk2::Gdk::Cursor->new ('hand1');
if ($event->button == 1)
{
$widget->window->set_cursor($cursor);
}
return TRUE;
}
Thanks for any suggestions.
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]