Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arabic text input #1570

Closed
nim4n opened this issue Oct 19, 2013 · 40 comments
Closed

arabic text input #1570

nim4n opened this issue Oct 19, 2013 · 40 comments
Labels
Status: Has PR There's a PR available for the issue Type: Feature Issue is a feature request
Milestone

Comments

@nim4n
Copy link

nim4n commented Oct 19, 2013

how can I convert text in typing time? http://postimg.org/image/u40ftpwm9/ http://postimg.org/image/ibefw8b89/ as you can see when I type in kivy the word is out of shape so I used "arabic reshaper" to fix this problem. now I can use convert button to fix It but how should I fix this in typing time without pressing convert button?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@akshayaurora
Copy link
Member

Try to pre-process the input by overriding the insert_text and passing the text through arabic re-shaper.

This would still be a hack and we need proper support for right to left languages, contributions/pull requests are always welcome, would help if some familiar with RtoL languages could devote time on this.

@nim4n
Copy link
Author

nim4n commented Oct 19, 2013

tnx for your answer. I found this "insert_text(substring, from_undo=False)" in api refrence can you give me a simple example of using It? I'm very new in kivy .

and is this possible to use halign for rtl in text input?

@akshayaurora
Copy link
Member

TextInput doesn't support alignment yet, that's y I stated the we actually need proper support for RtoL languages.

@nim4n
Copy link
Author

nim4n commented Oct 19, 2013

ok . what about insert_text example?

@akshayaurora
Copy link
Member

@nim4n
Copy link
Author

nim4n commented Oct 19, 2013

tnx I write this in my main.py so how can I tell kivy to use It for text input?

my main.py is:

import kivy
import arabic_reshaper
from bidi.algorithm import get_display

kivy.require('1.5.1')

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

from components.initialize import initialize_platform
from components.ttsspeak import ttsSpeak
from kivy.uix.textinput import TextInput

class NumericInput(TextInput):

    def insert_text(self, substring, from_undo=False):
        if not from_undo:
            try:
                int(substring)
            except ValueError:
                return
        super(NumericInput, self).insert_text(substring, from_undo)

class SayThis(FloatLayout):
    saywhat_text = ObjectProperty(None)

    def say_something(self, text):
        ttsSpeak(text)

    def clear(self, text):
        print text
        reshaped_text = arabic_reshaper.reshape(text)
        text = bidi_text = get_display(reshaped_text)
        print text
        self.saywhat_text.text =  text
        self.saywhat_text.focus = True


class SayThisApp(App):
    def build(self):
        initialize_platform()
        return SayThis()


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

@nim4n
Copy link
Author

nim4n commented Oct 20, 2013

I changed kivy.uix.textinput.py to this :

def _create_line_label(self, text, hint=False):
        reshaped_text = arabic_reshaper.reshape(text)
        text = get_display(reshaped_text)

and now It has no problem in showing arabic and farsi but I change It in the kivy core and It's not a good way . how can I force text input to use my input text class inside of my application? as I said I'm very new in kivy

@tshirtman
Copy link
Member

Well, maybe it would be nice to do a PR of that change? That adds a
dependency of kivy to arabic reshaper, but we need internationalisation
anyway, so unless there is a better way to do it, i think it's the way
forward.

At least it should be discussed.

If you want to do it only for your application, you could do a class

class BidiTextInput(TextInput):
def _create_line_label(self, text, hint=False):
reshaped_text = arabic_reshaper.reshape(text)
text = get_display(reshaped_text)
super(BidiTextInput, self)._create_line_label(text, hint)

and use this class instead of TextInput in the rest of your code. (in kv
and python, call BidiTextInput instead of TextInput, everytime you need
it). (BidiTextInput may not be a great name, i lake imagination right
now :P)

But i think it would be a nice addition to kivy.

On Sun, Oct 20, 2013 at 03:16:32AM -0700, Nima wrote:

I changed kivy.uix.textinput.py to this 👍
def _create_line_label(self, text, hint=False):
reshaped_text = arabic_reshaper.reshape(text)
text = get_display(reshaped_text)
and now It has no problem with arabic and farsi but I change It in the kivy core and It's not a good way . how can I force text input to use my input text class in my application? as I said I'm very new in kivy


Reply to this email directly or view it on GitHub:
#1570 (comment)

@nim4n
Copy link
Author

nim4n commented Oct 21, 2013

tnx. there is another problem with right to left and I have to work on It

@tshirtman
Copy link
Member

I understand it's working now, PR? :P

On Mon, Oct 21, 2013 at 12:25:13AM -0700, Nima wrote:

tnx. there is another problem with right to left and I'm working on It


Reply to this email directly or view it on GitHub:
#1570 (comment)

@nim4n
Copy link
Author

nim4n commented Oct 26, 2013

I still working on right to left,my solution is getting curser position and resolution of screen and using tab to move the word to the correct place. do you have a better Idea?

@hopewise
Copy link

hopewise commented Feb 5, 2014

Hey! Where can I find arabic reshaper?

@kashifpk
Copy link

kashifpk commented Aug 5, 2014

Hey! Where can I find arabic reshaper?

https://github.com/mpcabd/python-arabic-reshaper

@hopewise
Copy link

hopewise commented Aug 5, 2014

Do you want the haxe version?
On Aug 5, 2014 7:32 PM, "Kashif Iftikhar" notifications@github.com wrote:

Hey! Where can I find arabic reshaper?

https://github.com/mpcabd/python-arabic-reshaper


Reply to this email directly or view it on GitHub
#1570 (comment).

@sajadbanooie
Copy link

for textinput it wont work

@sajadbanooie
Copy link

def _create_line_label(self, text, hint=False):
reshaped_text = arabic_reshaper.reshape(text)
text = get_display(reshaped_text)
adding it to TextInput will get:
Traceback (most recent call last):
File "/home/sajad/PycharmProjects/kimiastone/Persian.py", line 112, in
myApp().run()
File "/usr/local/lib/python2.7/dist-packages/kivy/app.py", line 824, in run
runTouchApp()
File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 487, in runTouchApp
EventLoop.window.mainloop()
File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_pygame.py", line 401, in mainloop
self._mainloop()
File "/usr/local/lib/python2.7/dist-packages/kivy/core/window/window_pygame.py", line 288, in _mainloop
EventLoop.idle()
File "/usr/local/lib/python2.7/dist-packages/kivy/base.py", line 327, in idle
Clock.tick()
File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 483, in tick
self._process_events()
File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 615, in _process_events
event.tick(self._last_tick, remove)
File "/usr/local/lib/python2.7/dist-packages/kivy/clock.py", line 374, in tick
ret = callback(self._dt)
File "/usr/local/lib/python2.7/dist-packages/kivy/uix/textinput.py", line 1512, in _refresh_line_options
self._refresh_text_from_property()
File "/usr/local/lib/python2.7/dist-packages/kivy/uix/textinput.py", line 1531, in _refresh_text_from_property
self._refresh_text(self._get_text(encode=False), *largs)
File "/usr/local/lib/python2.7/dist-packages/kivy/uix/textinput.py", line 1551, in _refresh_text
_line_rects.append(Rectangle(size=lbl.size))
AttributeError: 'NoneType' object has no attribute 'size'

@pylover
Copy link

pylover commented Jun 26, 2015

I am currently working on kivy's rtl support. so i plan to start by implementing a reshaper in c(cython) . any suggestion ?

@sajadbanooie
Copy link

there is no reshaper in c but you can use cython and python arabic reshaper and bidi

@sajadbanooie
Copy link

i think there should be some changes in widget like algin property
im working on widget algin support

@sajadbanooie
Copy link

i think i have to replace windows x with 0

@pylover
Copy link

pylover commented Jun 26, 2015

The Only difficulty is the multiline-text-entry, selection and markups. the LabelBase's classes (SDL, PyGame & Pil) are easy to do that.

@dessant dessant modified the milestones: 2.0, 2.0.0 Jan 7, 2016
@tshirtman
Copy link
Member

hey @pylover did you get some result? would be nice to go forward on this :)

@pylover
Copy link

pylover commented Aug 4, 2016

