From 2470846549e3cb5933275fa9659f03d9db5c6f81 Mon Sep 17 00:00:00 2001 From: Taylor E <70374690+taylor-ennen@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:03:04 -0700 Subject: [PATCH 1/3] Update streamlit_shortcuts.py "control" -> "ctrl" update to reflect uniform syntax across file --- src/streamlit_shortcuts/streamlit_shortcuts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/streamlit_shortcuts/streamlit_shortcuts.py b/src/streamlit_shortcuts/streamlit_shortcuts.py index 4f1beb4..d4d9d0f 100644 --- a/src/streamlit_shortcuts/streamlit_shortcuts.py +++ b/src/streamlit_shortcuts/streamlit_shortcuts.py @@ -12,12 +12,12 @@ def add_keyboard_shortcuts(key_combinations: dict[str, str]): Add keyboard shortcuts to trigger Streamlit buttons. Keys: - - Modifiers: 'Control', 'Shift', 'Alt' + - Modifiers: 'Ctrl', 'Shift', 'Alt' - Common Keys: 'Enter', 'Escape', 'Space' - Arrow Keys: 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown' Examples of Key Combinations: - - 'Control+Enter' + - 'Ctrl+Enter' - 'Shift+ArrowUp' - 'Alt+Space' From 4b3f3acce5795c9b261dda4e7bc4d21e506060a2 Mon Sep 17 00:00:00 2001 From: Taylor E <70374690+taylor-ennen@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:08:20 -0700 Subject: [PATCH 2/3] Replace Dict with Str in button def, added dict builder using label Removed the type hinting on the `shortcut: parameter' to take a `str` instead of a `dict`. We now properly use the `label: parameter` build the `dict` with the `shortcut: str` passed into the button making the needed `dict` for the `add_keyboard_shortcuts`. --- src/streamlit_shortcuts/streamlit_shortcuts.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/streamlit_shortcuts/streamlit_shortcuts.py b/src/streamlit_shortcuts/streamlit_shortcuts.py index d4d9d0f..3e7d2a6 100644 --- a/src/streamlit_shortcuts/streamlit_shortcuts.py +++ b/src/streamlit_shortcuts/streamlit_shortcuts.py @@ -57,6 +57,7 @@ def add_keyboard_shortcuts(key_combinations: dict[str, str]): components.html(js_code, height=0, width=0) -def button(label: str, shortcut: dict[str, str], on_click: Callable[..., None]): +def button(label: str, shortcut: str, on_click: Callable[..., None]): + shortcut={shortcut: label} st.button(label=label, on_click=on_click) add_keyboard_shortcuts(shortcut) From 01845d95ecdcf7471cead17404365e2581ceb2b0 Mon Sep 17 00:00:00 2001 From: Taylor E <70374690+taylor-ennen@users.noreply.github.com> Date: Tue, 30 Apr 2024 14:11:27 -0700 Subject: [PATCH 3/3] Updated Control->Ctrl, Removed --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 72a06da..dd224f9 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ import streamlit_shortcuts def delete_callback(): st.write("DELETED!") -streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut,="Ctrl+Shift+X") +streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut="Ctrl+Shift+X") ``` 🥱 Old @@ -40,12 +40,12 @@ add_keyboard_shortcuts({ The 'Ctrl+Shift+X' combination will trigger "Another Button". ## Keys -- Modifiers: 'Control', 'Shift', 'Alt', 'Meta' ('Cmd' on Mac or 'Win' on Windows, thanks to @toolittlecakes) +- Modifiers: 'Ctrl', 'Shift', 'Alt', 'Meta' ('Cmd' on Mac or 'Win' on Windows, thanks to @toolittlecakes) - Common Keys: 'Enter', 'Escape', 'Space' - Arrow Keys: 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown' Examples of Key Combinations: -- 'Control+Enter' +- 'Ctrl+Enter' - 'Shift+ArrowUp' - 'Alt+Space' @@ -62,6 +62,8 @@ Contributions are welcome! If you have suggestions for improvements or bug fixes @quantum-ernest - Improved usage ergonomics +@taylor-ennen - Fixed usage `flow` of code + ## Credits Solution seen on: https://github.com/streamlit/streamlit/issues/1291