Beispiel #1
0
    async def add_text(_1, _2, item):
        global pp_sofar
        pp_sofar += item.label
        PassphraseMenu.check_length()

        while not isinstance(the_ux.top_of_stack(), PassphraseMenu):
            the_ux.pop()
Beispiel #2
0
 async def interact(self):
     # Only public entry point: do stuff.
     #
     while self.should_continue() and the_ux.top_of_stack() == self:
         ch = await self.wait_choice()
         gc.collect()
         await self.activate(ch)
Beispiel #3
0
    async def delete_user(menu, label, item):
        if not await ux_confirm('Delete user:\n %s\n' % item.arg):
            return

        Users.delete(item.arg)
        await ux_dramatic_pause('Deleted.', 3)

        from ux import the_ux
        the_ux.pop()
        m = the_ux.top_of_stack()
        m.update_contents()
Beispiel #4
0
def read_menu():
    # helper: return contents of current menu
    from ux import the_ux
    from menu import MenuSystem

    top = the_ux.top_of_stack()
    if not top: return None

    if not isinstance(top, MenuSystem):
        return repr(top)

    return list(it.label for it in top.items)
Beispiel #5
0
    def pop_menu(self):
        # drop them back into menu system, but try not to affect
        # menu position.
        self.ux_done = True

        from actions import goto_top_menu
        from ux import the_ux, restore_menu
        if the_ux.top_of_stack() == self:
            empty = the_ux.pop()
            if empty:
                goto_top_menu()

        restore_menu()
Beispiel #6
0
    def done(self, _1, menu_idx, item):
        final_path = item.arg or item.label
        self.chosen = menu_idx
        self.show()
        await sleep_ms(100)     # visual feedback that we changed it

        # pop entire stack of path choosing
        while 1:
            top = the_ux.top_of_stack()
            if isinstance(top, KeypathMenu):
                the_ux.pop()
                continue
            assert isinstance(top, AddressListMenu)
            break

        return PickAddrFmtMenu(final_path, top)
Beispiel #7
0
    def check_busy(cls, allowed_cls=None):
        # see if we're busy. don't interrupt that... unless it's of allowed_cls
        # - also handle cleanup of stale actions
        if not cls.active_request:
            return
        if allowed_cls and isinstance(cls.active_request, allowed_cls):
            return

        # check if UX actally was cleared, and we're not really doing that anymore; recover
        # - happens if USB caller never comes back for their final results
        from ux import the_ux
        top_ux = the_ux.top_of_stack()
        if not isinstance(top_ux, cls) and cls.active_request.ux_done:
            # do cleaup
            print('recovery cleanup')
            cls.cleanup()
            return

        raise CCBusyError()
Beispiel #8
0
async def ms_wallet_delete(menu, label, item):
    ms = item.arg

    # delete
    if not await ux_confirm("Delete this multisig wallet (%s)?\n\nFunds may be impacted."
                            % ms.name):
        return

    ms.delete()
    await ux_dramatic_pause('Deleted.', 3)

    # update/hide from menu
    # menu.update_contents()

    from ux import the_ux
    # pop stack
    the_ux.pop()

    m = the_ux.top_of_stack()
    m.update_contents()
Beispiel #9
0
 def pop_all(cls):
     while isinstance(the_ux.top_of_stack(), cls):
         the_ux.pop()
Beispiel #10
0
async def usb_keypad_emu():
    # Take keypresses on USB virtual serial port (when not in REPL mode)
    # and converts them into keypad events. Super handy for UX testing/dev.
    #
    # IMPORTANT: 
    # - code is **not** used in real product, but left here for devs to use
    # - this code isn't even called; unless you add code to do so, see ../stm32/my_lib_boot2.py
    #
    from ux import the_ux
    from menu import MenuSystem
    from seed import WordNestMenu

    u = pyb.USB_VCP()

    remap = {  '\r': 'y',
             '\x1b': 'x', 
           '\x1b[A': '5', 
           '\x1b[B': '8', 
           '\x1b[C': '9', 
           '\x1b[D': '7' }

    while 1:
        await sleep_ms(100)

        while u.isconnected() and u.any():
            from main import numpad

            k = u.read(3).decode()

            if k in '\x04':     # ^D
                # warm reset
                from machine import soft_reset
                soft_reset()

            if 0:
                if k == 'd':
                    numpad.debug = (numpad.debug + 1) % 3
                    continue

                if k == 'n':
                    if numpad.disabled:
                        numpad.start()
                    else:
                        numpad.stop()

                    print("npdis = %d" % numpad.disabled)
                    continue

            if k == 'U':
                # enter DFU
                import callgate
                callgate.enter_dfu()
                # not reached

            if k == 'T':
                ckcc.vcp_enabled(True)
                print("Repl enabled")
                continue

            if k == 'M':
                import gc
                print("Memory: %d" % gc.mem_free())
                continue

            # word menus: shortcut for first letter
            top = the_ux.top_of_stack()
            if top and isinstance(top, WordNestMenu) and len(top.items) > 6:
                pos = min(len(i.label) for i in top.items)
                if pos >= 2:
                    for n, it in enumerate(top.items):
                        if it.label[pos-2] == k:
                            top.goto_idx(n)
                            top.show()
                            k = None
                            break

                    if k is None: continue

            if k in remap:
                k = remap[k]

            if k in '0123456789xy':
                numpad.inject(k)
                continue
            
            print('? %r' % k)