https://github.com/daelonsuzuka/nicegui-command-palette
A VSCode/Sublime style Command Palette for NiceGUI applications
https://github.com/daelonsuzuka/nicegui-command-palette
command-palette component nicegui
Last synced: 5 months ago
JSON representation
A VSCode/Sublime style Command Palette for NiceGUI applications
- Host: GitHub
- URL: https://github.com/daelonsuzuka/nicegui-command-palette
- Owner: DaelonSuzuka
- License: mit
- Created: 2024-10-04T06:37:08.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-18T03:34:49.000Z (about 1 year ago)
- Last Synced: 2025-11-01T00:19:41.191Z (8 months ago)
- Topics: command-palette, component, nicegui
- Language: Python
- Homepage:
- Size: 1.96 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nicegui-command-palette
This plugin adds a command palette for NiceGUI applications.
## Installation
```sh
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.
```py
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:
```py
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