class ShowingDetailScreen(State):

    def enter_state(self, context=None):
        print 'ShowingDetailScreen/enter_state'

        if not 'Detail' in self.statechart.app.sm.screen_names:

            self.app = self.statechart.app

            view = BoxLayout(orientation='vertical', spacing=10)

            toolbar = BoxLayout(size_hint=(1.0, None), height=50)

            button = Button(text='Lists')
            button.bind(on_press=self.go_to_lists)
            toolbar.add_widget(button)

            button = Button(text='Search')
            button.bind(on_press=self.go_to_search)
            toolbar.add_widget(button)

            button = Button(text='Data')
            button.bind(on_press=self.go_to_data)
            toolbar.add_widget(button)

            label = Label(text='Detail', color=[.8, .8, .8, .8], bold=True)
            toolbar.add_widget(label)

            view.add_widget(toolbar)

            selected_fruit = \
                    self.statechart.fruits_dict_adapter.selection[0].text
            self.detail_view = FruitDetailView(
                    fruit_name=selected_fruit,
                    size_hint=(.6, 1.0))

            view.add_widget(self.detail_view)

            screen = Screen(name='Detail')
            screen.add_widget(view)

            self.app.sm.add_widget(screen)

        if self.app.sm.current != 'Detail':
            self.detail_view.fruit_name = \
                    self.statechart.fruits_dict_adapter.selection[0].text
            self.detail_view.redraw()
            self.app.sm.current = 'Detail'

    def exit_state(self, context=None):
        print 'ShowingDetailScreen/exit_state'

    def go_to_lists(self, *args):
        self.go_to_state('ShowingListsScreen')

    def go_to_search(self, *args):
        self.go_to_state('ShowingSearchScreen')

    def go_to_data(self, *args):
        self.go_to_state('ShowingDataScreen')
class ShowingDetailScreen(State):
    def enter_state(self, context=None):
        print 'ShowingDetailScreen/enter_state'

        if not 'Detail' in self.statechart.app.sm.screen_names:

            self.app = self.statechart.app

            view = BoxLayout(orientation='vertical', spacing=10)

            toolbar = BoxLayout(size_hint=(1.0, None), height=50)

            button = Button(text='Lists')
            button.bind(on_press=self.go_to_lists)
            toolbar.add_widget(button)

            button = Button(text='Search')
            button.bind(on_press=self.go_to_search)
            toolbar.add_widget(button)

            button = Button(text='Data')
            button.bind(on_press=self.go_to_data)
            toolbar.add_widget(button)

            label = Label(text='Detail', color=[.8, .8, .8, .8], bold=True)
            toolbar.add_widget(label)

            view.add_widget(toolbar)

            selected_fruit = \
                    self.statechart.fruits_dict_adapter.selection[0].text
            self.detail_view = FruitDetailView(fruit_name=selected_fruit,
                                               size_hint=(.6, 1.0))

            view.add_widget(self.detail_view)

            screen = Screen(name='Detail')
            screen.add_widget(view)

            self.app.sm.add_widget(screen)

        if self.app.sm.current != 'Detail':
            self.detail_view.fruit_name = \
                    self.statechart.fruits_dict_adapter.selection[0].text
            self.detail_view.redraw()
            self.app.sm.current = 'Detail'

    def exit_state(self, context=None):
        print 'ShowingDetailScreen/exit_state'

    def go_to_lists(self, *args):
        self.go_to_state('ShowingListsScreen')

    def go_to_search(self, *args):
        self.go_to_state('ShowingSearchScreen')

    def go_to_data(self, *args):
        self.go_to_state('ShowingDataScreen')
Example #3
0
    def enter_state(self, context=None):
        print 'ShowingListsScreen/enter_state'

        if not 'Lists' in self.statechart.app.sm.screen_names:

            # Convenience references:
            self.app = self.statechart.app

            view = BoxLayout(orientation='vertical', spacing=10)

            toolbar = BoxLayout(size_hint=(1.0, None), height=50)

            label = Label(text='Lists', color=[.8, .8, .8, .8], bold=True)
            toolbar.add_widget(label)

            button = Button(text='Search')
            button.bind(on_press=self.go_to_search)
            toolbar.add_widget(button)

            button = Button(text='Data')
            button.bind(on_press=self.go_to_data)
            toolbar.add_widget(button)

            button = Button(text='Detail')
            button.bind(on_press=self.go_to_detail)
            toolbar.add_widget(button)

            view.add_widget(toolbar)

            lists_view = GridLayout(cols=3, size_hint=(1.0, 1.0))

            lists_view.add_widget(
                ListView(adapter=self.statechart.fruit_categories_dict_adapter,
                         size_hint=(.2, 1.0)))

            lists_view.add_widget(
                ListView(adapter=self.statechart.fruits_dict_adapter,
                         size_hint=(.2, 1.0)))

            selected_fruit = \
                    self.statechart.fruits_dict_adapter.selection[0].text
            self.detail_view = FruitDetailView(fruit_name=selected_fruit,
                                               size_hint=(.6, 1.0))

            lists_view.add_widget(self.detail_view)

            view.add_widget(lists_view)

            self.create_adapter_bindings()

            screen = Screen(name='Lists')
            screen.add_widget(view)
            self.app.sm.add_widget(screen)

        if self.app.sm.current != 'Lists':
            self.app.sm.current = 'Lists'
