Skip to main content

Adds Python functions/methods to the Windows context menu

Project description

Adds Python functions/methods to the Windows context menu

pip install shellextools

Here are some examples:

https://github.com/hansalemaos/ripgrepgui

https://github.com/hansalemaos/rc_collage

https://github.com/hansalemaos/rc_pictools

https://github.com/githubrobbi/Ultra-Fast-File-Search

Create a pyw file

from PIL import Image
from hackyargparser import add_sysargv
from shellextools import (
    format_folder_drive_path_backslash,
    add_multicommands_files,
    change_file_extension,
)
import sys


@add_sysargv
def main(path: str = "", action: str = ""):
    path = format_folder_drive_path_backslash(path)
    img = Image.open(path)

    if action == "convert2ico":
        iconfi = change_file_extension(path=path, extension="ico")
        img.resize((512, 512)).save(iconfi)
    if action == "convert2gray":
        iconfi = change_file_extension(path=path, prefix="gray_", extension="png")
        img.convert("L").save(iconfi)
    if action == "convert2bw":
        iconfi = change_file_extension(path=path, prefix="bw_", extension="png")
        img.convert("1").save(iconfi)
    return 0


if __name__ == "__main__":
    if len(sys.argv) == 1:
        futurnameofcompiledexe = "pictools.exe"
        multicommands = [
            {
                "mainmenuitem": "PicTools",
                "submenu": "Convert to .ico",
                "folderinprogramdata": "RCTools",
                "filetypes": ["bmp", "png", "jpg", "jpeg"],
                "additional_arguments": "--action convert2ico",
            },
            {
                "mainmenuitem": "PicTools",
                "submenu": "Convert to grayscale",
                "folderinprogramdata": "RCTools",
                "filetypes": ["bmp", "png", "jpg", "jpeg"],
                "additional_arguments": "--action convert2gray",
            },
            {
                "mainmenuitem": "PicTools",
                "submenu": "Convert to bw",
                "folderinprogramdata": "RCTools",
                "filetypes": ["bmp", "png", "jpg", "jpeg"],
                "additional_arguments": "--action convert2bw",
            },
        ]
        add_multicommands_files(multicommands, futurnameofcompiledexe)
    else:
        main()

Compile it with nutika

from nutikacompile import compile_with_nuitka

wholecommand = compile_with_nuitka(
    pyfile=r"C:\ProgramData\anaconda3\envs\nu\pictools.pyw",
    icon=r"C:\Users\hansc\Downloads\cova.jpg",
    disable_console=True,
    file_version="1.0.0.0",
    onefile=True,
    outputdir="c:\\nuitkapictoicon",
    addfiles=[
    ],
    delete_onefile_temp=False,  # creates a permanent cache folder
    needs_admin=True,
    arguments2add="--msvc=14.3 --noinclude-numba-mode=nofollow",
)

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

shellextools-0.15.tar.gz (19.2 kB view hashes)

Uploaded Source

Built Distribution

shellextools-0.15-py3-none-any.whl (20.9 kB view hashes)

Uploaded Python 3

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