Coder Social home page Coder Social logo

streamlit-shortcuts's Introduction

Streamlit Shortcuts

Streamlit Shortcuts allows you to easily add keyboard shortcuts to your Streamlit buttons.

Installation

pip install streamlit-shortcuts

Example

⭐ NEW! thanks to @quantum-ernest

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")

🥱 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

Contributing

Contributions are welcome! If you have suggestions for improvements or bug fixes, please feel free to make a pull request or open an issue.

Contributors

@toolittlecakes - Added 'Meta' modifier

@quantum-ernest - Improved usage ergonomics

@taylor-ennen - Fixed usage flow of code

Credits

Solution seen on: streamlit/streamlit#1291

https://gist.github.com/brunomsantiago/e0ab366fc0dbc092c1a5946b30caa9a0

@brunomsantiago

@TomJohnH

And wrapped for comfier usage.

streamlit-shortcuts's People

Contributors

adriangalilea avatar taylor-ennen avatar toolittlecakes avatar quantum-ernest avatar

Stargazers

 avatar  avatar  avatar James Chen avatar ThatOneCoder20 avatar David Lee avatar Thiên Nhật avatar Dan Stanton avatar Dickson Neoh avatar G avatar Bruno Santiago avatar

Watchers

 avatar

streamlit-shortcuts's Issues

Readme example does not match code functionality

In the section of readme containing the new example usage, 'shortcut' is passed a string however the code calls for a dictionary, I would provide the fix myself but I'm not sure the direction your headed, keeping the dictionary or implement strings for the single button example that's been added.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.