Welcome to OGeek Q&A 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...