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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 252d178bae2d4f288912c01793457146213cfe166723f1167ac327c640b93d84 |
|
MD5 | a2c57c04a1ccc4ccb9d519be605d7693 |
|
BLAKE2b-256 | d963999326a509356ba1c3c4ff456a5253e32bc372509900892515efeefb7136 |
Close
Hashes for nicegui_command_palette-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71f3e6fc444f80e2f65b546cf2cd989819f2ecb2bc2dc672fd1ab69f42e5d933 |
|
MD5 | b4b412783f58843a5599b99741f0d424 |
|
BLAKE2b-256 | d6dcc259d56766070ecea77d0f8da18a79b05d57d660ac9d1e4b6598adc93930 |