2012-08-03 01:53:41 +00:00
|
|
|
from kivy.uix.gridlayout import GridLayout
|
|
|
|
from kivy.uix.label import Label
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
from kivy.uix.image import Image
|
|
|
|
from kivy.properties import StringProperty
|
|
|
|
|
|
|
|
from fruit_data import descriptors
|
|
|
|
from fruit_data import fruit_data
|
|
|
|
|
|
|
|
|
2012-08-04 10:28:53 +00:00
|
|
|
# Used in list_cascade.py example.
|
|
|
|
#
|
2012-08-03 01:53:41 +00:00
|
|
|
class FruitDetailView(GridLayout):
|
2012-08-04 10:28:53 +00:00
|
|
|
fruit_name = StringProperty('', allownone=True)
|
2012-08-03 01:53:41 +00:00
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
kwargs['cols'] = 2
|
|
|
|
super(FruitDetailView, self).__init__(**kwargs)
|
|
|
|
|
|
|
|
def redraw(self, *args):
|
|
|
|
self.clear_widgets()
|
2012-08-04 10:28:53 +00:00
|
|
|
if self.fruit_name:
|
|
|
|
self.add_widget(Label(text="Name:", halign='right'))
|
|
|
|
self.add_widget(Label(text=self.fruit_name))
|
|
|
|
for category in descriptors:
|
|
|
|
self.add_widget(Label(text="{0}:".format(category),
|
|
|
|
halign='right'))
|
|
|
|
self.add_widget(
|
2012-08-03 01:53:41 +00:00
|
|
|
Label(text=str(fruit_data[self.fruit_name][category])))
|
|
|
|
|
|
|
|
def fruit_changed(self, list_adapter, *args):
|
|
|
|
if len(list_adapter.selection) == 0:
|
2012-08-04 10:28:53 +00:00
|
|
|
self.fruit_name = None
|
2012-08-03 01:53:41 +00:00
|
|
|
else:
|
2012-08-04 10:28:53 +00:00
|
|
|
selected_object = list_adapter.selection[0]
|
2012-08-03 01:53:41 +00:00
|
|
|
|
2012-08-04 10:28:53 +00:00
|
|
|
if type(selected_object) is str:
|
|
|
|
self.fruit_name = selected_object
|
|
|
|
else:
|
|
|
|
self.fruit_name = str(selected_object)
|
2012-08-03 01:53:41 +00:00
|
|
|
|
2012-08-04 10:28:53 +00:00
|
|
|
self.redraw()
|
2012-08-03 01:53:41 +00:00
|
|
|
|
2012-08-04 10:28:53 +00:00
|
|
|
# Used in the list_cascade_oo.py example (ObjectAdapter and ObserverView
|
|
|
|
# example).
|
|
|
|
#
|
2012-08-03 22:50:22 +00:00
|
|
|
class FruitObserverDetailView(GridLayout):
|
|
|
|
fruit_name = StringProperty('')
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
kwargs['cols'] = 2
|
|
|
|
super(FruitObserverDetailView, self).__init__(**kwargs)
|
|
|
|
|
|
|
|
def redraw(self, *args):
|
|
|
|
self.clear_widgets()
|
|
|
|
if self.fruit_name:
|
|
|
|
self.add_widget(Label(text="Name:", halign='right'))
|
|
|
|
self.add_widget(Label(text=self.fruit_name))
|
|
|
|
for category in descriptors:
|
|
|
|
self.add_widget(Label(text="{0}:".format(category),
|
|
|
|
halign='right'))
|
|
|
|
if self.fruit_name == '':
|
|
|
|
self.add_widget(Label(text=''))
|
|
|
|
else:
|
|
|
|
self.add_widget(Label(
|
|
|
|
text=str(fruit_data[self.fruit_name][category])))
|
|
|
|
|
|
|
|
def update(self, object_adapter, *args):
|
|
|
|
print 'updating fodv', object_adapter, object_adapter.obj
|
|
|
|
if object_adapter.obj is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
if type(object_adapter.obj) is str:
|
|
|
|
self.fruit_name = object_adapter.obj
|
|
|
|
else:
|
|
|
|
self.fruit_name = str(object_adapter.obj)
|
|
|
|
|
|
|
|
self.redraw()
|
|
|
|
|
2012-08-04 10:28:53 +00:00
|
|
|
# Used in list_cascade_images.py example.
|
|
|
|
#
|
2012-08-03 01:53:41 +00:00
|
|
|
class FruitImageDetailView(BoxLayout):
|
2012-08-04 10:28:53 +00:00
|
|
|
fruit_name = StringProperty('', allownone=True)
|
2012-08-03 01:53:41 +00:00
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
kwargs['orientation'] = 'vertical'
|
|
|
|
super(FruitImageDetailView, self).__init__(**kwargs)
|
|
|
|
|
|
|
|
def redraw(self, *args):
|
|
|
|
self.clear_widgets()
|
|
|
|
|
2012-08-04 10:28:53 +00:00
|
|
|
if self.fruit_name:
|
|
|
|
self.add_widget(Image(
|
|
|
|
source="fruit_images/{0}.256.jpg".format(self.fruit_name),
|
|
|
|
size=(256, 256)))
|
|
|
|
|
|
|
|
container = GridLayout(cols=2)
|
|
|
|
container.add_widget(Label(text="Name:", halign='right'))
|
|
|
|
container.add_widget(Label(text=self.fruit_name))
|
|
|
|
for category in descriptors:
|
|
|
|
container.add_widget(Label(text="{0}:".format(category),
|
|
|
|
halign='right'))
|
|
|
|
container.add_widget(
|
|
|
|
Label(text=str(fruit_data[self.fruit_name][category])))
|
|
|
|
self.add_widget(container)
|
2012-08-03 01:53:41 +00:00
|
|
|
|
|
|
|
def fruit_changed(self, list_adapter, *args):
|
|
|
|
if len(list_adapter.selection) == 0:
|
2012-08-04 10:28:53 +00:00
|
|
|
self.fruit_name = None
|
2012-08-03 01:53:41 +00:00
|
|
|
else:
|
2012-08-04 10:28:53 +00:00
|
|
|
selected_object = list_adapter.selection[0]
|
|
|
|
|
|
|
|
# [TODO] Would we want touch events for the composite, as well as
|
|
|
|
# the components? Just the components? Just the composite?
|
|
|
|
#
|
|
|
|
# Is selected_object an instance of ThumbnailedListItem (composite)?
|
|
|
|
#
|
|
|
|
# Or is it a ListItemButton?
|
|
|
|
#
|
|
|
|
if hasattr(selected_object, 'fruit_name'):
|
|
|
|
self.fruit_name = selected_object.fruit_name
|
|
|
|
else:
|
|
|
|
self.fruit_name = selected_object.text
|
2012-08-03 01:53:41 +00:00
|
|
|
|
|
|
|
self.redraw()
|