0

I have a problem with Persian/Arabic characters in KivyMD, which in some places it seems that arabic_reshaper and bidi.algorithm are not working. this is my code:

from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from kivy.lang import Builder
import arabic_reshaper
import bidi.algorithm

screen_helper_up = """
Screen:
    NavigationLayout:
        ScreenManager:
            Screen:
                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        #1
                        title: app.res3 + 'A'
                        font_name:'arial'
                        left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]

                        elevation:10

                    MDTextField: 
                        #2
                        text: app.res3 + 'B'
                        #3
                        helper_text: app.res3 + 'C'
                        #4
                        hint_text: app.res3 + 'D'
                        font_name: 'arial'
                        helper_text_mode: "persistent"
                        font_size: 30
                        line_color_focus: self.theme_cls.opposite_bg_normal
                        pos_hint: {'center_x': 0.5, 'center_y': 0.3}
                        size_hint: (0.5,0.4)
                        icon_right: "android"


                    Widget:
                    Label:
                        #5
                        text: app.res3 + 'E'
                        font_name:'arial'
                        markup: True
                        font_size: 100
                        color: 0,0,0,1

        MDNavigationDrawer:
            id: nav_drawer

"""


class DemoApp(MDApp):
    text3 = ("امیر")
    reshaped_texts3 = arabic_reshaper.reshape(text3)
    res3 = bidi.algorithm.get_display(reshaped_texts3)

    def build(self):
        screen = Screen()
        screen = Builder.load_string(screen_helper_up)
        return screen


DemoApp().run()

In the lines after #2 and #5 the text:"امیر" is shown perfectly but in lines after #1 , #3 and #4 it is shown as small rectangles, as it is shown below: enter image description here

In other word the word "امیر" in MDTextField -> text and Label is displayed perfectly but in MDToolbar -> title , helper_text and hint_text the word "امیر" is written in unknown characters

i search SOF and there is another topic here but seems to be away from subject: TOPIC

I also red about this topic in KivyMD discord group and github pages but in some specific positions as I said above the problem still exists.

any suggestions would be appriciated.

Amir_DA
  • 147
  • 1
  • 1
  • 8
  • You've set the `font_name` property of MDToolbar, but does that property actually exist? It sounds like it maybe doesn't so you haven't actually changed the font it uses – inclement Nov 08 '20 at 13:37
  • 1
    @inclement i checked the documentation and i couldn't find the font_name property for neither the Label that works perfectly nor the MDToolbar that it isn't working. Shouldn't it work for all text fields? If i find the whole code that makes the MDToolbar can i change some specifics to make it work? thanks for your reply! – Amir_DA Nov 08 '20 at 13:52
  • There is no rule that all widgets displaying texts must expose a `font_name` property, although it would usually be a good idea. As you suggest, I would read the MDToolbar code to see if it has a way to change the font_name, and if necessary then change it. – inclement Nov 08 '20 at 14:05
  • you can use this link for Persian or Arabic font: https://hamruyesh.com/product/kivymd-material-design-widgets-kivy-python-tutorial/ – fatemeh Dec 29 '20 at 23:03
  • Refer to this https://stackoverflow.com/questions/65391292/is-there-a-way-to-write-persian-in-python-kivy – Fadi Abu Raid Dec 30 '20 at 16:29

0 Answers0