Skip to main content

Add search to Textual SelectionList.

Project description

Searchable SelectionList

image Project License - MIT

Add search to Textual's SelectionList.

  • Selectable items can be filtered by substring.
  • Select one or multiple items.
  • Search is case-insensitive.
  • Title and description can be customized.

Installation

pip install textual-searchable-selectionlist

Usage

from textual_searchable_selectionlist.options import SelectionStrategy
from textual_searchable_selectionlist.select import select, select_enum

selected = select(
    ['John', 'Jane', 'James'],
    selection_strategy=SelectionStrategy.MULTIPLE,
    search_title='Select people',
)

# Enums
# class Color(Enum):
#     RED = 'red'
#     GREEN = 'green'
#
# selected_colors = select_enum(Color, selection_strategy=SelectionStrategy.ONE)

Events and callbacks

Use selected_callback when embedding the widget, or listen for the SearchableListWidget.Selected message in your app.

from textual.app import App, ComposeResult
from textual_searchable_selectionlist.options import SelectionStrategy
from textual_searchable_selectionlist.searchable_list_widget import SearchableListWidget


class MyApp(App):
    def compose(self) -> ComposeResult:
        yield SearchableListWidget(
            "Alpha",
            "Beta",
            "Gamma",
            selection_strategy=SelectionStrategy.ONE,
            selected_callback=self._on_selected_callback,
        )

    def _on_selected_callback(self, selected: list[str]):
        self.log(f"Callback selected: {selected}")

    def on_searchable_list_widget_selected(
        self, event: SearchableListWidget.Selected
    ):
        self.log(f"Event selected: {event.selected}")

Testing

There are currently no automated tests. Manual testing can be done by running:

python tests/manual/searchable_selection_list_select.py

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

textual_searchable_selectionlist-0.0.6.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

textual_searchable_selectionlist-0.0.6-py2.py3-none-any.whl (10.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file textual_searchable_selectionlist-0.0.6.tar.gz.

File metadata

File hashes

Hashes for textual_searchable_selectionlist-0.0.6.tar.gz
Algorithm Hash digest
SHA256 ba3fb4054d7544fa8d1ac0cadc46dc655a5899b924e1f1a1444034e359f71b6e
MD5 b013671a00726519c5b4858cb5ffc626
BLAKE2b-256 1495564bc8088aac5db8a70ea59ae321f56372b1ca7a60fe1c4a097c21a0447c

See more details on using hashes here.

File details

Details for the file textual_searchable_selectionlist-0.0.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for textual_searchable_selectionlist-0.0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 802b56a538484b332ddc506e0a16c7dc81834dfaebd50931ea886a3028ebef8d
MD5 946cfcfb63db804cd1aab5198845dfea
BLAKE2b-256 99f0c04619aca6ff35b86bdcefea4175bb5107035b9eb2f29ddc8ca20587524e

See more details on using hashes here.

Supported by

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