Python Kivy:如何在模板中调用函数

时间:2015-10-21 10:06:38

标签: python kivy

我使用带有模板的ListAdapter。

    o__dico_medoc = self.p__database.GetAllMedoc()
    data_items = []
    for key, value in o__dico_medoc.items():
        data_items.append({'text': '  %s   %s' % (value.get('NAME'), value.get('DOSAGE')),
                           'is_selected': False})

    list_item_args_converter = lambda row_index, obj: {'text': obj['text'],
                                                       'is_selected': obj['is_selected'],
                                                       'size_hint_y': None,
                                                       'height': '50sp'}

    self.list_adapter = ListAdapter(data=data_items,
                                    args_converter=list_item_args_converter,
                                    selection_mode='single',
                                    allow_empty_selection=True,
                                    template='MedocListItem')

    self.adapter_list_medoc.adapter = self.list_adapter

模板是:

[MedocListItem@SelectableView+BoxLayout]:
    size_hint_y: ctx.size_hint_y
    size_hint_y: ctx.size_hint_y
    height: ctx.height
    canvas.before:
        Color:
            rgba: 1,1,1, 1
        Rectangle:
            pos: self.pos
            size: self.size
    ListItemButton:
        size_hint: (.9, 1)
        text_size: self.size
        text: ctx.text
        is_selected: ctx.is_selected
    ListItemButton:
        size_hint: (.1, 1)
        text: "INFO"
        on_press: DisplayInformation(ctx.text)

在第二个ListItemButton中如何调用on_press函数。我知道模板不是类,所以函数没有定义。但怎么办?

ListAdpater系统很难学习。

0 个答案:

没有答案