2012-07-12 14:09:10 +00:00
|
|
|
from kivy.uix.gridlayout import GridLayout
|
2012-07-31 03:39:15 +00:00
|
|
|
from kivy.uix.listview import ListView, ListItemButton
|
2012-08-13 18:42:40 +00:00
|
|
|
from kivy.adapters.dictadapter import DictAdapter
|
2012-07-12 14:09:10 +00:00
|
|
|
|
2012-08-13 18:42:40 +00:00
|
|
|
from fixtures import fruit_data
|
2012-08-01 12:29:11 +00:00
|
|
|
|
2012-08-13 18:42:40 +00:00
|
|
|
from fruit_detail_view import FruitDetailView
|
2012-08-01 12:29:11 +00:00
|
|
|
|
2012-08-01 00:19:37 +00:00
|
|
|
|
2012-07-12 14:09:10 +00:00
|
|
|
class MasterDetailView(GridLayout):
|
2012-08-18 09:58:43 +00:00
|
|
|
'''Implementation of an master-detail view with a vertical scrollable list
|
2012-07-12 14:09:10 +00:00
|
|
|
on the left (the master, or source list) and a detail view on the right.
|
2012-08-18 09:58:43 +00:00
|
|
|
When selection changes in the master list, the content of the detail view
|
|
|
|
is updated.
|
2012-07-12 14:09:10 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
def __init__(self, items, **kwargs):
|
|
|
|
kwargs['cols'] = 2
|
|
|
|
super(MasterDetailView, self).__init__(**kwargs)
|
|
|
|
|
2012-12-09 14:28:09 +00:00
|
|
|
list_item_args_converter = \
|
|
|
|
lambda row_index, rec: {'text': rec['name'],
|
|
|
|
'size_hint_y': None,
|
|
|
|
'height': 25}
|
2012-08-13 18:42:40 +00:00
|
|
|
|
|
|
|
dict_adapter = DictAdapter(sorted_keys=sorted(fruit_data.keys()),
|
|
|
|
data=fruit_data,
|
2012-07-31 19:08:00 +00:00
|
|
|
args_converter=list_item_args_converter,
|
|
|
|
selection_mode='single',
|
|
|
|
allow_empty_selection=False,
|
|
|
|
cls=ListItemButton)
|
2012-08-13 18:42:40 +00:00
|
|
|
|
|
|
|
master_list_view = ListView(adapter=dict_adapter,
|
2012-07-30 03:47:32 +00:00
|
|
|
size_hint=(.3, 1.0))
|
2012-08-13 18:42:40 +00:00
|
|
|
|
2012-07-30 03:47:32 +00:00
|
|
|
self.add_widget(master_list_view)
|
2012-07-12 14:09:10 +00:00
|
|
|
|
2012-10-23 18:20:27 +00:00
|
|
|
detail_view = FruitDetailView(
|
|
|
|
fruit_name=dict_adapter.selection[0].text,
|
|
|
|
size_hint=(.7, 1.0))
|
|
|
|
|
2012-08-13 18:42:40 +00:00
|
|
|
dict_adapter.bind(on_selection_change=detail_view.fruit_changed)
|
2012-10-31 23:27:54 +00:00
|
|
|
self.add_widget(detail_view)
|
2012-08-01 12:04:36 +00:00
|
|
|
|
2012-07-12 14:09:10 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
from kivy.base import runTouchApp
|
|
|
|
|
2012-07-13 19:11:33 +00:00
|
|
|
master_detail = MasterDetailView(sorted(fruit_data.keys()), width=800)
|
2012-07-12 14:09:10 +00:00
|
|
|
|
|
|
|
runTouchApp(master_detail)
|