Skip to main content

helper functions for xbar menus

Project description

Python library to make xbar development easy in python

Include this in your file after the regular imports

def install(pkg: str, spec: str = "", cache_dir: Path | str = "~/.cache"):
    import os, sys, pip, importlib, importlib.metadata  # isort: skip # noqa: E401
    from pip._vendor.packaging.requirements import Requirement
    name, cache = Path(__file__), Path(os.environ.get("XDG_CACHE_HOME", cache_dir))
    sitep = (cache / f"pyxbar/{name.name}/site-packages").expanduser().as_posix()
    sys.path += [] if sitep in sys.path else [sitep]
    try:
        requirement = Requirement(spec or pkg)
        assert importlib.metadata.version(requirement.name) in requirement.specifier
    except Exception as e:
        pip.main(["install", "--upgrade", f"--target={sitep}", *(spec or pkg).split()])
        importlib.invalidate_caches()


# install the PyXbar library from pypi
install("pyxbar")

# use it!
from pyxbar import (
    Config,
    Divider,
    Menu,
    MenuItem,
    Renderable,
    ShellItem,
)


class MyConfig(Config):
    MYVARIABLE: bool = True
    ...

CONFIG = get_config(MyConfig)  # type: ignore




if __name__ == "__main__":
    Menu("some title").with_items(
        Divider(),  # shortcut for ---, also handles submenu depth
        MenuItem(
            "👁️ overview",
        ).with_submenu(
            MenuItem("hi, i'm a submenu!").
            MenuItem("hi, i'm monospace!", monospaced=True)
        ),
    ).print()

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

pyxbar-0.3.30.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

pyxbar-0.3.30-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file pyxbar-0.3.30.tar.gz.

File metadata

  • Download URL: pyxbar-0.3.30.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for pyxbar-0.3.30.tar.gz
Algorithm Hash digest
SHA256 aee57197b6a3de847d70bb4f1775803b29d5c1118f306d3e3f41038a1035bec6
MD5 2a64ee497616e3f322f325397a7d7ee5
BLAKE2b-256 a1de65ad794afde339f9b78ca4f611b24f7dc1df38e36a4bccaab8cc54d555f9

See more details on using hashes here.

File details

Details for the file pyxbar-0.3.30-py3-none-any.whl.

File metadata

  • Download URL: pyxbar-0.3.30-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for pyxbar-0.3.30-py3-none-any.whl
Algorithm Hash digest
SHA256 f868013143719776f3653a23dc620692e6eb4cfba5e3904e2277e76622023612
MD5 9c310b1476cacf26173b5705ae2b65a8
BLAKE2b-256 f806ccaaee9a1bbb36d691ac7ab0e6166b12bf3f55e4b5c5882ae1859d5d212a

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