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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file nicegui_command_palette-0.3.2.tar.gz.

File metadata

File hashes

Hashes for nicegui_command_palette-0.3.2.tar.gz
Algorithm Hash digest
SHA256 9abf208cb3aec754c6c01e5e075b84ff9146c81d430a2e75e9d4a1f6c75246d2
MD5 d7c19c147cf6b90cce10206fc6c39a7d
BLAKE2b-256 362981d9be17f07354f4c556413558c658f825ea81db5005fcc85129699a6853

See more details on using hashes here.

File details

Details for the file nicegui_command_palette-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for nicegui_command_palette-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d40c39954d5fc3d713bf551d7737f8442bd16ae878308f5081b654cabbd103ea
MD5 d2e276e6ef298eb22061be1f54dfeca3
BLAKE2b-256 90f43b23a3953442f234995911d6ce6820b56beb7ee849ad9420f3f9728f504d

See more details on using hashes here.

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