in reply to Russian input with Tk

I guess Tk's handling of keyboard input is ASCII-centric -- it probably doesn't know about any sort of "locale" or other mechanism whereby a given keycode (the byte value emitted when you press a shifted or unshifted alphabetic key) can be interpreted as something other than the standard ASCII value.

You could work around this for the Entry widget by binding a subroutine of your own to the "KeyRelease" event: each time a key is released, bind will call your sub and provide the keycode; now, all you need to do in that subroutine is to remap the ASCII codes to their Cyrillic equivalents (in whatever character encoding you happen to use for Russian).

I'm assuming that you have been able to use other Tk widgets (labels, listboxes, etc) with a suitable Cyrllic font in order to display strings in Russian. I'm also assuming that you are familiar with an appropriate keyboard mapping for Cyrillic input (e.g. the key that would be "S" on an English keyboard maps to "C" on a Russian keyboard, or whatever).

If these assumptions are correct, then it should be the case that when your KeyRelease-bound subroutine replaces ASCII keycodes with the proper Russian character codes, the Entry widget will display the Cyrillic characters that you want to see.

The subroutine probably won't be as simple as I've made it sound... First, the KeyRelease event will occur when you release any key -- and you only want to remap the ones that represent Cyrillic letters, so if the key just released is not a letter with a Cyrillic counter part, you should just leave it alone. Second, as the user types a string into the Entry, your subroutine may need to extract the widget's current string value, edit it, and insert it back into the widget, in order to make the Cyrillic characters show up as intended. This is not really a difficult issue -- just a tedious detail that you'll need to work out. (I'm sorry that I'm not in a position right now to try something out by way of example.)

Replies are listed 'Best First'.
Re: Re: Russian input with Tk
by mamont (Initiate) on Sep 05, 2003 at 10:26 UTC
    Great ideas! Sure I have russian support in Tk Labels/Widgets and others. This part was easy. Just set the right font with koi8-r encoding. Sure I can map english characters to russians, but I never thought about this way of doing things :) I will try to do it :)
Re: Re: Russian input with Tk
by zby (Vicar) on Sep 05, 2003 at 11:05 UTC
    The canonical way of doing keyboard remapping under X is by xmodmap. I did try this method for polish ISO8859-2 characters, and had many problems. Here is my usenet thread about it: input of iso8859-2 characters. I don't remember it too well, but to add to it I remember that the KDE2 own method did not work, and the only way to go with KDE2 was with the xmodmap.
      Maybe I should move to Qt since my application is small yet. But there is a problem with documentation on Qt :( Actually I wish I could do it on Qt since I am just a fan of KDE and related, but I can not larn perl Qt module using C Qt documentation :(