Streamlit keyboard shortcuts for your buttons.
Project description
Streamlit Shortcuts
Streamlit Shortcuts allows you to easily add keyboard shortcuts to your Streamlit buttons.
Installation
pip install streamlit-shortcuts
Example
import streamlit as st
import streamlit_shortcuts
def delete_callback():
st.write("DELETED!")
streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut="Ctrl+Shift+X")
⭐ NEW in v0.1.5: Support for args and kwargs
import streamlit as st
import streamlit_shortcuts
def delete_callback(item_id, user="anonymous"):
st.write(f"Item {item_id} DELETED by {user}!")
streamlit_shortcuts.button(
"Delete",
shortcut="Ctrl+Shift+X",
on_click=delete_callback,
args=(42,),
kwargs={"user": "admin"},
type="primary"
)
This creates a primary Streamlit button labeled "Delete" with the shortcut "Ctrl+Shift+X".
When clicked (or activated via shortcut), it calls delete_callback(42, user="admin")
.
🥱 Old
import streamlit as st
from streamlit_shortcuts import add_keyboard_shortcuts
def delete_callback():
st.write("DELETED!")
st.button("delete", on_click=delete_callback)
add_keyboard_shortcuts({
'Ctrl+Shift+X': 'delete',
})
The 'Ctrl+Shift+X' combination will trigger "Another Button".
Keys
- 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:
- 'Ctrl+Enter'
- 'Shift+ArrowUp'
- 'Alt+Space'
For a complete list of key values, refer to: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
Versioning
We use semantic versioning. The current version is stored in the VERSION
file in the root of the repository.
Contributing
Contributions are welcome! If you have suggestions for improvements or bug fixes, please follow these steps:
- Fork the repository
- Create a new branch for your feature or bugfix
- Make your changes
- Add or update tests as necessary
- Update the
VERSION
file if your changes warrant a version bump - Submit a pull request
Please make sure to update tests as appropriate and adhere to the existing coding style.
Releasing New Versions
To release a new version:
- Update the
VERSION
file with the new version number - Commit the change:
git commit -am "Bump version to X.Y.Z"
- Create a new tag:
git tag vX.Y.Z
- Push the changes and the tag:
git push && git push --tags
The GitHub Actions workflow will automatically create a new release and publish to PyPI.
Contributors
- @toolittlecakes - Added 'Meta' modifier
- @quantum-ernest - Improved usage ergonomics
- @taylor-ennen - Fixed usage
flow
of code
Credits
Solution inspired by:
- https://github.com/streamlit/streamlit/issues/1291
- https://gist.github.com/brunomsantiago/e0ab366fc0dbc092c1a5946b30caa9a0
Special thanks to @brunomsantiago and @TomJohnH for their initial work on this concept.
Wrapped and extended for easier usage by the Streamlit Shortcuts team.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file streamlit_shortcuts-0.1.7.tar.gz
.
File metadata
- Download URL: streamlit_shortcuts-0.1.7.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20ebd8f7d112bb6f056025c3c7412b2eb62c974a2252e8083bd9fb9a2822682e |
|
MD5 | 44189d5d30cf86c5933e0590a1ff3646 |
|
BLAKE2b-256 | 97a6df904f2cd2fb620aef66d46ab46cb475bac78638a8224d2e4a567a2dd057 |
File details
Details for the file streamlit_shortcuts-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: streamlit_shortcuts-0.1.7-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 258dda14345d420ec689f1d324674f3a2330e7f32f9ad9c9d4c5c1c811deaca1 |
|
MD5 | 6ffd20e5e69e2cfee37413f027071e5d |
|
BLAKE2b-256 | f438ce3c916ae194015eeda40b0eddb0373aece2ef5e5f80757b384871070bf5 |