Example #4
0
    def __init__(self, items, **kwargs):
        kwargs['cols'] = 2
        kwargs['size_hint'] = (1.0, 1.0)
        super(MasterDetailView, self).__init__(**kwargs)

        list_item_args_converter = \
                lambda row_index, rec: {'text': rec['name'],
                                        'size_hint_y': None,
                                        'height': 25}

        dict_adapter = DictAdapter(sorted_keys=sorted(fruit_data.keys()),
                                   data=fruit_data,
                                   args_converter=list_item_args_converter,
                                   selection_mode='single',
                                   allow_empty_selection=False,
                                   cls=ListItemButton)

        master_list_view = ListView(adapter=dict_adapter, size_hint=(.3, 1.0))

        self.add_widget(master_list_view)

        detail_view = FruitDetailView(
            fruit_name=dict_adapter.selection[0].text, size_hint=(.7, 1.0))

        dict_adapter.bind(on_selection_change=detail_view.fruit_changed)
        self.add_widget(detail_view)
    def enter_state(self, context=None):
        print 'ShowingListsScreen/enter_state'

        if not 'Lists' in self.statechart.app.sm.screen_names:

            # Convenience references:
            self.app = self.statechart.app

            view = BoxLayout(orientation='vertical', spacing=10)

            toolbar = BoxLayout(size_hint=(1.0, None), height=50)

            label = Label(text='Lists', color=[.8, .8, .8, .8], bold=True)
            toolbar.add_widget(label)

            button = Button(text='Search')
            button.bind(on_press=self.go_to_search)
            toolbar.add_widget(button)

            button = Button(text='Data')
            button.bind(on_press=self.go_to_data)
            toolbar.add_widget(button)

            button = Button(text='Detail')
            button.bind(on_press=self.go_to_detail)
            toolbar.add_widget(button)

            view.add_widget(toolbar)

            lists_view = GridLayout(cols=3, size_hint=(1.0, 1.0))

            lists_view.add_widget(ListView(
                adapter=self.statechart.fruit_categories_dict_adapter,
                size_hint=(.2, 1.0)))

            lists_view.add_widget(ListView(
                adapter=self.statechart.fruits_dict_adapter,
                size_hint=(.2, 1.0)))

            selected_fruit = \
                    self.statechart.fruits_dict_adapter.selection[0].text
            self.detail_view = FruitDetailView(fruit_name=selected_fruit,
                                               size_hint=(.6, 1.0))

            lists_view.add_widget(self.detail_view)

            view.add_widget(lists_view)

            self.create_adapter_bindings()

            screen = Screen(name='Lists')
            screen.add_widget(view)
            self.app.sm.add_widget(screen)

        if self.app.sm.current != 'Lists':
            self.app.sm.current = 'Lists'
Example #6
0
    def __init__(self, **kwargs):
        kwargs['cols'] = 3
        super(CascadingView, self).__init__(**kwargs)

        list_item_args_converter = \
                lambda row_index, rec: {'text': rec['name'],
                                        'size_hint_y': None,
                                        'height': 25}

        # Fruit categories list on the left:
        #
        categories = sorted(fruit_categories.keys())
        fruit_categories_dict_adapter = \
            DictAdapter(
                    sorted_keys=categories,
                    data=fruit_categories,
                    args_converter=list_item_args_converter,
                    selection_mode='single',
                    allow_empty_selection=False,
                    cls=ListItemButton)
        fruit_categories_list_view = \
                ListView(adapter=fruit_categories_dict_adapter,
                         size_hint=(.2, 1.0))
        self.add_widget(fruit_categories_list_view)

        fruits_dict_adapter = \
                FruitsDictAdapter(
                    sorted_keys=fruit_categories[categories[0]]['fruits'],
                    data=fruit_data,
                    args_converter=list_item_args_converter,
                    selection_mode='single',
                    allow_empty_selection=False,
                    cls=ListItemButton)

        fruit_categories_dict_adapter.bind(
            on_selection_change=fruits_dict_adapter.fruit_category_changed)

        fruits_list_view = \
                ListView(adapter=fruits_dict_adapter,
                    size_hint=(.2, 1.0))

        self.add_widget(fruits_list_view)

        # Detail view, for a given fruit, on the right:
        #
        detail_view = FruitDetailView(
                fruit_name=fruits_dict_adapter.selection[0].text,
                size_hint=(.6, 1.0))

        fruits_dict_adapter.bind(
                on_selection_change=detail_view.fruit_changed)
        self.add_widget(detail_view)
