Show the user an error message when pressing a key results in an exception
This commit is contained in:
parent
d7f569b341
commit
9161c71b51
2 changed files with 13 additions and 3 deletions
|
|
@ -1133,10 +1133,14 @@ def report_match(f: Callable[..., Any]) -> None:
|
|||
''')
|
||||
def combine(self, actions: Tuple[KeyAction, ...], window_for_dispatch: Optional[Window] = None, dispatch_type: str = 'KeyPress') -> bool:
|
||||
consumed = False
|
||||
if self.dispatch_action(actions[0], window_for_dispatch, dispatch_type):
|
||||
try:
|
||||
if self.dispatch_action(actions[0], window_for_dispatch, dispatch_type):
|
||||
consumed = True
|
||||
if len(actions) > 1:
|
||||
self.drain_actions(list(actions[1:]), window_for_dispatch, dispatch_type)
|
||||
except Exception as e:
|
||||
self.show_error('Key action failed', f'{actions[0].pretty()}\n{e}')
|
||||
consumed = True
|
||||
if len(actions) > 1:
|
||||
self.drain_actions(list(actions[1:]), window_for_dispatch, dispatch_type)
|
||||
return consumed
|
||||
|
||||
def on_focus(self, os_window_id: int, focused: bool) -> None:
|
||||
|
|
|
|||
|
|
@ -260,6 +260,12 @@ def __repr__(self) -> str:
|
|||
return f'KeyAction({self.func!r}, {self.args!r})'
|
||||
return f'KeyAction({self.func!r})'
|
||||
|
||||
def pretty(self) -> str:
|
||||
ans = self.func
|
||||
for x in self.args:
|
||||
ans += f' {x}'
|
||||
return ans
|
||||
|
||||
|
||||
def parse_kittens_func_args(action: str, args_funcs: Dict[str, KeyFunc[Tuple[str, Any]]]) -> KeyAction:
|
||||
parts = action.strip().split(' ', 1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue