Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Russian input with Tk

by mamont (Initiate)
on Sep 04, 2003 at 16:37 UTC ( #288913=perlquestion: print w/replies, xml ) Need Help??

mamont has asked for the wisdom of the Perl Monks concerning the following question:

I am playing with Tk and I have a have a problem with Entry. It doesnt want to read russian letters. Is there any way I can use russian letters in Entry?

Replies are listed 'Best First'.
Re: Russian input with Tk
by batkins (Chaplain) on Sep 04, 2003 at 18:37 UTC
    I think you're pretty much out of luck until Tk 806 is released - the current version of Tk (804) doesn't support Unicode.

    Look on CPAN for Prima. Prima is a full GUI toolkit, similar to Tk. Prima can do Unicode, though, so it should be perfect for you.


    it says she can do math, but will she recognize 8 / 0?

    We can only hope they've put in those safeguards.

    Worst case scenario: She succeeds in dividing by zero, and suddenly little Tiphany-Amber's bedroom becomes the center of a howling vortex of nonspace, frying the neighborhood with sparkling discharges of zero-point energy.

    - slashdot
      I thought about it a lot, but I have some problems with installing Prima module :( I saw there were some requirements - I have all of the required files, but still I have errors while building a module :(
        If you're running on UNIX, just use the CPAN shell. If you're running on Win32, go to the Prima website (google for "prima perl") and download the Win32 binaries. I had no problems doing it this way.
        it says she can do math, but will she recognize 8 / 0?

        We can only hope they've put in those safeguards.

        Worst case scenario: She succeeds in dividing by zero, and suddenly little Tiphany-Amber's bedroom becomes the center of a howling vortex of nonspace, frying the neighborhood with sparkling discharges of zero-point energy.

        - slashdot
Re: Russian input with Tk
by graff (Chancellor) on Sep 05, 2003 at 04:50 UTC
    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.)

      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 :)
      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 :(
Re: Russian input with Tk
by zby (Vicar) on Sep 05, 2003 at 09:48 UTC
    About a year ago I had a similar problem with imputing polish ISO8859-2 characters. The solution was to use some traditional method of polish characters input - with a keymap. The problem was quite complicated and I don't remember it details - but generaly KDE had it's own method of keyboard control and switching between character sets, but it did not work with Tk.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-08-19 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?