class ShowingListsScreen(State):
    '''Implementation of a cascading style display, with a scrollable
    list of fruit categories on the left, a list of fruits for the
    selected category in the middle, and a fruit detail view on the
    right.
    '''

    def enter_state(self, context=None):
        print 'ShowingListsScreen/enter_state'

        if not 'Lists' in self.statechart.app.sm.screen_names:

            # Convenience references:
            self.app = self.statechart.app

            view = BoxLayout(orientation='vertical', spacing=10)

            toolbar = BoxLayout(size_hint=(1.0, None), height=50)

            label = Label(text='Lists', color=[.8, .8, .8, .8], bold=True)
            toolbar.add_widget(label)

            button = Button(text='Search')
            button.bind(on_press=self.go_to_search)
            toolbar.add_widget(button)

            button = Button(text='Data')
            button.bind(on_press=self.go_to_data)
            toolbar.add_widget(button)

            button = Button(text='Detail')
            button.bind(on_press=self.go_to_detail)
            toolbar.add_widget(button)

            view.add_widget(toolbar)

            lists_view = GridLayout(cols=3, size_hint=(1.0, 1.0))

            lists_view.add_widget(ListView(
                adapter=self.statechart.fruit_categories_dict_adapter,
                size_hint=(.2, 1.0)))

            lists_view.add_widget(ListView(
                adapter=self.statechart.fruits_dict_adapter,
                size_hint=(.2, 1.0)))

            selected_fruit = \
                    self.statechart.fruits_dict_adapter.selection[0].text
            self.detail_view = FruitDetailView(fruit_name=selected_fruit,
                                               size_hint=(.6, 1.0))

            lists_view.add_widget(self.detail_view)

            view.add_widget(lists_view)

            self.create_adapter_bindings()

            screen = Screen(name='Lists')
            screen.add_widget(view)
            self.app.sm.add_widget(screen)

        if self.app.sm.current != 'Lists':
            self.app.sm.current = 'Lists'

    def exit_state(self, context=None):
        print 'ShowingListsScreen/exit_state'

    def create_adapter_bindings(self):
        # Create bindings from selection in adapters to
        # action callback functions here:
        self.statechart.fruit_categories_dict_adapter.bind(
                on_selection_change=self.fruit_category_changed)

        self.statechart.fruits_dict_adapter.bind(
                on_selection_change=self.fruit_changed)

    def fruit_category_changed(self, fruit_categories_adapter, *args):
        if len(fruit_categories_adapter.selection) == 0:
            self.statechart.fruits_dict_adapter.data = {}
            return

        key = fruit_categories_adapter.selection[0].text
        category = fruit_categories[key]
        self.statechart.fruits_dict_adapter.sorted_keys = category['fruits']

    def fruit_changed(self, list_adapter, *args):
        if len(list_adapter.selection) == 0:
            self.detail_view.fruit_name = None
        else:
            selected_object = list_adapter.selection[0]

            if type(selected_object) is str:
                self.detail_view.fruit_name = selected_object
            else:
                self.detail_view.fruit_name = selected_object.text

            self.detail_view.redraw()

    def go_to_search(self, *args):
        self.go_to_state('ShowingSearchScreen')

    def go_to_data(self, *args):
        self.go_to_state('ShowingDataScreen')

    def go_to_detail(self, *args):
        self.go_to_state('ShowingDetailScreen')