Interesting, but i don't have time.
I am planning a project with kivy in next month. i think it's good chance for me to do that.

@pylover
Copy link

pylover commented Aug 8, 2016

I am starting just right now. I love kivy

@engmms
Copy link

engmms commented Sep 10, 2016

follow

@motad333
Copy link

motad333 commented Nov 7, 2016

hellow
thank for all of idea
but there is problem that not solved
and problem is : when i convert .py file to .apk file i find new problem that is encoding of textinput in android system is 'str' and type is hexdecimial but reshaper get unicode utf-8
now how i can convert it to unicode for reshaper??

@pylover
Copy link

pylover commented Nov 7, 2016

@motad333 , I have no idea.the core developers of kivy may help you.

@stale
Copy link

stale bot commented Oct 7, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 7, 2017
@dessant dessant added the Status: Has PR There's a PR available for the issue label Oct 7, 2017
@stale stale bot removed the stale label Oct 7, 2017
@RevengeComing
Copy link
Contributor

RevengeComing commented Nov 19, 2017

Cursor has a bug on farsi/arabic text input and it wont work until SDL fix this problem.
The problem rises from kivy.core.label.LabelBase.get_extents(). it has implemented in pygame, PIL, and SDL. since pygame and PIL using SDL2 ttf, LabelBase implementation of these providers have problem too.

kivy_input

My fork contains fix for farsi/arabic Label/Button, but user has to change font_name to a valid farsi/arabic font_name, since default font doesn't work for farsi. I can create a PR if you want.

Edit: I try to find SDL2's problem with arabic/farsi rendering , but i don't have previous experience about how font/text rendering works.

@engmms
Copy link

engmms commented Nov 19, 2017

@RevengeComing ..hi i want to use this solution in my App..can you tell me how

@RevengeComing
Copy link
Contributor

@engmms , Yet it's not a valid solution but you can install my fork:
pip install git+https://github.com/RevengeComing/kivy.git
( you might need to install rtl, arabic_reshaper, python-bidi , install them with pip)

And you have to add a farsi/arabic font to your application and change all the font_name of your Labels/Buttons/TextInputs to your font since default font doesn't support farsi/arabic.

@RevengeComing
Copy link
Contributor

RevengeComing commented Nov 25, 2017

I'm creating a python binding for harfbuzz library to use its text glyph info inside kivy so we can advance cursor with details it gives to us. with mix of python-bidi and pyharfbuzz we can have multi language support for kivy.

@RevengeComing
Copy link
Contributor

Hello again,

I created kivy_i18n repository in order to solve this problem:

The result is:
peek 2018-01-22 16-23

It requires pyharfbuzz and python-fribidi which only supports linux(py3, py2) and mac(py3) right now as well as harfbuzz, fribidi, freetype2.

TextInput has some problems like not being rtl and ... but I'll add these features to it.

@engmms
Copy link

engmms commented Jan 23, 2018

ok @RevengeComing...thanks for your hard word ..

@engmms
Copy link

engmms commented Jan 23, 2018

@RevengeComing ...I will test this solution

@tito
Copy link
Member

tito commented Oct 9, 2018

An experimental support is now available in master using KIVY_TEXT=pango

@tito tito closed this as completed Oct 9, 2018
@tshirtman
Copy link
Member

Although, as far as i know this solution only works on Linux and OSX, more work is certainly needed for it to work on Windows and mobile platforms.

@P0oOOOo0YA
Copy link

P0oOOOo0YA commented Sep 14, 2020

@RevengeComing @tshirtman Hi buddy, What's up? Is this feature ready to be integrated into mobile and windows applications?I'm really concerned about Android right now rather than windows. One silly workaround for Persian/Farsi speakers is to use Finglish. :)

@ali-aliraqi
Copy link

ali-aliraqi commented Jan 26, 2023

you can use this simple solution for Arabic text input real time in kivy @
https://github.com/ali-aliraqi/Kivy-Arabic_Text_Input

@ARahmanKhallaf
Copy link

did you find a solution to this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Has PR There's a PR available for the issue Type: Feature Issue is a feature request
Projects
None yet
Development

No branches or pull requests