Last active
December 20, 2015 22:19
-
-
Save geojeff/6204340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.adapters.listadapter import ListAdapter | |
from kivy.base import runTouchApp | |
from kivy.lang import Builder | |
from kivy.models import SelectableDataItem | |
from kivy.properties import ListProperty | |
from kivy.properties import ObjectProperty | |
from kivy.properties import StringProperty | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.uix.button import Button | |
from kivy.uix.carousel import Carousel | |
from kivy.uix.label import Label | |
from kivy.uix.listview import SelectableView | |
from kivy.uix.listview import ListView | |
from kivy.uix.widget import Widget | |
Builder.load_string(''' | |
''') | |
class OrganismGroupListItem(SelectableView, BoxLayout): | |
carousel = ObjectProperty(None) | |
def __init__(self, **kw): | |
super(OrganismGroupListItem, self).__init__(**kw) | |
self.add_widget(Label(text=kw['text'])) | |
self.carousel = Carousel() | |
for organism in kw['organisms']: | |
self.carousel.add_widget(CarouselItem(list_item=self, text=organism)) | |
self.add_widget(self.carousel) | |
def on_touch_up(self, touch): | |
self.carousel.on_touch_up(touch) | |
return super(OrganismGroupListItem, self).on_touch_up(touch) | |
def carousel_item_touched(self, touch): | |
super(OrganismGroupListItem, self).dispatch('on_release') | |
class CarouselItem(Button): | |
list_item = ObjectProperty(None) | |
def on_touch_up(self, touch): | |
self.list_item.carousel_item_touched(touch) | |
class CarouselDataItem(SelectableDataItem): | |
def __init__(self, **kw): | |
super(CarouselDataItem, self).__init__(**kw) | |
self.text = kw['text'] | |
self.organisms = kw['organisms'] | |
data = [CarouselDataItem( | |
text='Mammals:', | |
organisms=['cat', 'dog', 'chimpanzee', 'giraffe', 'mouse']), | |
CarouselDataItem( | |
text='Reptiles:', | |
organisms=['chameleon', 'monitor', 'dinosaur', 'snake', 'turtle']), | |
CarouselDataItem( | |
text='Fish:', | |
organisms=['barracuda', 'tuna', 'perch', 'piranha', 'bass']), | |
CarouselDataItem( | |
text='Mollusks:', | |
organisms=['clam', 'snail', 'chiton', 'oyster', 'scallop']), | |
CarouselDataItem( | |
text='Dinosaurs:', | |
organisms=['carnosaur', 'dromeosaur', 'ceratopsian', 'bird', 'hadrosaur']), | |
CarouselDataItem( | |
text='Angiosperms:', | |
organisms=['oak', 'rose', 'corn', 'lilac', 'petunia'])] | |
converter = lambda x, d: dict(text=d.text, | |
size_hint_y=None, | |
height=75, | |
organisms=d.organisms, | |
) | |
adapter = ListAdapter(data=data, | |
args_converter=converter, | |
cls=OrganismGroupListItem, | |
selection_mode='single', | |
) | |
def selection_changed(*args): | |
print 'selection changed', args | |
adapter.bind(selection=selection_changed) | |
list_view = ListView(adapter=adapter) | |
if __name__ == '__main__': | |
runTouchApp(list_view) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment