Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

python - Kivy Text Input for Arabic Text

I'm trying to use Kivy's text input for Arabic text. I have an Arabic font set up with my text input but when I type into the input (in Arabic) I just get Arabic letters appearing from left to right (and they're not connected as Arabic letters should be when they're adjacent to each other).

Is there a way to get Kivy/text input to support RTL languages input that I'm missing (esp Arabic).

Here's my code,

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout

Config.set('graphics', 'width', '300')
Config.set('graphics', 'height', '500')


logger = logging.getLogger('')

from kivy.uix.textinput import TextInput


class EditorApp(App):
    def build(self):
        f = FloatLayout()
        textinput = TextInput(text='Hello world', font_name='DroidKufi-Regular.ttf')
        # import pdb; pdb.set_trace()

        f.add_widget(textinput)

        return f


if __name__ == '__main__':
    EditorApp().run()

The result of this code:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Unfortunately, Kivy TextInput support for right-to-left is an open issue (checked 29/05/2015). Actually, Kivy is not supporting right-to-left not only to TextInput.

For static texts like labels , there is a hack by using arabic_reshaper and python-bidi (reference):

import arabic_reshaper
from bidi.algorithm import get_display

reshaped_text = arabic_reshaper.reshape(u'????? ??????? ?????')
bidi_text = get_display(reshaped_text)

enter image description here

Yet, as for TextInput with a dynamic input, you had to override most of class methods to support RTL and you will end up like implementing the whole RTL support to kivy.

Here is an open attempt to implement Kivy bidi support. Another closed one: Right-to-left labels support.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...