Custom key bindings.
(python_input: PythonInput)
| 52 | |
| 53 | |
| 54 | def load_python_bindings(python_input: PythonInput) -> KeyBindings: |
| 55 | """ |
| 56 | Custom key bindings. |
| 57 | """ |
| 58 | bindings = KeyBindings() |
| 59 | |
| 60 | sidebar_visible = Condition(lambda: python_input.show_sidebar) |
| 61 | handle = bindings.add |
| 62 | |
| 63 | @handle("c-l") |
| 64 | def _(event: E) -> None: |
| 65 | """ |
| 66 | Clear whole screen and render again -- also when the sidebar is visible. |
| 67 | """ |
| 68 | event.app.renderer.clear() |
| 69 | |
| 70 | @handle("c-z") |
| 71 | def _(event: E) -> None: |
| 72 | """ |
| 73 | Suspend. |
| 74 | """ |
| 75 | if python_input.enable_system_bindings: |
| 76 | event.app.suspend_to_background() |
| 77 | |
| 78 | # Delete word before cursor, but use all Python symbols as separators |
| 79 | # (WORD=False). |
| 80 | handle("c-w")(get_by_name("backward-kill-word")) |
| 81 | |
| 82 | @handle("f2") |
| 83 | def _(event: E) -> None: |
| 84 | """ |
| 85 | Show/hide sidebar. |
| 86 | """ |
| 87 | python_input.show_sidebar = not python_input.show_sidebar |
| 88 | if python_input.show_sidebar: |
| 89 | event.app.layout.focus(python_input.ptpython_layout.sidebar) |
| 90 | else: |
| 91 | event.app.layout.focus_last() |
| 92 | |
| 93 | @handle("f3") |
| 94 | def _(event: E) -> None: |
| 95 | """ |
| 96 | Select from the history. |
| 97 | """ |
| 98 | python_input.enter_history() |
| 99 | |
| 100 | @handle("f4") |
| 101 | def _(event: E) -> None: |
| 102 | """ |
| 103 | Toggle between Vi and Emacs mode. |
| 104 | """ |
| 105 | python_input.vi_mode = not python_input.vi_mode |
| 106 | |
| 107 | @handle("f6") |
| 108 | def _(event: E) -> None: |
| 109 | """ |
| 110 | Enable/Disable paste mode. |
| 111 | """ |