mirror of https://github.com/kivy/kivy.git
Multiple binding sets collapsed to one. Added comment explaining selection modes.
This commit is contained in:
parent
a0c9fe78af
commit
b49a5638f6
|
@ -4,7 +4,8 @@ from kivy.uix.button import Button
|
|||
from kivy.uix.listview import ListView, ListAdapter
|
||||
from kivy.uix.mixins.selection import SelectionObserver, SelectableItem
|
||||
from kivy.properties import ListProperty, StringProperty, ObjectProperty
|
||||
|
||||
from kivy.clock import Clock
|
||||
from kivy.graphics.instructions import Callback
|
||||
|
||||
# This is an expansion on the "master-detail" example to illustrate
|
||||
# cascading from the selection of one list view to another.
|
||||
|
@ -25,11 +26,6 @@ class ListItem(SelectableItem, Button):
|
|||
self.bind(on_release=self.handle_selection)
|
||||
|
||||
def handle_selection(self, button):
|
||||
# if not self.is_selected:
|
||||
# self.select()
|
||||
# else:
|
||||
# self.deselect()
|
||||
|
||||
self.list_adapter.handle_selection(self)
|
||||
|
||||
def select(self, *args):
|
||||
|
@ -52,10 +48,12 @@ class FruitsListView(SelectionObserver, ListView):
|
|||
def __init__(self, **kwargs):
|
||||
super(FruitsListView, self).__init__(**kwargs)
|
||||
|
||||
# Observed selection is fruit categories list.
|
||||
def observed_selection_changed(self, observed_selection):
|
||||
if len(observed_selection.selection) == 0:
|
||||
return
|
||||
|
||||
# Clear the previously built views.
|
||||
self.item_view_instances = {}
|
||||
|
||||
# Single selection is operational for fruit categories list.
|
||||
|
@ -70,8 +68,12 @@ class FruitsListView(SelectionObserver, ListView):
|
|||
# to self.adapter.initialize_selection().
|
||||
self.adapter.data = fruit_categories[fruit_category]
|
||||
|
||||
#print self.adapter.selection[0], self.adapter.selection[0].background_color
|
||||
|
||||
self.populate()
|
||||
|
||||
self.canvas.ask_update()
|
||||
|
||||
print 'just added or updated fruit category'
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,11 @@ class SelectionObserver(object):
|
|||
|
||||
class SelectionSupport(object):
|
||||
selection = ListProperty([])
|
||||
# none -- use the list as a simple list (no select action)
|
||||
# single -- multi-touch/click ignored. single item selecting only
|
||||
# multiple -- multi-touch / incremental clicks to select allowed
|
||||
# filter -- idea only now. Could pass in filtering function to
|
||||
# perform associated items selection
|
||||
selection_mode = OptionProperty('multiple',
|
||||
options=('none', 'single', 'multiple', 'filter'))
|
||||
allow_empty_selection = BooleanProperty(True)
|
||||
|
@ -50,9 +55,9 @@ class SelectionSupport(object):
|
|||
|
||||
def __init__(self, **kwargs):
|
||||
super(SelectionSupport, self).__init__(**kwargs)
|
||||
self.bind(data=self.update_selection)
|
||||
self.bind(selection_mode=self.update_selection)
|
||||
self.bind(allow_empty_selection=self.update_selection)
|
||||
self.bind(data=self.initialize_selection,
|
||||
selection_mode=self.initialize_selection,
|
||||
allow_empty_selection=self.initialize_selection)
|
||||
|
||||
def register_selection_observer(self, obs):
|
||||
if isinstance(obs, SelectionObserver):
|
||||
|
|
Loading…
Reference in New Issue