Skip to main content

VCollab Selection - generic single-select container for keyed options

Project description

Selection

Generic single-select container for keyed options.

Overview

vcti-selection provides Selection[T], a small generic container for managing a collection of options where exactly one option can be selected at a time. Options are stored by string keys and the selected option can be changed, cleared, or removed at any time.

Typical uses are modelling UI single-choice state (theme, view mode, current dataset) and tracking the "active" item among several. It has zero dependencies and is not thread-safe — callers synchronize if needed.

Installation

pip install vcti-selection

In requirements.txt

vcti-selection>=2.1.0

In pyproject.toml dependencies

dependencies = [
    "vcti-selection>=2.1.0",
]

Quick Start

from vcti.selection import Selection

# Construct from a mapping — first key is auto-selected
themes = Selection[str]({
    "dark":   "Dark Theme",
    "light":  "Light Theme",
    "system": "System Theme",
})

print(themes.selected)      # "Dark Theme"
print(themes.selected_key)  # "dark"

themes.select("light")
print(themes.selected)      # "Light Theme"

# Cycle through keys in insertion order, wrapping at the ends
themes.select_next()        # "system"
themes.select_next()        # "dark" (wrapped)

# Clear the selection; deselect() returns the previous key
previous = themes.deselect()
print(previous)             # "dark"
print(themes.selected)      # None

Holding any value type

from dataclasses import dataclass
from vcti.selection import Selection

@dataclass
class View:
    title: str
    renderer: str

views = Selection[View]({
    "plot":  View("Plot view",  "matplotlib"),
    "table": View("Table view", "pandas"),
}, selected="table")

active = views.selected  # View(title="Table view", renderer="pandas")

Dict-like access

sel = Selection[str]({"a": "Alpha", "b": "Beta"})

"a" in sel                  # True
sel["a"]                    # "Alpha"
sel.get("missing", "—")     # "—"
list(sel.keys())            # ["a", "b"]
list(sel.items())           # [("a", "Alpha"), ("b", "Beta")]
for key in sel: ...         # iterates keys

Dependencies

None. Standard library only.

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

vcti_selection-2.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

vcti_selection-2.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file vcti_selection-2.1.0.tar.gz.

File metadata

  • Download URL: vcti_selection-2.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vcti_selection-2.1.0.tar.gz
Algorithm Hash digest
SHA256 671614826b9a9b072f76724a90c9250394ac2c13800d4096f8662313878b885d
MD5 6e7b26de0552befa7aeec5eb670c2a24
BLAKE2b-256 d8acfaefed5d1fec9770d7390910dc28674686e81eaaba9abc7353fc889a9089

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_selection-2.1.0.tar.gz:

Publisher: publish.yml on vcollab/vcti-python-selection

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vcti_selection-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: vcti_selection-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vcti_selection-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d6907ed8449e802e8303cf38a12aec34be0cb9fbacf44abe283324d93571987
MD5 bb0b742206ed45a62fb6032f3af45cc9
BLAKE2b-256 b8b7dc59e4d9a3784f178316c1d908a411f8858166bcd9504caf99326acf635a

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_selection-2.1.0-py3-none-any.whl:

Publisher: publish.yml on vcollab/vcti-python-selection

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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