Skip to main content

Windows Context Menus

Create native Windows Explorer context menus declaratively in Python

Quick example

Its common to download an image file, just for it to be some .jfif nonsense. Or maybe you have some .jpg but you need a .ico for uploading icons? And now you need to upload them to some thirdparty site that converts it to .jpg or .ico for you. What if you could do that natively from your Windows Explorer?

Provided imagemagick is installed:

# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "windows_context_menus",
# ]
#
# [tool.uv.sources]
# windows_context_menus = { git = "https://github.com/orishamir/WindowsContextMenus", tag = "0.1.3" }
# ///
"""Adds a context menu for converting images from and to formats."""

from windows_context_menus import CommandPlaceholder, Condition, ContextMenu, ContextMenuBinding, ExplorerItemType, RegistryHandler

CONVERT_IMAGE_COMMAND = f'cmd.exe /c magick "{CommandPlaceholder.FIRST_SELECTED}" "{CommandPlaceholder.FIRST_SELECTED}".{{}}'

convert_to_png_entry = ContextMenu(
    display_text="Convert to PNG",
    command=CONVERT_IMAGE_COMMAND.format("png"),
    condition=Condition.model_validate({"extension": {"ne": ".png"}}),
)

convert_to_jpeg_entry = ContextMenu(
    display_text=("Convert to JPEG"),
    command=CONVERT_IMAGE_COMMAND.format("jpeg"),
    condition=Condition.model_validate({"extension": {"ne": ".jpeg"}}),
)

convert_to_ico_entry = ContextMenu(
    display_text=("Convert to ICO"),
    command=CONVERT_IMAGE_COMMAND.format("ico"),
    condition=Condition.model_validate({"extension": {"ne": ".ico"}}),
)

convert_to_bmp_entry = ContextMenu(
    display_text=("Convert to BMP"),
    command=CONVERT_IMAGE_COMMAND.format("bmp"),
    condition=Condition.model_validate({"extension": {"ne": ".bmp"}}),
)

main: ContextMenu = ContextMenu(
    display_text=("Convert to..."),
    selection_limit=1,  # This menu supports only 1 file at a time.
    condition=Condition.model_validate(
        {
            "extension": {
                "in": [
                    ".png",
                    ".jpeg",
                    ".jpg",
                    ".bmp",
                    ".ico",
                    ".webp",
                    ".avif",
                    ".jfif",
                ],
            },
        },
    ),
    submenus=[convert_to_png_entry, convert_to_ico_entry, convert_to_jpeg_entry, convert_to_bmp_entry],
)

if __name__ == "__main__":
    RegistryHandler().apply_context_menu(
        main,
        bindings=[
            ContextMenuBinding(
                ExplorerItemType.ALL_FILES,
            ),
        ],
    )

Produces:
convert_image.png

For a more complicated example, see Documentation

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

windows_context_menus-0.1.3.tar.gz (160.6 kB view details)

Uploaded Source

Built Distribution

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

windows_context_menus-0.1.3-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file windows_context_menus-0.1.3.tar.gz.

File metadata

  • Download URL: windows_context_menus-0.1.3.tar.gz
  • Upload date:
  • Size: 160.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for windows_context_menus-0.1.3.tar.gz
Algorithm Hash digest
SHA256 269145478fae5584d2e3f26ce29dee4591641056d044394542d56371087b18f5
MD5 26e5b7b84f98bcf46b4191b11d8bd970
BLAKE2b-256 4af5c1807b650f222efb43c51849e4279200983878654894797850858ce4b0b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for windows_context_menus-0.1.3.tar.gz:

Publisher: create-new-version.yml on orishamir/WindowsContextMenus

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

File details

Details for the file windows_context_menus-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for windows_context_menus-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 71003f27e32c49d0f2565efd5eb53d4d010d5c3222e3bfed04edd9acd5faac34
MD5 1b0187b99ad602c40b5de4f11e725ae0
BLAKE2b-256 e9aadcbf0b17732ab7d2f6ddbbc8750713053587f2db7118e36ba3d08d663ee9

See more details on using hashes here.

Provenance

The following attestation bundles were made for windows_context_menus-0.1.3-py3-none-any.whl:

Publisher: create-new-version.yml on orishamir/WindowsContextMenus

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

Release history Release notifications | RSS feed

0.1.4

2 files

This release

0.1.3 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page