Example #8
0
    def __init__(self, **kwargs):
        kwargs['cols'] = 3
        super(CascadingView, self).__init__(**kwargs)

        list_item_args_converter = \
                lambda row_index, selectable: {'text': selectable.name,
                                               'size_hint_y': None,
                                               'height': 25}

        # Add a fruit categories list on the left. We use ListAdapter, for
        # which we set the data argument to the list of CategoryItem
        # instances from above. The args_converter only pulls the name
        # property from these instances, adding also size_hint_y and height.
        # selection_mode is single, because this list will "drive" the second
        # list defined below. allow_empty_selection is False, because we
        # always want a selected category, so that the second list will be
        # populated. Finally, we instruct ListAdapter to build list item views
        # using the provided cls, ListItemButton.
        #
        fruit_categories_list_adapter = \
            ListAdapter(data=category_data_items,
                        args_converter=list_item_args_converter,
                        selection_mode='single',
                        allow_empty_selection=False,
                        cls=ListItemButton)

        fruit_categories_list_view = \
                ListView(adapter=fruit_categories_list_adapter,
                         size_hint=(.2, 1.0))

        self.add_widget(fruit_categories_list_view)

        # Fruits, for a given category, are in a list in the middle, which
        # uses FruitsListsAdapter, defined above. FruitsListAdapter has a
        # fruit_changed() method that updates the data list. The binding
        # to the fruit_categories_list_adapter is set up after
        # instantiation of the fruit_list_adapter.
        #
        first_category_fruits = \
            fruit_categories[fruit_categories.keys()[0]]['fruits']

        first_category_fruit_data_items = \
            [f for f in fruit_data_items if f.name in first_category_fruits]

        fruits_list_adapter = \
                FruitsListAdapter(data=first_category_fruit_data_items,
                                  args_converter=list_item_args_converter,
                                  selection_mode='single',
                                  allow_empty_selection=False,
                                  cls=ListItemButton)

        fruit_categories_list_adapter.bind(
            on_selection_change=fruits_list_adapter.fruit_category_changed)

        fruits_list_view = \
                ListView(adapter=fruits_list_adapter, size_hint=(.2, 1.0))

        self.add_widget(fruits_list_view)

        # Detail view, for a given fruit, on the right:
        #
        detail_view = FruitDetailView(
            fruit_name=fruits_list_adapter.selection[0].text,
            size_hint=(.6, 1.0))

        fruits_list_adapter.bind(on_selection_change=detail_view.fruit_changed)
        self.add_widget(detail_view)
Example #9
0
class ShowingListsScreen(State):
    '''Implementation of a cascading style display, with a scrollable
    list of fruit categories on the left, a list of fruits for the
    selected category in the middle, and a fruit detail view on the
    right.
    '''
    def enter_state(self, context=None):
        print 'ShowingListsScreen/enter_state'

        if not 'Lists' in self.statechart.app.sm.screen_names:

            # Convenience references:
            self.app = self.statechart.app

            view = BoxLayout(orientation='vertical', spacing=10)

            toolbar = BoxLayout(size_hint=(1.0, None), height=50)

            label = Label(text='Lists', color=[.8, .8, .8, .8], bold=True)
            toolbar.add_widget(label)

            button = Button(text='Search')
            button.bind(on_press=self.go_to_search)
            toolbar.add_widget(button)

            button = Button(text='Data')
            button.bind(on_press=self.go_to_data)
            toolbar.add_widget(button)

            button = Button(text='Detail')
            button.bind(on_press=self.go_to_detail)
            toolbar.add_widget(button)

            view.add_widget(toolbar)

            lists_view = GridLayout(cols=3, size_hint=(1.0, 1.0))

            lists_view.add_widget(
                ListView(adapter=self.statechart.fruit_categories_dict_adapter,
                         size_hint=(.2, 1.0)))

            lists_view.add_widget(
                ListView(adapter=self.statechart.fruits_dict_adapter,
                         size_hint=(.2, 1.0)))

            selected_fruit = \
                    self.statechart.fruits_dict_adapter.selection[0].text
            self.detail_view = FruitDetailView(fruit_name=selected_fruit,
                                               size_hint=(.6, 1.0))

            lists_view.add_widget(self.detail_view)

            view.add_widget(lists_view)

            self.create_adapter_bindings()

            screen = Screen(name='Lists')
            screen.add_widget(view)
            self.app.sm.add_widget(screen)

        if self.app.sm.current != 'Lists':
            self.app.sm.current = 'Lists'

    def exit_state(self, context=None):
        print 'ShowingListsScreen/exit_state'

    def create_adapter_bindings(self):
        # Create bindings from selection in adapters to
        # action callback functions here:
        self.statechart.fruit_categories_dict_adapter.bind(
            on_selection_change=self.fruit_category_changed)

        self.statechart.fruits_dict_adapter.bind(
            on_selection_change=self.fruit_changed)

    def fruit_category_changed(self, fruit_categories_adapter, *args):
        if len(fruit_categories_adapter.selection) == 0:
            self.statechart.fruits_dict_adapter.data = {}
            return

        key = fruit_categories_adapter.selection[0].text
        category = fruit_categories[key]
        self.statechart.fruits_dict_adapter.sorted_keys = category['fruits']

    def fruit_changed(self, list_adapter, *args):
        if len(list_adapter.selection) == 0:
            self.detail_view.fruit_name = None
        else:
            selected_object = list_adapter.selection[0]

            if type(selected_object) is str:
                self.detail_view.fruit_name = selected_object
            else:
                self.detail_view.fruit_name = selected_object.text

            self.detail_view.redraw()

    def go_to_search(self, *args):
        self.go_to_state('ShowingSearchScreen')

    def go_to_data(self, *args):
        self.go_to_state('ShowingDataScreen')

    def go_to_detail(self, *args):
        self.go_to_state('ShowingDetailScreen')