本文整理汇总了Python中kivy.adapters.listadapter.ListAdapter.bind_triggers_to_view方法的典型用法代码示例。如果您正苦于以下问题:Python ListAdapter.bind_triggers_to_view方法的具体用法?Python ListAdapter.bind_triggers_to_view怎么用?Python ListAdapter.bind_triggers_to_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.adapters.listadapter.ListAdapter
的用法示例。
在下文中一共展示了ListAdapter.bind_triggers_to_view方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_list_view_reset_data
# 需要导入模块: from kivy.adapters.listadapter import ListAdapter [as 别名]
# 或者: from kivy.adapters.listadapter.ListAdapter import bind_triggers_to_view [as 别名]
def test_list_view_reset_data(self):
class PetListener(object):
def __init__(self, pet):
self.current_pet = pet
# This should happen as a result of data changing.
def callback(self, *args):
self.current_pet = args[1]
pet_listener = PetListener('cat')
list_item_args_converter = \
lambda row_index, rec: {'text': rec,
'size_hint_y': None,
'height': 25}
list_adapter = ListAdapter(
data=['cat', 'dog', 'lizard', 'hamster', 'ferret'],
args_converter=list_item_args_converter,
selection_mode='multiple',
allow_empty_selection=False,
cls=ListItemButton)
list_view = ListView(adapter=list_adapter)
list_adapter.bind_triggers_to_view(pet_listener.callback)
self.assertEqual(pet_listener.current_pet, 'cat')
self.assertEqual(list_view.adapter.get_view(2).text, 'lizard')
pet_data = list_adapter.data
pet_data[2] = 'bird'
self.assertEqual(list_adapter.data, ['cat',
'dog',
'bird',
'hamster',
'ferret'])
self.assertTrue(hasattr(list_view.adapter, 'selection'))
self.assertEqual(len(list_view.adapter.data), 5)
self.assertEqual(type(list_view.adapter.get_view(0)), ListItemButton)
self.assertEqual(list_view.adapter.get_view(0).text, 'cat')
self.assertEqual(list_view.adapter.get_view(2).text, 'bird')
示例2: test_list_view_reset_data
# 需要导入模块: from kivy.adapters.listadapter import ListAdapter [as 别名]
# 或者: from kivy.adapters.listadapter.ListAdapter import bind_triggers_to_view [as 别名]
def test_list_view_reset_data(self):
class PetListener(object):
def __init__(self, pet):
self.current_pet = pet
# This should happen as a result of data changing.
def callback(self, *args):
self.current_pet = args[1]
pet_listener = PetListener("cat")
list_item_args_converter = lambda row_index, rec: {"text": rec, "size_hint_y": None, "height": 25}
list_adapter = ListAdapter(
data=["cat", "dog", "lizard", "hamster", "ferret"],
args_converter=list_item_args_converter,
selection_mode="multiple",
allow_empty_selection=False,
cls=ListItemButton,
)
list_view = ListView(adapter=list_adapter)
list_adapter.bind_triggers_to_view(pet_listener.callback)
self.assertEqual(pet_listener.current_pet, "cat")
self.assertEqual(list_view.adapter.get_view(2).text, "lizard")
pet_data = list_adapter.data
pet_data[2] = "bird"
self.assertEqual(list_adapter.data, ["cat", "dog", "bird", "hamster", "ferret"])
self.assertTrue(hasattr(list_view.adapter, "selection"))
self.assertEqual(len(list_view.adapter.data), 5)
self.assertEqual(type(list_view.adapter.get_view(0)), ListItemButton)
self.assertEqual(list_view.adapter.get_view(0).text, "cat")
self.assertEqual(list_view.adapter.get_view(2).text, "bird")