{"id":13500203,"url":"https://github.com/saleguas/context_menu","last_synced_at":"2025-08-31T17:06:43.805Z","repository":{"id":48165181,"uuid":"264610552","full_name":"saleguas/context_menu","owner":"saleguas","description":"💻 A Python library to create and deploy cross-platform native context menus. 💻","archived":false,"fork":false,"pushed_at":"2024-09-14T17:11:04.000Z","size":14520,"stargazers_count":478,"open_issues_count":12,"forks_count":27,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-26T15:55:52.571Z","etag":null,"topics":["context-menu","library","linux","metaprogramming","python","registry","windows"],"latest_commit_sha":null,"homepage":"https://context-menu.readthedocs.io/en/latest/index.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saleguas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-17T07:50:35.000Z","updated_at":"2025-03-26T06:45:13.000Z","dependencies_parsed_at":"2024-06-19T16:03:55.032Z","dependency_job_id":"6fa5c98e-3d69-4c12-bfe3-1d904629e6ea","html_url":"https://github.com/saleguas/context_menu","commit_stats":{"total_commits":94,"total_committers":8,"mean_commits":11.75,"dds":"0.34042553191489366","last_synced_commit":"7bda7330b957d83929fea975ecefbc4e8ceb66dd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saleguas%2Fcontext_menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saleguas%2Fcontext_menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saleguas%2Fcontext_menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saleguas%2Fcontext_menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saleguas","download_url":"https://codeload.github.com/saleguas/context_menu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246145013,"owners_count":20730494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["context-menu","library","linux","metaprogramming","python","registry","windows"],"created_at":"2024-07-31T22:00:53.205Z","updated_at":"2025-03-29T05:33:16.763Z","avatar_url":"https://github.com/saleguas.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# 🗂️[context_menu](https://github.com/saleguas/context_menu) [![build passing](https://github.com/saleguas/context_menu/actions/workflows/ci.yml/badge.svg)](https://github.com/saleguas/context_menu/actions/workflows/ci.yml)   [![readthedocs](https://img.shields.io/readthedocs/context_menu)](https://context-menu.readthedocs.io/en/latest/) ![pip](https://img.shields.io/badge/pip-context__menu-blue) [![Downloads](https://pepy.tech/badge/context-menu)](https://pepy.tech/project/context-menu)\n\n![logo](media/logo.png)\n\n💻 A Python library to create and deploy cross-platform native context menus. 💻\n\n\nDocumentation available at: https://context-menu.readthedocs.io/en/latest/\n\n* * *\n\n![example usage](media/thumbnail2.gif)\n\n* * *\n\n# Table of Contents\n- [⚙ Features ⚙](#-features-)\n  * [🙋 What is the context menu? 🙋](#-what-is-the-context-menu-)\n  * [🖥️ What Operating Systems are supported? 🖥️](#%EF%B8%8F-what-operating-systems-are-supported-%EF%B8%8F)\n  * [🐍 What Python versions are supported? 🐍](#-what-python-versions-are-supported-)\n- [💽 Installation 💽](#-installation-)\n- [🕹️ Quickstart 🕹️](#%EF%B8%8F-quickstart-%EF%B8%8F)\n- [🤖 Advanced Usage 🤖](#-advanced-usage-)\n  * [The `ContextMenu` Class](#the-contextmenu-class)\n  * [The `ContextCommand` Class](#the-contextcommand-class)\n  * [The `FastCommand` Class](#the-fastcommand-class)\n  * [The `removeMenu` method](#the-removemenu-method)\n  * [The `params` Command Parameter](#the-params-command-parameter)\n  * [`command_vars` Command Parameter](#command_vars-command-parameter)\n  * [Opening on Files](#opening-on-files)\n  * [Activation Types](#activation-types)\n- [🏁 Goals 🏁](#-goals-)\n- [🙌 Contribution 🙌](#-contribution-)\n- [📓 Important notes 📓](#-important-notes-)\n- [💻 Freshen - A context_menu project! 💻](#-freshen---a-context_menu-project-)\n- [💙 Support 💙](#-support-)\n\n# ⚙ Features ⚙\nThis library lets you edit the entries on the right click menu for Windows and Linux using pure Python. It also allows you to make cascading context menus!\n\ncontext_menu was created as due to the lack of an intuitive and easy to use cross-platform context menu library. The\nlibrary allows you to create your own context menu entries and control their behavior seamlessly in native Python. The\nlibrary has the following features:\n\n* Written in pure python with no other dependencies\n* Extremely intuitive design inspired by Keras Tensorflow\n* Swift installation from Python's Package Manager (pip)\n* Painless context menu creation\n* Cascading context menu support\n* The ability to natively integrate python functions from a context entry call\n* Detailed documentation\n\n## 🙋 What is the context menu? 🙋\n\nThe context menu is the window that is displayed when you right click:\n\n![img.png](media/context_menu.png)\n\nThe context menu is different depending on what was right clicked. For example, right clicking a folder will give you\ndifferent options than right clicking a file.\n\n## 🖥️ What Operating Systems are supported? 🖥️ \n\nCurrently, the only operating systems supported are:\n\n- Windows 7\n- Windows 10\n- Windows 11\n- Linux (Using Nautilus)\n\n## 🐍 What Python versions are supported? 🐍\n\n**All python versions 3.7 and above** are supported.\n\n# 💽 Installation 💽\n\nIf you haven't installed Python, download and run an installer from the official\nwebsite: https://www.python.org/downloads/\n\nOnce you have Python, the rest is super simple. Simply just run the following command in a terminal to install the\npackage:\n\n```commandline\npython -m pip install context_menu\n```\n\nor if you're on Linux:\n\n```commandline\npython3 -m pip install context_menu\n```\n\n_Note: If you're on Windows and it says the command isn't recognized, make sure to\nadd [Python to your path](https://datatofish.com/add-python-to-windows-path/) and run the command prompt as\nadministrator_\n\n# 🕹️ Quickstart 🕹️\n\nLet's say you want to make a basic context menu entry when you right click a file.\n\n1. If you haven't already Install the library via pip:\n\n```commandline\npython -m pip install context_menu\n```\n\n2. Create and compile the menu:\n\nIt's super easy!\nYou can create entries in as little as 3 lines:\n\n```python\nfrom context_menu import menus\n\nfc = menus.FastCommand('Example Fast Command 1', type='FILES', command='echo Hello')\nfc.compile()\n```\n\n![example fast command](media/example_fast_command.png)\n\n\u003e **Note:** On Windows, the command `echo Hello` may not work as expected because `echo` is a built-in command of the cmd shell. To execute such commands on Windows, you need to prefix them with `cmd /c`. So the command becomes:\n\u003e \n\u003e ```python\n\u003e fc = menus.FastCommand('Example Fast Command 1', type='FILES', command='cmd /c echo Hello')\n\u003e ```\n\u003e \n\u003e This ensures that the command is run within the cmd shell.\n\nAll you have to do is import the library and define the type of context entry you want. The options are:\n\n* A context menu (an entry that has more entries)\n* A fast command (a single context menu entry to kick a running script)\n* A context command which can be added to menus for more complex commands\n\nYou can also create much more complicated nested menus:\n\n```Python\ndef foo2(filenames, params):\n    print('foo2')\n    print(filenames)\n    input()\n\n\ndef foo3(filenames, params):\n    print('foo3')\n    print(filenames)\n    input()\n\n\nif __name__ == '__main__':\n    from context_menu import menus\n\n    cm = menus.ContextMenu('Foo menu', type='FILES')\n    cm2 = menus.ContextMenu('Foo Menu 2')\n    cm3 = menus.ContextMenu('Foo Menu 3')\n\n    cm3.add_items([\n        menus.ContextCommand('Foo One', command='echo hello \u003e example.txt'),\n    ])\n    cm2.add_items([\n        menus.ContextCommand('Foo Two', python=foo2),\n        cm3,\n    ])\n    cm.add_items([\n        cm2,\n        menus.ContextCommand('Foo Three', python=foo3)\n    ])\n\n    cm.compile()\n```\n\n![second Example](media/second_example.png)\n\nAll context menus are **permanent** unless you remove them.\n\n# 🤖 Advanced Usage 🤖\n\n## The `ContextMenu` Class\n\nThe [ContextMenu](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu) object\nholds other context objects. It expects a name, **the activation type** if it is the root menu(the first menu), and an optional icon path. Only\ncompile the root menu.\n\n```Python\nContextMenu(name: str, type: str = None, icon_path: str = None)\n```\n\nMenus can be added to menus, creating cascading context menus. You can use\nthe [{MENU}.add_items{ITEMS}](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu.add_items)\nfunction to add context elements together, for example:\n\n```Python\ncm = menus.ContextMenu('Foo menu', type='DIRECTORY_BACKGROUND')\ncm.add_items([\n    menus.ContextMenu(...),\n    menus.ContextCommand(...),\n    menus.ContextCommand(...)\n])\ncm.compile()\n```\n\nYou have to\ncall [{MENU}.compile()](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu.compile)\nin order to create the menu.\n\n## The `ContextCommand` Class\n\nThe [ContextCommand](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextCommand)\nclass creates the selectable part of the menu (you can click it). It requires a name, and either a Python function or a\ncommand **(but NOT both)** and has various other options\n\n```Python\nContextCommand(name: str, command: str = None, python: 'function' = None, params: str = None, command_vars: list = None, icon_path: str = None)\n```\n\nPython functions can be passed to this method, regardless of their location. **However, the function must accept only\ntwo parameters `filenames`, which is a list of paths\\*, and `params`, the parameters passed to the function**. and if\nthe function is in the same file as the menu, you have to surround it with `if __name__ == '__main__':`\n\n```python\n# An example of a valid function\ndef valid_function(filenames, params):\n    print('Im valid!')\n    print(filenames)\n    print(params)\n\n\n# Examples of invalid functions\ndef invalid_function_1(filenames, param1, param2):\n    print('Im invalid!')\n    print(filenames)\n\n\ndef invalid_function_2(params):\n    print('Im invalid!')\n    print(params)\n```\n\nAny command passed (as a string) will be directly ran from the shell.\n\n## The `FastCommand` Class\n\nThe [FastCommand](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.FastCommand) class\nis an extension of the ContextMenu class and allows you to quickly create a single entry menu. It expects a name, type,\ncommand/function and an optional icon path.\n\n```python\nFastCommand(\n    name: str, type: str, command: str = None, python: 'function' = None, params: str = '', command_vars: list = None, icon_path: str = None)\n```\n\n```python\ndef foo1(filenames, params):\n    print(filenames)\n    input()\n\n\nif __name__ == '__main__':\n    from context_menu import menus\n\n    fc = menus.FastCommand('Example Fast Command 1', type='FILES', python=foo1)\n    fc.compile()\n```\n\n## The `removeMenu` method\n\nYou can remove a context menu entry easily as well. Simply call the ['menus.removeMenu()'](\u003c\u003e) method.\n\n```python\nremoveMenu(name: str, type: str)\n```\n\nFor example, if I wanted to remove the menu 'Foo Menu' that activated on type 'FILES':\n\n```python\nfrom context_menu import menus\n\nmenus.removeMenu('Foo Menu', 'FILES')\n```\n\nand boom! It's gone 😎\n\n## The `params` Command Parameter\n\nIn both the `ContextCommand` class and `FastCommand` class you can pass in a parameter, defined by the `parameter=None`\nvariable. **This value MUST be a string!** This means instead of passing a list or numbers, pass it as a string\nseparated by spaces or whatever to delimitate it.\n\n```Python\nfc = menus.FastCommand('Example Fast Command 1', type='FILES', python=foo1, params='a b c d e')\nfc.compile()\n```\n\nFor more information, [see this.](https://github.com/saleguas/context_menu/issues/4)\n\nWorks on the `FastCommand` and `ContextCommand` class.\n\n## `command_vars` Command Parameter\n\nIf you decide to pass a shell command, you can access a list of special variables. For example, if I wanted to run a\ncustom command with the file selected, I could use the following:\n\n```Python\nfc = menus.FastCommand('Weird Copy', type='FILES', command='touch ?x', command_vars=['FILENAME'])\nfc.compile()\n```\n\nwhich would create a new file with the name of whatever I selected with an 'x' on the end. The `?` variable is\ninterpreted from left to right and replaced with the selected\nvalues [(see this)](https://github.com/saleguas/context_menu/issues/3).\n\nAll of the preset values are as follows:\n\n| Name          | Function                                |\n| ------------- | --------------------------------------- |\n| FILENAME      | The path to the file selected           |\n| DIR/DIRECTORY | The directory the script was ran in.    |\n| PYTHONLOC     | The location of the python interpreter. |\n\nWorks on the `FastCommand` and `ContextCommand` class.\n\n## Opening on Files\n\nLet's say you only want your context menu entry to open on a certain type of file, such as a `.txt` file. You can do\nthis by adding a `type` variable to the `ContextCommand` or `FastCommand` class.\n\n```Python\nfc = menus.FastCommand('Weird Copy', type='.txt', command='touch ?x',\n                       command_vars=['FILENAME'])  # opens only on .txt files\nfc.compile()\n```\n\nNow you'll only see the \"Weird Copy\" menu entry when you right click a .txt file.\n\n## Activation Types\n\nThere are different locations where a context menu can fire. For example, if you right click on a folder you'll get\ndifferent options than if you right click on a file. The `type` variable controls this behavior in the library, and you\ncan reference this table to determine the `type`:\n\n| Name                 | Location                                                           | Action                                   |\n| -------------------- | ------------------------------------------------------------------ | ---------------------------------------- |\n| FILES                | HKEY_CURRENT_USER\\\\Software\\\\Classes\\\\\\*\\\\shell\\\\                  | Opens on a file                          |\n| DIRECTORY            | HKEY_CURRENT_USER\\\\Software\\\\Classes\\\\Directory\\\\shell             | Opens on a directory                     |\n| DIRECTORY_BACKGROUND | HKEY_CURRENT_USER\\\\Software\\\\Classes\\\\Directory\\\\Background\\\\shell | Opens on the background of the Directory |\n| DRIVE                | HKEY_CURRENT_USER\\\\Software\\\\Classes\\\\Drive\\\\shell                 | Opens on the drives(think USBs)          |\n| DESKTOP              | Software\\\\Classes\\\\DesktopBackground\\\\shell                        | Opens on the background of the desktop   |\n\n* * *\n\nI strongly recommend checking out the [examples folder](examples) for more complicated examples and usage.\n\nYou can check out the official documentation [here](https://context-menu.readthedocs.io/en/latest/index.html).\n\n\n* * *\n\n# 🏁 Goals 🏁\n\nThis project tackles some pretty big issues, and there's definetly some goals that I'd like to accomplish. The current roadmap is as follows:\n\n* Support for other Linux distributions\n* Better approach to the Linux GNOME integration\n* Mac support\n* Bypass 16 entry limit on windows\n\nIf by all means you want to help reach these milestones, see contribution below.\n\n# 🙌 Contribution 🙌\n\n**I _really_ want to add support for MacOS, but I don't have the experience required to implement it.**\n\nContributing is super simple! Create an additional branch and make a pull request with your changes. If the changes past the automated tests, it will be manually reviewed and merged accordingly.\n\nAny and all help is appreciated, and if you have any questions, feel free to contact me directly.\n\n# 📓 Important notes 📓\n\n- Almost all the errors I've encountered in testing were when the code and the functions were in the same file. You\n  should make a separate file for the code or surround it with `if __name__ == '__main__':`.\n- On windows, there's currently a 16 entry limit on the context menu.\n\n# 💻 Freshen - A context_menu project! 💻\n\nFeel free to check out a [file sorter](https://github.com/saleguas/freshen) program I made that directly implements this library.\n\n[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=saleguas\u0026repo=freshen)](https://github.com/saleguas/freshen)\n\n# 💙 Support 💙\n\nAll my work is and always will be free and open source. If you'd like to support me, **please consider leaving a ⭐ star ⭐**, as it motivates me and the community to keep working on this project.\n\nThanks for reading!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaleguas%2Fcontext_menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaleguas%2Fcontext_menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaleguas%2Fcontext_menu/lists"}