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 awaiting 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nicegui_command_palette-0.3.2.tar.gz.
File metadata
- Download URL: nicegui_command_palette-0.3.2.tar.gz
- Upload date:
- Size: 1.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9abf208cb3aec754c6c01e5e075b84ff9146c81d430a2e75e9d4a1f6c75246d2
|
|
| MD5 |
d7c19c147cf6b90cce10206fc6c39a7d
|
|
| BLAKE2b-256 |
362981d9be17f07354f4c556413558c658f825ea81db5005fcc85129699a6853
|
File details
Details for the file nicegui_command_palette-0.3.2-py3-none-any.whl.
File metadata
- Download URL: nicegui_command_palette-0.3.2-py3-none-any.whl
- Upload date:
- Size: 5.9 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 |
d40c39954d5fc3d713bf551d7737f8442bd16ae878308f5081b654cabbd103ea
|
|
| MD5 |
d2e276e6ef298eb22061be1f54dfeca3
|
|
| BLAKE2b-256 |
90f43b23a3953442f234995911d6ce6820b56beb7ee849ad9420f3f9728f504d
|