Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

View: New views
8 Messages — Rating Filter:   Alert me  

Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

by Jeffrey Ratcliffe-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In the example below, whichever Goo::Canvas::Text object is clicked, only the signal from the first one clicked is fired. With Gtk2::Buttons, it works.

If I comment out the

if ($dialog->run eq 'ok') {}

line, then the Goo::Canvas example works too.

Does anyone have any insight why that might be?

Regards

Jeff

#!/usr/bin/perl
use warnings;
use strict;
use Goo::Canvas;
use Gtk2 '-init';
use Glib qw(TRUE FALSE);

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_default_size(640, 600);

my $canvas = Goo::Canvas->new();
$canvas->set_bounds(0, 0, 250, 250);
my $vbox = Gtk2::VBox->new;
$window->add($vbox);
$vbox->add($canvas);

my $root = $canvas->get_root_item();

for (my $i = 0; $i < 3; $i++) {
boxed_text($root, $i, $i*50, $i*50, $i*50+50, $i*50+50);
add_button($vbox, $i);
}

$window->show_all();

sub boxed_text {
my ($root, $char, $x1, $y1, $x2, $y2) = @_;
my $text = Goo::Canvas::Text->new($root, $char, $x1, $y1, $x2-$x1, 'nw', 'height' => $y2-$y1);

# clicking text box produces a dialog to edit the text
$text->signal_connect('button-press-event' => sub {
my ($widget, $target, $ev) = @_;
print "text $widget button-press-event\n", $widget->get('text'), "\n";
my $dialog = Gtk2::Dialog -> new ('Editing text...', $window,
'modal',
'gtk-ok' => 'ok',
'gtk-cancel' => 'cancel');
$dialog->set_default_response ('ok');
$dialog->show_all;
if ($dialog->run eq 'ok') {}
$dialog->destroy;
return TRUE;
});
}

sub add_button {
my ($vbox, $label) = @_;
my $button = Gtk2::Button->new($label);
$vbox->add($button);
$button->signal_connect('button-press-event' => sub {
my ($widget, $target, $ev) = @_;
print "text $widget button-press-event\n", $widget->get('label'), "\n";
my $dialog = Gtk2::Dialog -> new ('Editing text...', $window,
'modal',
'gtk-ok' => 'ok',
'gtk-cancel' => 'cancel');
$dialog->set_default_response ('ok');
$dialog->show_all;
if ($dialog->run eq 'ok') {}
$dialog->destroy;
return TRUE;
});
}

Gtk2->main;
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

by Mario Kemper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> In the example below, whichever Goo::Canvas::Text object is clicked,
> only the signal from the first one clicked is fired. With
> Gtk2::Buttons, it works.
>
> If I comment out the
>
> if ($dialog->run eq 'ok') {}
>
> line, then the Goo::Canvas example works too.
>
> Does anyone have any insight why that might be?
>

This is strange, indeed.

When I change the event to 'button-release-event' everything works fine,
as well.
But even more strange is the fact that I am doing exactly the same in
Shutter and I didn't experience such problems.
I will have more time to investigate here over the weekend..

Regards
Mario


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

by Mario Kemper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> In the example below, whichever Goo::Canvas::Text object is clicked,
> only the signal from the first one clicked is fired. With
> Gtk2::Buttons, it works.
>
> If I comment out the
>
> if ($dialog->run eq 'ok') {}
>
> line, then the Goo::Canvas example works too.
>
> Does anyone have any insight why that might be?
>
It looks like the button-press-event causes a pointer-grab. This leads
to the described behaviour, because all following events are received by
the first text item that was clicked until the grab gets broken.

Hence, you need to ungrab the pointer after destroying the dialog.
See:
http://library.gnome.org/devel/goocanvas/unstable/GooCanvas.html#goo-canvas-pointer-ungrab 


> my $dialog = Gtk2::Dialog -> new ('Editing text...', $window,
> 'modal',
> 'gtk-ok' => 'ok',
> 'gtk-cancel' => 'cancel');
> $dialog->set_default_response ('ok');
> $dialog->show_all;
> if ($dialog->run eq 'ok') {}
> $dialog->destroy;

$canvas->pointer_ungrab( $widget, $ev->time );

> return TRUE;
> });
> }
>

Your modified script is attached as well.

Regards
Mario



_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

goo.pl (2K) Download Attachment

Re: Re: Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

by Jeffrey Ratcliffe-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jul 14, 2009 7:34pm, Mario Kemper <mario.kemper@...> wrote:
> It looks like the button-press-event causes a pointer-grab. This leads

That's a nice piece of detective work. Thanks for spotting it.

Is it not a bug that Goo::Canvas::Text grabs the pointer?

In both your and my examples, I can only get the first Goo::Canvas::Text created to emit a pressed signal. If I put the Goo::Canvas::Text in a Goo::Canvas::Group, it works as expected.

Regards

Jeff
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Re: Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

by Mario Kemper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am Montag, den 20.07.2009, 11:25 +0000 schrieb
jeffrey.ratcliffe@...:
>
> Is it not a bug that Goo::Canvas::Text grabs the pointer?
>

Might be, yes.
I've added a 'button-release-event'-handler in my code and did the
ungrab while doing some other stuff:

$canvas->pointer_ungrab( $item, $ev->time );

This was the reason why I did not notice any problems here...

> In both your and my examples, I can only get the first
> Goo::Canvas::Text created to emit a pressed signal.

Really? Did you add the 'pointer_ungrab' call to your code?

--------snip-------------

$dialog->destroy;
       
#ungrab the pointer
$canvas->pointer_ungrab( $widget, $ev->time );

--------snip-------------


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Re: Re: Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

by Jeffrey Ratcliffe-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jul 20, 2009 2:15pm, Mario Kemper <mario.kemper@...> wrote:
> > In both your and my examples, I can only get the first
> > Goo::Canvas::Text created to emit a pressed signal.

> Really? Did you add the 'pointer_ungrab' call to your code?

Yup. With the ungrab call, your code only emits a signal for the text "0" - clicks on the other text is ignored. If I put the text in groups, then it works as expected.

Regards

Jeff
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Re: Re: Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

by Mario Kemper :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Am Montag, den 20.07.2009, 12:20 +0000 schrieb
jeffrey.ratcliffe@...:
>
> Yup. With the ungrab call, your code only emits a signal for the text
> "0" - clicks on the other text is ignored. If I put the text in
> groups, then it works as expected.
>

I was using 0.05 of the bindings, but I after upgrading to 0.06 it is
still working for me.
I am sorry, but currently I don't know where the differences between our
system / configurations might be here.

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: Re: Re: Re: Strange interaction between Gtk2::Dialog and signal from Goo::Canvas

by Jeffrey Ratcliffe-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jul 20, 2009 2:40pm, Mario Kemper <mario.kemper@...> wrote:
> > Yup. With the ungrab call, your code only emits a signal for the text
> > "0" - clicks on the other text is ignored. If I put the text in
> > groups, then it works as expected.

No apologies. Yours also works as expected.

If I remove height => $y2-$y1 from the Goo::Canvas::Text->new() call in mine, mine does too, or as I said before, if I put it in a group.

Strange. I'll try and find some time to rewrite the examples in C
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list