Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Valid values of Tk::Text see() function.

by JamesNC (Chaplain)
on Jul 30, 2004 at 03:08 UTC ( [id://378579]=note: print w/replies, xml ) Need Help??


in reply to Valid values of Tk::Text see() function.

Without seeing the rest of your code and not really sure what value the widget ( $t->index('insert') ) is actually returning, you said '2.0'... Since I am not sure what widget you are using... I would maybe try qq/ $t->index('insert')/ or $t->index('insert').""... since perl may be trying to cast the index into a number instead of leaving it as a string The following works for me on AS 5.8.3 build 809 and Tk 804.021:
use Tk; use strict; my $mw = tkinit; $mw->geometry('100x100'); my $linenumbers = $mw->Text()->pack(-fill, 'both', -expand, 1); &line_num(30); MainLoop; sub line_num { my $total_lines = shift; #my $line_number = qq($t->index('insert')); #? my $line_number = '21.0'; print $line_number,"\n"; $linenumbers->delete("0.1", "end"); for (0..$total_lines) { $linenumbers->insert('end', join "\n", map {sprintf "%4d\n", $_ +} $_); } #$linenumbers->yviewMoveto($line_number/$total_lines); #$linenumbers->yview(-pickplace, $line_number); $linenumbers->see($line_number); }

JamesNC

Replies are listed 'Best First'.
Re^2: Valid values of Tk::Text see() function.
by Anonymous Monk on Jul 30, 2004 at 12:50 UTC
    I don't want to be picky, but seeing this section of your code:
    #my $line_number = qq($t->index('insert')); #? my $line_number = '21.0'; print $line_number,"\n";
    I wonder whether you're really doing what the OP wanted to. After all you're just hard coding the line number...
      I don't know what widget $t is? It is definitely not the same widget he is using see() with and he is using the insertion point index of that widget. So, just working the problem backwards to that line should convince him that the problem is not in the see() function, but in the arguements he gave to it. Plug in '2.0' and it still works fine.
        What I have is a TextUndo widget and a ROText widget side by side. The TextUndo widget is the main window and the ROText is simply a 4 pixle width column that does line numbering.

        I have the two mapped and they scroll congruently using yscrollcommand so that is fine. I also created a function to have the scroll congruently when using a binded mousewheel scroll I had already implemented. The last thing that I am having issues with is if you use the arrow keys to scroll up or down. When I start on line "0" and hit the down arrow key to line one everything is fine but as soon as I hit it again and the line number value becomes 2 the ROText widget jumps all the way down to the last line of that widget but the TextUndo widget remains where it is at.

        As you cans ee from my source code I have tried a few methods using yview and implenting the "-pickplace" option but this option is suppose to be obsolete and replaced by the see() function. The closest I have gotten to the performance I want is using yviewMoveto(). However when I do this I start on line 0 and hit the arrow button down one and the line number column then shows the number 2 as the first number in the list and the TextUndo widget does not scroll so now the line number no longer matches up to it's line.

        I have also gotten them to stay together by having them both scroll when I hit the down key but this is not what I want either because neither window should scroll untill the value of "index" is off the screen (not visible). In the last example this is not the case. If I were to start on line 0 and hit the down arrow key both widgets would scroll and would now show line 1 at the top of the widget and move line 0 off the screen even though line 1 was already visible the widgets would still scroll to adjust.

        I hope that clears some things up. I know this is somewhat confusing especially when you are not really sure what I am doing in the first place.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://378579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found