Skip to main content

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

screenshot usage

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

nicegui_command_palette-0.3.2.tar.gz (1.8 MB view hashes)

Uploaded Source

Built Distribution

nicegui_command_palette-0.3.2-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page