adriangalilea / streamlit-shortcuts

Streamlit keyboard shortcuts for your buttons.
MIT License
21 stars 4 forks source link

improve usage ergonomics #4

Closed github-actions[bot] closed 4 months ago

github-actions[bot] commented 4 months ago

https://github.com/adriangalilea/streamlit-shortcuts/blob/bfca99129ff68cb85987673cfe24d73d2da552c0/src/streamlit_shortcuts/streamlit_shortcuts.py#L5


import streamlit.components.v1 as components

# TODO bump to v0.1.2 for 'Meta modifier'
# TODO add keyboard tooltip to button (streamlit-extras)
# TODO improve usage ergonomics

def add_keyboard_shortcuts(key_combinations: dict[str, str]):
    """
adriangalilea commented 4 months ago

Instead of

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',
})

It can be:

import streamlit as st
from streamlit_shortcuts import button

def delete_callback():
    st.write("DELETED!")

streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut,="Ctrl+Shift+X")