<commit_before>from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.properties import ListProperty, StringProperty, ObjectProperty

from kivy.uix.listview import ListView, ListAdapter
from kivy.uix.mixins.selection import SelectionObserver, SelectableItem


# This is an expansion on the "master-detail" example to illustrate
# cascading from the selection of one list view to another.

# Generic list item will do fine for both list views:

class ListItem(SelectableItem, Button):
    selected_color = ListProperty([1., 0., 0., 1])
    deselected_color = ListProperty([.33, .33, .33, 1])

    def __init__(self, selection_callback, **kwargs):
        self.selection_callback = selection_callback
        super(ListItem, self).__init__(**kwargs)

        self.bind(on_release=self.handle_selection)

    def handle_selection(self, button):
        if self.is_selected:
            self.select()
        else:
            self.deselect()

        self.selection_callback(self)

    def select(self, *args):
        self.background_color = self.selected_color

    def deselect(self, *args):
        self.background_color = self.deselected_color

    def __repr__(self):
        return self.text


class FruitsListView(SelectionObserver, ListView):
    # The fruit categories list view can be a simple ListView,
    # but the fruits list, showing fruits for a given category,
    # will be a SelectionObserver, changing when fruit category
    # changes.

    fruit_category = StringProperty('')

    def __init__(self, **kwargs):
        super(FruitsListView, self).__init__(**kwargs)

    def observed_selection_changed(self, observed_selection):
        if len(observed_selection.selection) == 0:
            return

        selected_object = observed_selection.selection[0]

        if type(selected_object) is str:
            self.fruit_category = selected_object
        else:
            self.fruit_category = str(selected_object)

        self.adapter.arranged_objects = fruit_categories[self.fruit_category]

        self.populate()

        print 'just added or updated fruit category'


class DetailView(SelectionObserver, GridLayout):
    fruit_name = StringProperty('')

    def __init__(self, **kwargs):
        kwargs['cols'] = 2
        super(DetailView, self).__init__(**kwargs)
        self.bind(fruit_name=self.redraw)

    def redraw(self, *args):
        self.clear_widgets()
        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(
                    Label(text=str(fruit_data[self.fruit_name][category])))

    def observed_selection_changed(self, observed_selection):
        if len(observed_selection.selection) == 0:
            return
<commit_msg>Removed unneeded property. Added reset of the list view items property when observed selection changes.<commit_after>from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
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


# This is an expansion on the "master-detail" example to illustrate
# cascading from the selection of one list view to another.

# Generic list item will do fine for both list views:

class ListItem(SelectableItem, Button):
    selected_color = ListProperty([1., 0., 0., 1])
    deselected_color = ListProperty([.33, .33, .33, 1])

    def __init__(self, selection_callback, **kwargs):
        self.selection_callback = selection_callback
        super(ListItem, self).__init__(**kwargs)

        self.bind(on_release=self.handle_selection)

    def handle_selection(self, button):
        if self.is_selected:
            self.select()
        else:
            self.deselect()

        self.selection_callback(self)

    def select(self, *args):
        self.background_color = self.selected_color

    def deselect(self, *args):
        self.background_color = self.deselected_color

    def __repr__(self):
        return self.text


class FruitsListView(SelectionObserver, ListView):
    # The fruit categories list view can be a simple ListView,
    # but the fruits list, showing fruits for a given category,
    # will be a SelectionObserver, changing when fruit category
    # changes.
    def __init__(self, **kwargs):
        super(FruitsListView, self).__init__(**kwargs)

    def observed_selection_changed(self, observed_selection):
        if len(observed_selection.selection) == 0:
            return

        selected_object = observed_selection.selection[0]

        if type(selected_object) is str:
            fruit_category = selected_object
        else:
            fruit_category = str(selected_object)

        self.adapter.arranged_objects = fruit_categories[fruit_category]

        self.items = {}

        self.populate()

        print 'just added or updated fruit category'


class DetailView(SelectionObserver, GridLayout):
    fruit_name = StringProperty('')

    def __init__(self, **kwargs):
        kwargs['cols'] = 2
        super(DetailView, self).__init__(**kwargs)
        self.bind(fruit_name=self.redraw)

    def redraw(self, *args):
        self.clear_widgets()
        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(
                    Label(text=str(fruit_data[self.fruit_name][category])))

    def observed_selection_changed(self, observed_selection):
        if len(observed_selection.selection) == 0:
            return

{'fraction_non_alphanumeric': 0.09306963603124481, 'fraction_numerical': 0.005318264916071132, 'mean_word_length': 3.0744752877454298, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865615', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1629, 'n_words': 423}