A command palette for NiceGUI applications
Project description
nicegui-command-palette
This plugin adds a command palette for NiceGUI applications.
Installation
pip install nicegui-command-palette
Usage
Register commands to the CommandPalette
as a list of either strings or Command
objects.
A Command
can have a callback attached, which could be cleaner than checking the CommandPalette
's result.
Open the CommandPalette
by await
ing it. The returned value is the name of the command selected by the user, or None
if they dismissed the palette without selecting anything.
from command_palette import CommandPalette, Command
def some_action():
ui.notify('User picked the third option!')
commands = [
'one',
Command('two', 'Second'),
Command('three', 'Third', cb=some_action),
]
if result := await CommandPalette(commands):
# result is the name of the user's selection, or None
ui.notify(f'Selected: {result}')
Full example:
from nicegui import ui
from nicegui.events import KeyEventArguments
from command_palette import CommandPalette, Command
async def handle_key(e: KeyEventArguments):
# open the command palette when the user presses ctrl+shift+p
if e.action.keydown and e.modifiers.ctrl and e.modifiers.shift and e.key == 'P':
commands = [
'one',
Command('two', 'Second'),
Command('three', 'Third', cb=some_action),
]
if result := await CommandPalette(commands):
ui.notify(result)
ui.keyboard(on_key=handle_key)
ui.run()
Screenshots
Todo
- highlighting substring matches like in VSCode
- additional functions like specific prompts?
- improve matching algorithm
- figure out how to use the user fixture with dialogs
Project details
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
Close
Hashes for nicegui_command_palette-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d07652daa1b29e94fe7962dd5b88c4beebe8836023a52f8abdab1134033f8b7 |
|
MD5 | 80074251d7b467502a47ab65d5156d82 |
|
BLAKE2b-256 | 1b6f3fefda62d34129a7c9af4d7575b08bc55fd222c19c584518ec785add69de |
Close
Hashes for nicegui_command_palette-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1aed37595ead385401eaa49cbaa12d67e55ddd188acd3c9f30c78cf95e64371 |
|
MD5 | fb6b07c98b8f073cfbb5153eff937aae |
|
BLAKE2b-256 | 70d1c4c756dc3dd7404dbda8ed6837932263e5b120ee69d156a2c7a1acb2c4e4 |