Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: right to left Tk text widget

by wolfger (Deacon)
on Dec 06, 2004 at 20:45 UTC ( #412750=note: print w/replies, xml ) Need Help??


in reply to right to left Tk text widget

Tricky problem. I threw together some code that *almost* works. Feel free to expand on this. Current bugs I have noticed are:
1) Backspace and delete should be re-mapped to one another (to account for the backwords nature of the writing).
2) Sometime it just plain goofs, and doesn't print letters in the proper (reversed) order. This bug seems to have something to do with using the mouse to change cursor position, but I can't tell for sure.
3) cursor keys will not navigate properly.
#!/usr/bin/perl use strict; use warnings; use Tk; my $mw = MainWindow->new( -background=>"darkviolet" ); my $t1 = $mw->Text( -background=>"navy", -foreground=>"white", -height=>35, -width=>80, -wrap=>"word", -selectbackground=>"blueviolet" )->pack; $t1->bind("<KeyRelease>" => sub {$t1->SetCursor('current - 1 chars')}) +; MainLoop;


edit: I think I figured bug 2 out... text is printed out of order if you hit a second key before the first key is released. Unfortunately, switching KeyRelease with KeyPress doesn't make everything work. Text is still sometimes out of order, for no apparant reason.

--
Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0

Replies are listed 'Best First'.
Re^2: right to left Tk text widget
by wolfger (Deacon) on Dec 07, 2004 at 14:26 UTC
    Okay, I got it working better, but it's still buggy. I fixed the bug that prevented cursor keys from working. Also, delete and backspace function normally now (without causing undue cursor movement), although backspace still goes left rather than right, and vice versa. The proper text direction is more reliable, but still committing errors. When I type "This is a test.", I invariably wind up with " .tseta si sihT". The cursor fails to move left on the space following the "a" every single time I type that sentence. If somebody can figure this out, I'd be grateful, as I am now quite interested in solving this problem.
    #!/usr/bin/perl use strict; use warnings; use Tk; my $last=1.0; my $mw = MainWindow->new( -background=>"darkviolet" ); my $t1 = $mw->Text( -background=>"navy", -foreground=>"white", -height=>35, -width=>80, -wrap=>"word", -selectbackground=>"blueviolet" )->pack; $t1->bind("<Key>" => \&rtl); #$t1->bind("<KeyRelease>" => sub {$t1->SetCursor('insert - 1 chars')}) +; sub rtl { my $size = $t1->index('end - 1 chars'); if ($last < $size) { $t1->SetCursor('insert - 1 chars'); } $last = $size; } MainLoop;

    edit: Got it! This error occurs on the 10th character of the line, and repeats at the 100th. Our comparison is saying that 1.9 is not less than 1.10 and 1.99 is not less than 1.100. True for integers, but not for line.word count.

    --
    Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2022-01-21 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?