For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > June 2007 > Line no. in text box









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Line no. in text box
nishant

2007-06-07, 10:04 pm

Hi ,
How can I find out the line no of the text over which the mouse cursor
is placed ?

zentara

2007-06-07, 10:04 pm

On Thu, 07 Jun 2007 04:20:28 -0700, nishant <nishant.031@gmail.com>
wrote:

>Hi ,
>How can I find out the line no of the text over which the mouse cursor
>is placed ?


Here is a generalized example, that should show you the way.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::Balloon;

my @last = ('','');
my @word = ('','');
my $msg;

my $mw = tkinit;

my $t = $mw->Text->pack;

my $balloon = $mw->Balloon(
-initwait => 0,
-balloonposition => 'mouse',
-postcommand => \&post_com,
-motioncommand => \&motion_com
);

$t->insert( 'end', "Balloon over words is easy, eh?\n" );
$t->insert( 'end', "Adding position over words is easy also, eh?\n" );


$balloon->attach( $t, -balloonmsg => \$msg );

MainLoop;
########################################
################
sub post_com {
if ( $word[0] eq $word[1] ) {
0; # No word under mouse - don't post the balloon.
}
else {
# Have a word under mouse - change the message:
my $word = $t->get( $word[0], $word[1] );
# Skip it if it contains non-word chars:
return 0 if $word =~ /\W/;
$msg = "The word under the mouse is: $word @last";
$t->tag( 'add', 'sel', $word[0] => $word[1] );

# Find a good place to put the balloon (right below the last charin
the word):
my $i = $t->index("$word[1] - 1 chars");
my @p = $t->bbox($i);
my $x = $t->rootx + $p[0] + $p[2] - 4;
my $y = $t->rooty + $p[1] + $p[3] + 2;
"$x,$y";
}
}
########################################
#######
sub motion_com {
my $x = $t->pointerx - $t->rootx;
my $y = $t->pointery - $t->rooty;
@word = ( $t->index("\@$x,$y wordstart"), $t->index("\@$x,$y
wordend") );
if ( $word[0] eq $last[0] and $word[1] eq $last[1] ) {
0;# Same word - don't cancel the balloon.
}
else {
# New word under mouse - cancel it so a new balloon will
beposted.
$t->SelectionClear;
@last = @word;
1;
}
}
########################################
##############

zentara




--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sizza

2007-06-12, 2:11 am

http://www.eyrenet.com/a?id=1673286
Aderpotardder

2007-06-22, 4:04 pm

Halle Berry and Alyson Hannigan Lesbians Get Messy With Food!
http://www.YourTubeAmp.com/PlayFile?q=1673286

Christina Aguilera and Christina Aguilera Doing Hot Bottle Insertion!
http://www.YourTubeAmp.com/WatchTube?watch=1673286

Cameron Diaz and Jessica Alba ,Insert Bottly In XXXXXXX!
http://www.YourTubeAmp.com/Watch?q=1673286

Lindsay Lohan and Hilary Swank Tongue Tickles Lesbian Lovers Pussy Movies!
http://www.YourTubeAmp.com/WatchMovie?id=1673286

Nikki Cox and Lindsay Lohan Having Fun Together!
http://www.YourTubeAmp.com/Watch?movie=1673286
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com