Esempio n. 1
0
    async def activate(self, menu, idx):

        if getattr(self, 'chooser', None):
            start_chooser(self.chooser)

        else:
            # nesting menus, and functions and so on.
            f = getattr(self, 'next_function', None)
            if f:
                rv = await f(menu, idx, self)
                if isinstance(rv, MenuSystem):
                    # XXX the function should do this itself
                    # go to new menu
                    the_ux.replace(rv)

            m = getattr(self, 'next_menu', None)

            if callable(m):
                m = await m(menu, idx, self)

            if isinstance(m, list):
                m = MenuSystem(m)

            if m:
                the_ux.push(m)
Esempio n. 2
0
    async def activate(self, menu, idx):

        if self.chooser:
            # get which one to show as selected, list of choices, and fcn to call after
            selected, choices, setter = self.chooser()

            def picked(menu, picked, xx_self):
                menu.chosen = picked
                menu.show()
                await sleep_ms(100)  # visual feedback that we changed it
                setter(picked, choices[picked])

                the_ux.pop()

            # make a new menu, just for the choices
            m = MenuSystem([MenuItem(c, f=picked) for c in choices],
                           chosen=selected)
            the_ux.push(m)

        else:
            # nesting menus, and functions and so on.
            f = self.next_function
            if f:
                rv = await f(menu, idx, self)
                if isinstance(rv, MenuSystem):
                    # XXX the function should do this itself
                    # go to new menu
                    the_ux.replace(rv)

            m = self.next_menu

            if callable(m):
                m = await m(menu, idx, self)

            if isinstance(m, list):
                m = MenuSystem(m)

            if m:
                the_ux.push(m)