Guest User

https://github.com/kivy/kivy/issues/3078

a guest
Feb 25th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. # -*- coding: utf8 -*-
  2.  
  3. from kivy.adapters.dictadapter import DictAdapter
  4. from kivy.uix.listview import ListItemButton, ListItemLabel, \
  5.         CompositeListItem, ListView
  6. from kivy.uix.gridlayout import GridLayout
  7.  
  8.  
  9. integers_dict = {str(i): {'text': str(i), 'is_selected': False}
  10.                  for i in range(100)}
  11.  
  12. class MainView(GridLayout):
  13.     '''Uses :class:`CompositeListItem` for list item views comprised by two
  14.    :class:`ListItemButton`s and one :class:`ListItemLabel`. Illustrates how
  15.    to construct the fairly involved args_converter used with
  16.    :class:`CompositeListItem`.
  17.    '''
  18.  
  19.     def __init__(self, **kwargs):
  20.         kwargs['cols'] = 2
  21.         super(MainView, self).__init__(**kwargs)
  22.  
  23.         # This is quite an involved args_converter, so we should go through the
  24.         # details. A CompositeListItem instance is made with the args
  25.         # returned by this converter. The first three, text, size_hint_y,
  26.         # height are arguments for CompositeListItem. The cls_dicts list
  27.         # contains argument sets for each of the member widgets for this
  28.         # composite: ListItemButton and ListItemLabel.
  29.         args_converter = lambda row_index, rec: {
  30.             'text': rec['text'],
  31.             'size_hint_y': None,
  32.             'height': 25,
  33.             'cls_dicts': [{'cls': ListItemButton,
  34.                            'kwargs': {'text': u"chérie"}},
  35.                            {
  36.                                'cls': ListItemLabel,
  37.                                'kwargs': {
  38.                                    'text': u"Middle-{0}".format(rec['text']),
  39.                                    'is_representing_cls': True}},
  40.                            {
  41.                                'cls': ListItemButton,
  42.                                'kwargs': {'text': rec['text']}}]}
  43.  
  44.         item_strings = ["{0}".format(index) for index in range(100)]
  45.  
  46.         dict_adapter = DictAdapter(sorted_keys=item_strings,
  47.                                    data=integers_dict,
  48.                                    args_converter=args_converter,
  49.                                    selection_mode='single',
  50.                                    allow_empty_selection=False,
  51.                                    cls=CompositeListItem)
  52.  
  53.         # Use the adapter in our ListView:
  54.         list_view = ListView(adapter=dict_adapter)
  55.  
  56.         self.add_widget(list_view)
  57.  
  58.  
  59. if __name__ == '__main__':
  60.     from kivy.base import runTouchApp
  61.     runTouchApp(MainView(width=800))
Add Comment
Please, Sign In to add comment