在猕猴桃列表中写波斯语查看项目 [英] wrinting persian in kivy list view item

查看:81
本文介绍了在猕猴桃列表中写波斯语查看项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在奇异果编程中遇到了另一个问题. 我想在我的应用程序中使用波斯语,并用它使用Arabi_reshaper. 当我尝试做这样的事情时:

I've another problem in kivy programming. I wanht to write persian in my App and in used Arabi_reshaper for it. when i try to do sth like this:

# -*- coding: utf-8 -*-
import kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from bidi.algorithm import get_display
import arabic_reshaper
Builder.load_string(
'''
<TI>
    but: but
    Button:
        id: but
        font_name: 'data/fonts/DejaVuSans.ttf'
        font_size: '45dp'   
''')

class TI(FloatLayout):

    def __init__(self, **kwargs):
        super(TI, self).__init__(**kwargs)
        self.but.text = get_display(arabic_reshaper.reshape(u'سلام دنیا'))


class MyApp(App):

    def build(self):
        return TI()


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

它正常工作. 但是当我尝试在listview项目中写波斯语时,它只显示深色方块... 我的列表项示例代码是:

it works properly. but when i try to write persian in listview item it only show dark squares... my sample code for list item is this:

# -*- coding: utf-8 -*-
import kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from bidi.algorithm import get_display
import arabic_reshaper
Builder.load_string(
'''
<TI>
    but: but
    ListView:
        id: but 
''')

class TI(FloatLayout):

    def __init__(self, **kwargs):
        super(TI, self).__init__(**kwargs)
        self.but.item_strings = [get_display(arabic_reshaper.reshape(n))  for n in name]


class MyApp(App):

    def build(self):
        return TI()


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

问题出在哪里? 有什么办法可以纠正它? 如何在Kivy的列表视图中使用波斯语?

where is the problem? Is there any way to correct it? how can i use persian in list view in kivy?

推荐答案

您必须设置字体,就像在工作示例中一样,您正在使用DejaVuSans,因为默认字体显然是DroidSans.不支持您的语言.您可以通过列表适配器执行此操作:

You have to set the font, just like you did in working example, where you are using DejaVuSans, since the default font, DroidSans, apparently doesn't support your language. You can do this through list adapter:

# -*- coding: utf-8 -*-
import kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.uix.label import Label

Builder.load_string(
'''
#:import la kivy.adapters.listadapter 
#:import lbl kivy.uix.label

<TI>
    but: but
    ListView:
        id: but 
        adapter: la.ListAdapter(data=[], cls=lbl.Label)

<MyLabel>:
    font_name: 'data/fonts/DejaVuSans.ttf'
''')

class MyLabel(Label):
    pass

class TI(FloatLayout):
    def __init__(self, **kwargs):
        super(TI, self).__init__(**kwargs)
        self.but.adapter.data = [u'سلام دنیا']
        self.but.adapter.cls = MyLabel

class MyApp(App):
    def build(self):
        return TI()


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

这篇关于在猕猴桃列表中写波斯语查看项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