Re: Problems with Gtk::Text and set_pointer and Text widget questions



"Fannin, David P." a écrit :

I got to reading the tutorial on signal handlers again, and you need to use
signal_connect_after if you want your signal handler to appear to have an
effect when there is a default signal handler for the widget.  In this case,
I was able to get the result Michel discribes by using the following:

$text->signal_connect_after ("button_press_event" => \&button_press);

I also changed the signal handler to insert a space and then delete it at
the insertion point.  This seems to be the only way to actually get the Text
widget to move the cursor.  It isn't elegant, but it works.

sub button_press
{
        my ($text, $event) = @_;
        my $len = $text->get_length()-1;
        $text->set_point ($len +1);
        $text->insert ('','','',' ');
        $text->backward_delete (1);
}


It seems to work most of the time. Some button_presses pass thru and it
is still possible to put the cursor in the middle of the text. I don't
know under wich conditions it happens though.
Anyway, it seems that it is hard to get to a perfect solution there, and
it is good enough for me until we have Gtk 2.0, and a rocking text
widget.

Thanks for spending time on that everybody, and thanks for the solution
David.

Last minute. I found something that works :

Connecting the handler before the stock handler used to freeze input in
the text widget. Adding David's code and 
using grab_focus does the trick :

$text->signal_connect ("button_press_event" => \&button_press);

sub button_press
{
        my ($text, $event) = @_;
        my $len = $text->get_length()-1;
        $text->set_point ($len +1);
        $text->insert ('','','',' ');
        $text->backward_delete (1);

        $text->grab_focus();

        $text->signal_emit_stop_by_name('button_press_event');
        return 1;
}


Unfortunately, this prevents mouse copy/paste operations....

I'll try to sort that out !

Thanks,

Michel.
-- 
Michel Blanc
Centre Multimédia Erasme/Parc d'activités innovantes
69930 Saint Clément-les-places
Tel : +33-(0)4-74-70-68-40 / Fax : +33-(0)4-74-70-68-40




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