Re: Tooltip for GtkTextView contents

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

 



Also should note - the detection of whether the pointer is over a word
or not ( $iter->inside_word ) *is* working correctly ... as my app
appears to be returning correctly when I'm pointing at whitespace. It
just prints blank lines when I point at some text.

Dan

On Fri, Feb 17, 2017 at 3:50 PM, Daniel Kasak <d.j.kasak.dk@xxxxxxxxx> wrote:
> Hi all.
>
> I'd like to provide help on special text ( tokens in code ) in a
> GtkSourceView / GtkTextView. I see my question is basically:
> https://mail.gnome.org/archives/gtk-list/2010-May/msg00107.html
>
>  ... and the important part of the response to this question was:
>
> "Simply set text view's "has-tooltip" property to "TRUE" and connect handler to
> "query-tooltip" signal. Use coordinates provided by callback to find
> the word that cursor hovers over and then do the lookup. I think
> things should be relatively simple."
>
> So I've done attempted this in Perl:
>
> ---
>
> sub on_PARAM_VALUE_query_tooltip {
>
>     my ( $self, $sourceview, $window_x, $window_y, $keyboard_mode,
> $tooltip ) = @_;
>
>     my ( $buffer_x, $buffer_y ) = $sourceview->window_to_buffer_coords
> ( 'GTK_TEXT_WINDOW_TEXT', $window_x, $window_y );
>
>     my ( $trailing, $iter ) = $sourceview->get_iter_at_position(
> $buffer_x, $buffer_y );
>
>     if ( ! $iter->inside_word ) {
>         return FALSE;
>     }
>
>     my $start_iter;
>
>     if ( $iter->starts_word ) {
>         $start_iter = $iter;
>     } else {
>         $iter->backward_word_start;
>         $start_iter = $iter;
>     }
>
>     $iter->forward_word_end;
>
>     my $text = $sourceview->get_buffer->get_text( $start_iter, $iter, 1 );
>
>     print "$text\n";
>
> }
>
> ---
>
> This code runs, produces iters where expected, but then never gets any text.
>
> What have I done wrong?
>
> Thanks :)
>
> Dan
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list



[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux