mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-25 16:08:32 +00:00
refactor(core/ui): allow custom exception on menu cancelation
[no changelog]
This commit is contained in:
parent
2c50db3cde
commit
1e7108f6d2
@ -3,12 +3,15 @@ from typing import TYPE_CHECKING, Awaitable
|
|||||||
import trezorui_api
|
import trezorui_api
|
||||||
from trezor.enums import ButtonRequestType
|
from trezor.enums import ButtonRequestType
|
||||||
from trezor.ui.layouts.common import interact
|
from trezor.ui.layouts.common import interact
|
||||||
|
from trezor.wire import ActionCancelled
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Callable, Iterable, Sequence
|
from typing import Callable, Iterable, Sequence
|
||||||
|
|
||||||
from typing_extensions import Self
|
from typing_extensions import Self
|
||||||
|
|
||||||
|
from common import ExceptionType
|
||||||
|
|
||||||
|
|
||||||
class Menu:
|
class Menu:
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -42,6 +45,7 @@ class Details:
|
|||||||
|
|
||||||
async def show_menu(
|
async def show_menu(
|
||||||
root: Menu,
|
root: Menu,
|
||||||
|
raise_on_cancel: ExceptionType = ActionCancelled,
|
||||||
) -> None:
|
) -> None:
|
||||||
menu_path = []
|
menu_path = []
|
||||||
current_item = 0
|
current_item = 0
|
||||||
@ -56,7 +60,9 @@ async def show_menu(
|
|||||||
current=current_item,
|
current=current_item,
|
||||||
cancel=menu.cancel,
|
cancel=menu.cancel,
|
||||||
)
|
)
|
||||||
choice = await interact(layout, br_name=None)
|
choice = await interact(
|
||||||
|
layout, br_name=None, raise_on_cancel=raise_on_cancel
|
||||||
|
)
|
||||||
if isinstance(choice, int):
|
if isinstance(choice, int):
|
||||||
# go one level down
|
# go one level down
|
||||||
menu_path.append(choice)
|
menu_path.append(choice)
|
||||||
@ -79,11 +85,12 @@ async def confirm_with_menu(
|
|||||||
menu: Menu,
|
menu: Menu,
|
||||||
br_name: str | None,
|
br_name: str | None,
|
||||||
br_code: ButtonRequestType = ButtonRequestType.Other,
|
br_code: ButtonRequestType = ButtonRequestType.Other,
|
||||||
|
raise_on_cancel: ExceptionType = ActionCancelled,
|
||||||
) -> None:
|
) -> None:
|
||||||
while True:
|
while True:
|
||||||
result = await interact(main, br_name, br_code)
|
result = await interact(main, br_name, br_code, raise_on_cancel)
|
||||||
br_name = None # ButtonRequest should be sent once (for the main layout)
|
br_name = None # ButtonRequest should be sent once (for the main layout)
|
||||||
if result is trezorui_api.INFO:
|
if result is trezorui_api.INFO:
|
||||||
await show_menu(menu)
|
await show_menu(menu, raise_on_cancel)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user