# đī¸[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)
![logo](media/logo.png)
đģ A Python library to create and deploy cross-platform native context menus. đģ
Documentation available at: https://context-menu.readthedocs.io/en/latest/
* * *
![example usage](media/thumbnail2.gif)
* * *
# Table of Contents
- [â Features â](#-features-)
* [đ What is the context menu? đ](#-what-is-the-context-menu-)
* [đĨī¸ What Operating Systems are supported? đĨī¸](#%EF%B8%8F-what-operating-systems-are-supported-%EF%B8%8F)
* [đ What Python versions are supported? đ](#-what-python-versions-are-supported-)
- [đŊ Installation đŊ](#-installation-)
- [đšī¸ Quickstart đšī¸](#%EF%B8%8F-quickstart-%EF%B8%8F)
- [đ¤ Advanced Usage đ¤](#-advanced-usage-)
* [The `ContextMenu` Class](#the-contextmenu-class)
* [The `ContextCommand` Class](#the-contextcommand-class)
* [The `FastCommand` Class](#the-fastcommand-class)
* [The `removeMenu` method](#the-removemenu-method)
* [The `params` Command Parameter](#the-params-command-parameter)
* [`command_vars` Command Parameter](#command_vars-command-parameter)
* [Opening on Files](#opening-on-files)
* [Activation Types](#activation-types)
- [đ Goals đ](#-goals-)
- [đ Contribution đ](#-contribution-)
- [đ Important notes đ](#-important-notes-)
- [đģ Freshen - A context_menu project! đģ](#-freshen---a-context_menu-project-)
- [đ Support đ](#-support-)
# â Features â
This 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!
context_menu was created as due to the lack of an intuitive and easy to use cross-platform context menu library. The
library allows you to create your own context menu entries and control their behavior seamlessly in native Python. The
library has the following features:
* Written in pure python with no other dependencies
* Extremely intuitive design inspired by Keras Tensorflow
* Swift installation from Python's Package Manager (pip)
* Painless context menu creation
* Cascading context menu support
* The ability to natively integrate python functions from a context entry call
* Detailed documentation
## đ What is the context menu? đ
The context menu is the window that is displayed when you right click:
![img.png](media/context_menu.png)
The context menu is different depending on what was right clicked. For example, right clicking a folder will give you
different options than right clicking a file.
## đĨī¸ What Operating Systems are supported? đĨī¸
Currently, the only operating systems supported are:
- Windows 7
- Windows 10
- Windows 11
- Linux (Using Nautilus)
## đ What Python versions are supported? đ
**All python versions 3.7 and above** are supported.
# đŊ Installation đŊ
If you haven't installed Python, download and run an installer from the official
website: https://www.python.org/downloads/
Once you have Python, the rest is super simple. Simply just run the following command in a terminal to install the
package:
```commandline
python -m pip install context_menu
```
or if you're on Linux:
```commandline
python3 -m pip install context_menu
```
_Note: If you're on Windows and it says the command isn't recognized, make sure to
add [Python to your path](https://datatofish.com/add-python-to-windows-path/) and run the command prompt as
administrator_
# đšī¸ Quickstart đšī¸
Let's say you want to make a basic context menu entry when you right click a file.
1. If you haven't already Install the library via pip:
```commandline
python -m pip install context_menu
```
2. Create and compile the menu:
It's super easy!
You can create entries in as little as 3 lines:
```python
from context_menu import menus
fc = menus.FastCommand('Example Fast Command 1', type='FILES', command='echo Hello')
fc.compile()
```
![example fast command](media/example_fast_command.png)
All you have to do is import the library and define the type of context entry you want. The options are:
* A context menu (an entry that has more entries)
* A fast command (a single context menu entry to kick a running script)
* A context command which can be added to menus for more complex commands
You can also create much more complicated nested menus:
```Python
def foo2(filenames, params):
print('foo2')
print(filenames)
input()
def foo3(filenames, params):
print('foo3')
print(filenames)
input()
if __name__ == '__main__':
from context_menu import menus
cm = menus.ContextMenu('Foo menu', type='FILES')
cm2 = menus.ContextMenu('Foo Menu 2')
cm3 = menus.ContextMenu('Foo Menu 3')
cm3.add_items([
menus.ContextCommand('Foo One', command='echo hello > example.txt'),
])
cm2.add_items([
menus.ContextCommand('Foo Two', python=foo2),
cm3,
])
cm.add_items([
cm2,
menus.ContextCommand('Foo Three', python=foo3)
])
cm.compile()
```
![second Example](media/second_example.png)
All context menus are **permanent** unless you remove them.
# đ¤ Advanced Usage đ¤
## The `ContextMenu` Class
The [ContextMenu](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu) object
holds 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
compile the root menu.
```Python
ContextMenu(name: str, type: str = None, icon_path: str = None)
```
Menus can be added to menus, creating cascading context menus. You can use
the [{MENU}.add_items{ITEMS}](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu.add_items)
function to add context elements together, for example:
```Python
cm = menus.ContextMenu('Foo menu', type='DIRECTORY_BACKGROUND')
cm.add_items([
menus.ContextMenu(...),
menus.ContextCommand(...),
menus.ContextCommand(...)
])
cm.compile()
```
You have to
call [{MENU}.compile()](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu.compile)
in order to create the menu.
## The `ContextCommand` Class
The [ContextCommand](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextCommand)
class creates the selectable part of the menu (you can click it). It requires a name, and either a Python function or a
command **(but NOT both)** and has various other options
```Python
ContextCommand(name: str, command: str = None, python: 'function' = None, params: str = None, command_vars: list = None, icon_path: str = None)
```
Python functions can be passed to this method, regardless of their location. **However, the function must accept only
two parameters `filenames`, which is a list of paths\*, and `params`, the parameters passed to the function**. and if
the function is in the same file as the menu, you have to surround it with `if __name__ == '__main__':`
```python
# An example of a valid function
def valid_function(filenames, params):
print('Im valid!')
print(filenames)
print(params)
# Examples of invalid functions
def invalid_function_1(filenames, param1, param2):
print('Im invalid!')
print(filenames)
def invalid_function_2(params):
print('Im invalid!')
print(params)
```
Any command passed (as a string) will be directly ran from the shell.
## The `FastCommand` Class
The [FastCommand](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.FastCommand) class
is an extension of the ContextMenu class and allows you to quickly create a single entry menu. It expects a name, type,
command/function and an optional icon path.
```python
FastCommand(
name: str, type: str, command: str = None, python: 'function' = None, params: str = '', command_vars: list = None, icon_path: str = None)
```
```python
def foo1(filenames, params):
print(filenames)
input()
if __name__ == '__main__':
from context_menu import menus
fc = menus.FastCommand('Example Fast Command 1', type='FILES', python=foo1)
fc.compile()
```
## The `removeMenu` method
You can remove a context menu entry easily as well. Simply call the ['menus.removeMenu()'](<>) method.
```python
removeMenu(name: str, type: str)
```
For example, if I wanted to remove the menu 'Foo Menu' that activated on type 'FILES':
```python
from context_menu import menus
menus.removeMenu('Foo Menu', 'FILES')
```
and boom! It's gone đ
## The `params` Command Parameter
In both the `ContextCommand` class and `FastCommand` class you can pass in a parameter, defined by the `parameter=None`
variable. **This value MUST be a string!** This means instead of passing a list or numbers, pass it as a string
separated by spaces or whatever to delimitate it.
```Python
fc = menus.FastCommand('Example Fast Command 1', type='FILES', python=foo1, params='a b c d e')
fc.compile()
```
For more information, [see this.](https://github.com/saleguas/context_menu/issues/4)
Works on the `FastCommand` and `ContextCommand` class.
## `command_vars` Command Parameter
If you decide to pass a shell command, you can access a list of special variables. For example, if I wanted to run a
custom command with the file selected, I could use the following:
```Python
fc = menus.FastCommand('Weird Copy', type='FILES', command='touch ?x', command_vars=['FILENAME'])
fc.compile()
```
which would create a new file with the name of whatever I selected with an 'x' on the end. The `?` variable is
interpreted from left to right and replaced with the selected
values [(see this)](https://github.com/saleguas/context_menu/issues/3).
All of the preset values are as follows:
| Name | Function |
| ------------- | --------------------------------------- |
| FILENAME | The path to the file selected |
| DIR/DIRECTORY | The directory the script was ran in. |
| PYTHONLOC | The location of the python interpreter. |
Works on the `FastCommand` and `ContextCommand` class.
## Opening on Files
Let'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
this by adding a `type` variable to the `ContextCommand` or `FastCommand` class.
```Python
fc = menus.FastCommand('Weird Copy', type='.txt', command='touch ?x',
command_vars=['FILENAME']) # opens only on .txt files
fc.compile()
```
Now you'll only see the "Weird Copy" menu entry when you right click a .txt file.
## Activation Types
There are different locations where a context menu can fire. For example, if you right click on a folder you'll get
different options than if you right click on a file. The `type` variable controls this behavior in the library, and you
can reference this table to determine the `type`:
| Name | Location | Action |
| -------------------- | ------------------------------------------------------------------ | ---------------------------------------- |
| FILES | HKEY_CURRENT_USER\\Software\\Classes\\\*\\shell\\ | Opens on a file |
| DIRECTORY | HKEY_CURRENT_USER\\Software\\Classes\\Directory\\shell | Opens on a directory |
| DIRECTORY_BACKGROUND | HKEY_CURRENT_USER\\Software\\Classes\\Directory\\Background\\shell | Opens on the background of the Directory |
| DRIVE | HKEY_CURRENT_USER\\Software\\Classes\\Drive\\shell | Opens on the drives(think USBs) |
| DESKTOP | Software\\Classes\\DesktopBackground\\shell | Opens on the background of the desktop |
* * *
I strongly recommend checking out the [examples folder](examples) for more complicated examples and usage.
You can check out the official documentation [here](https://context-menu.readthedocs.io/en/latest/index.html).
* * *
# đ Goals đ
This project tackles some pretty big issues, and there's definetly some goals that I'd like to accomplish. The current roadmap is as follows:
* Support for other Linux distributions
* Better approach to the Linux GNOME integration
* Mac support
* Bypass 16 entry limit on windows
If by all means you want to help reach these milestones, see contribution below.
# đ Contribution đ
**I _really_ want to add support for MacOS, but I don't have the experience required to implement it.**
Contributing 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.
Any and all help is appreciated, and if you have any questions, feel free to contact me directly.
# đ Important notes đ
- Almost all the errors I've encountered in testing were when the code and the functions were in the same file. You
should make a separate file for the code or surround it with `if __name__ == '__main__':`.
- On windows, there's currently a 16 entry limit on the context menu.
# đģ Freshen - A context_menu project! đģ
Feel free to check out a [file sorter](https://github.com/saleguas/freshen) program I made that directly implements this library.
[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=saleguas&repo=freshen)](https://github.com/saleguas/freshen)
# đ Support đ
All 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.
Thanks for reading!
Raw data
{
"_id": null,
"home_page": "https://github.com/saleguas/context_menu",
"name": "context-menu",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Salvador Aleguas",
"author_email": "salvador@aleguas.dev",
"download_url": "https://files.pythonhosted.org/packages/ad/be/276959c4ece0e906ecee0387745dbae7989e09b27c41051046751c4b7775/context_menu-1.4.1.tar.gz",
"platform": null,
"description": "# \ud83d\uddc2\ufe0f[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)\r\n\r\n![logo](media/logo.png)\r\n\r\n\ud83d\udcbb A Python library to create and deploy cross-platform native context menus. \ud83d\udcbb\r\n\r\n\r\nDocumentation available at: https://context-menu.readthedocs.io/en/latest/\r\n\r\n* * *\r\n\r\n![example usage](media/thumbnail2.gif)\r\n\r\n* * *\r\n\r\n# Table of Contents\r\n- [\u2699 Features \u2699](#-features-)\r\n * [\ud83d\ude4b What is the context menu? \ud83d\ude4b](#-what-is-the-context-menu-)\r\n * [\ud83d\udda5\ufe0f What Operating Systems are supported? \ud83d\udda5\ufe0f](#%EF%B8%8F-what-operating-systems-are-supported-%EF%B8%8F)\r\n * [\ud83d\udc0d What Python versions are supported? \ud83d\udc0d](#-what-python-versions-are-supported-)\r\n- [\ud83d\udcbd Installation \ud83d\udcbd](#-installation-)\r\n- [\ud83d\udd79\ufe0f Quickstart \ud83d\udd79\ufe0f](#%EF%B8%8F-quickstart-%EF%B8%8F)\r\n- [\ud83e\udd16 Advanced Usage \ud83e\udd16](#-advanced-usage-)\r\n * [The `ContextMenu` Class](#the-contextmenu-class)\r\n * [The `ContextCommand` Class](#the-contextcommand-class)\r\n * [The `FastCommand` Class](#the-fastcommand-class)\r\n * [The `removeMenu` method](#the-removemenu-method)\r\n * [The `params` Command Parameter](#the-params-command-parameter)\r\n * [`command_vars` Command Parameter](#command_vars-command-parameter)\r\n * [Opening on Files](#opening-on-files)\r\n * [Activation Types](#activation-types)\r\n- [\ud83c\udfc1 Goals \ud83c\udfc1](#-goals-)\r\n- [\ud83d\ude4c Contribution \ud83d\ude4c](#-contribution-)\r\n- [\ud83d\udcd3 Important notes \ud83d\udcd3](#-important-notes-)\r\n- [\ud83d\udcbb Freshen - A context_menu project! \ud83d\udcbb](#-freshen---a-context_menu-project-)\r\n- [\ud83d\udc99 Support \ud83d\udc99](#-support-)\r\n\r\n# \u2699 Features \u2699\r\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!\r\n\r\ncontext_menu was created as due to the lack of an intuitive and easy to use cross-platform context menu library. The\r\nlibrary allows you to create your own context menu entries and control their behavior seamlessly in native Python. The\r\nlibrary has the following features:\r\n\r\n* Written in pure python with no other dependencies\r\n* Extremely intuitive design inspired by Keras Tensorflow\r\n* Swift installation from Python's Package Manager (pip)\r\n* Painless context menu creation\r\n* Cascading context menu support\r\n* The ability to natively integrate python functions from a context entry call\r\n* Detailed documentation\r\n\r\n## \ud83d\ude4b What is the context menu? \ud83d\ude4b\r\n\r\nThe context menu is the window that is displayed when you right click:\r\n\r\n![img.png](media/context_menu.png)\r\n\r\nThe context menu is different depending on what was right clicked. For example, right clicking a folder will give you\r\ndifferent options than right clicking a file.\r\n\r\n## \ud83d\udda5\ufe0f What Operating Systems are supported? \ud83d\udda5\ufe0f \r\n\r\nCurrently, the only operating systems supported are:\r\n\r\n- Windows 7\r\n- Windows 10\r\n- Windows 11\r\n- Linux (Using Nautilus)\r\n\r\n## \ud83d\udc0d What Python versions are supported? \ud83d\udc0d\r\n\r\n**All python versions 3.7 and above** are supported.\r\n\r\n# \ud83d\udcbd Installation \ud83d\udcbd\r\n\r\nIf you haven't installed Python, download and run an installer from the official\r\nwebsite: https://www.python.org/downloads/\r\n\r\nOnce you have Python, the rest is super simple. Simply just run the following command in a terminal to install the\r\npackage:\r\n\r\n```commandline\r\npython -m pip install context_menu\r\n```\r\n\r\nor if you're on Linux:\r\n\r\n```commandline\r\npython3 -m pip install context_menu\r\n```\r\n\r\n_Note: If you're on Windows and it says the command isn't recognized, make sure to\r\nadd [Python to your path](https://datatofish.com/add-python-to-windows-path/) and run the command prompt as\r\nadministrator_\r\n\r\n# \ud83d\udd79\ufe0f Quickstart \ud83d\udd79\ufe0f\r\n\r\nLet's say you want to make a basic context menu entry when you right click a file.\r\n\r\n1. If you haven't already Install the library via pip:\r\n\r\n```commandline\r\npython -m pip install context_menu\r\n```\r\n\r\n2. Create and compile the menu:\r\n\r\nIt's super easy!\r\nYou can create entries in as little as 3 lines:\r\n\r\n```python\r\nfrom context_menu import menus\r\n\r\nfc = menus.FastCommand('Example Fast Command 1', type='FILES', command='echo Hello')\r\nfc.compile()\r\n```\r\n\r\n![example fast command](media/example_fast_command.png)\r\n\r\nAll you have to do is import the library and define the type of context entry you want. The options are:\r\n\r\n* A context menu (an entry that has more entries)\r\n* A fast command (a single context menu entry to kick a running script)\r\n* A context command which can be added to menus for more complex commands\r\n\r\nYou can also create much more complicated nested menus:\r\n\r\n```Python\r\ndef foo2(filenames, params):\r\n print('foo2')\r\n print(filenames)\r\n input()\r\n\r\n\r\ndef foo3(filenames, params):\r\n print('foo3')\r\n print(filenames)\r\n input()\r\n\r\n\r\nif __name__ == '__main__':\r\n from context_menu import menus\r\n\r\n cm = menus.ContextMenu('Foo menu', type='FILES')\r\n cm2 = menus.ContextMenu('Foo Menu 2')\r\n cm3 = menus.ContextMenu('Foo Menu 3')\r\n\r\n cm3.add_items([\r\n menus.ContextCommand('Foo One', command='echo hello > example.txt'),\r\n ])\r\n cm2.add_items([\r\n menus.ContextCommand('Foo Two', python=foo2),\r\n cm3,\r\n ])\r\n cm.add_items([\r\n cm2,\r\n menus.ContextCommand('Foo Three', python=foo3)\r\n ])\r\n\r\n cm.compile()\r\n```\r\n\r\n![second Example](media/second_example.png)\r\n\r\nAll context menus are **permanent** unless you remove them.\r\n\r\n# \ud83e\udd16 Advanced Usage \ud83e\udd16\r\n\r\n## The `ContextMenu` Class\r\n\r\nThe [ContextMenu](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu) object\r\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\r\ncompile the root menu.\r\n\r\n```Python\r\nContextMenu(name: str, type: str = None, icon_path: str = None)\r\n```\r\n\r\nMenus can be added to menus, creating cascading context menus. You can use\r\nthe [{MENU}.add_items{ITEMS}](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu.add_items)\r\nfunction to add context elements together, for example:\r\n\r\n```Python\r\ncm = menus.ContextMenu('Foo menu', type='DIRECTORY_BACKGROUND')\r\ncm.add_items([\r\n menus.ContextMenu(...),\r\n menus.ContextCommand(...),\r\n menus.ContextCommand(...)\r\n])\r\ncm.compile()\r\n```\r\n\r\nYou have to\r\ncall [{MENU}.compile()](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextMenu.compile)\r\nin order to create the menu.\r\n\r\n## The `ContextCommand` Class\r\n\r\nThe [ContextCommand](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.ContextCommand)\r\nclass creates the selectable part of the menu (you can click it). It requires a name, and either a Python function or a\r\ncommand **(but NOT both)** and has various other options\r\n\r\n```Python\r\nContextCommand(name: str, command: str = None, python: 'function' = None, params: str = None, command_vars: list = None, icon_path: str = None)\r\n```\r\n\r\nPython functions can be passed to this method, regardless of their location. **However, the function must accept only\r\ntwo parameters `filenames`, which is a list of paths\\*, and `params`, the parameters passed to the function**. and if\r\nthe function is in the same file as the menu, you have to surround it with `if __name__ == '__main__':`\r\n\r\n```python\r\n# An example of a valid function\r\ndef valid_function(filenames, params):\r\n print('Im valid!')\r\n print(filenames)\r\n print(params)\r\n\r\n\r\n# Examples of invalid functions\r\ndef invalid_function_1(filenames, param1, param2):\r\n print('Im invalid!')\r\n print(filenames)\r\n\r\n\r\ndef invalid_function_2(params):\r\n print('Im invalid!')\r\n print(params)\r\n```\r\n\r\nAny command passed (as a string) will be directly ran from the shell.\r\n\r\n## The `FastCommand` Class\r\n\r\nThe [FastCommand](https://context-menu.readthedocs.io/en/latest/context_menu.html#context_menu.menus.FastCommand) class\r\nis an extension of the ContextMenu class and allows you to quickly create a single entry menu. It expects a name, type,\r\ncommand/function and an optional icon path.\r\n\r\n```python\r\nFastCommand(\r\n name: str, type: str, command: str = None, python: 'function' = None, params: str = '', command_vars: list = None, icon_path: str = None)\r\n```\r\n\r\n```python\r\ndef foo1(filenames, params):\r\n print(filenames)\r\n input()\r\n\r\n\r\nif __name__ == '__main__':\r\n from context_menu import menus\r\n\r\n fc = menus.FastCommand('Example Fast Command 1', type='FILES', python=foo1)\r\n fc.compile()\r\n```\r\n\r\n## The `removeMenu` method\r\n\r\nYou can remove a context menu entry easily as well. Simply call the ['menus.removeMenu()'](<>) method.\r\n\r\n```python\r\nremoveMenu(name: str, type: str)\r\n```\r\n\r\nFor example, if I wanted to remove the menu 'Foo Menu' that activated on type 'FILES':\r\n\r\n```python\r\nfrom context_menu import menus\r\n\r\nmenus.removeMenu('Foo Menu', 'FILES')\r\n```\r\n\r\nand boom! It's gone \ud83d\ude0e\r\n\r\n## The `params` Command Parameter\r\n\r\nIn both the `ContextCommand` class and `FastCommand` class you can pass in a parameter, defined by the `parameter=None`\r\nvariable. **This value MUST be a string!** This means instead of passing a list or numbers, pass it as a string\r\nseparated by spaces or whatever to delimitate it.\r\n\r\n```Python\r\nfc = menus.FastCommand('Example Fast Command 1', type='FILES', python=foo1, params='a b c d e')\r\nfc.compile()\r\n```\r\n\r\nFor more information, [see this.](https://github.com/saleguas/context_menu/issues/4)\r\n\r\nWorks on the `FastCommand` and `ContextCommand` class.\r\n\r\n## `command_vars` Command Parameter\r\n\r\nIf you decide to pass a shell command, you can access a list of special variables. For example, if I wanted to run a\r\ncustom command with the file selected, I could use the following:\r\n\r\n```Python\r\nfc = menus.FastCommand('Weird Copy', type='FILES', command='touch ?x', command_vars=['FILENAME'])\r\nfc.compile()\r\n```\r\n\r\nwhich would create a new file with the name of whatever I selected with an 'x' on the end. The `?` variable is\r\ninterpreted from left to right and replaced with the selected\r\nvalues [(see this)](https://github.com/saleguas/context_menu/issues/3).\r\n\r\nAll of the preset values are as follows:\r\n\r\n| Name | Function |\r\n| ------------- | --------------------------------------- |\r\n| FILENAME | The path to the file selected |\r\n| DIR/DIRECTORY | The directory the script was ran in. |\r\n| PYTHONLOC | The location of the python interpreter. |\r\n\r\nWorks on the `FastCommand` and `ContextCommand` class.\r\n\r\n## Opening on Files\r\n\r\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\r\nthis by adding a `type` variable to the `ContextCommand` or `FastCommand` class.\r\n\r\n```Python\r\nfc = menus.FastCommand('Weird Copy', type='.txt', command='touch ?x',\r\n command_vars=['FILENAME']) # opens only on .txt files\r\nfc.compile()\r\n```\r\n\r\nNow you'll only see the \"Weird Copy\" menu entry when you right click a .txt file.\r\n\r\n## Activation Types\r\n\r\nThere are different locations where a context menu can fire. For example, if you right click on a folder you'll get\r\ndifferent options than if you right click on a file. The `type` variable controls this behavior in the library, and you\r\ncan reference this table to determine the `type`:\r\n\r\n| Name | Location | Action |\r\n| -------------------- | ------------------------------------------------------------------ | ---------------------------------------- |\r\n| FILES | HKEY_CURRENT_USER\\\\Software\\\\Classes\\\\\\*\\\\shell\\\\ | Opens on a file |\r\n| DIRECTORY | HKEY_CURRENT_USER\\\\Software\\\\Classes\\\\Directory\\\\shell | Opens on a directory |\r\n| DIRECTORY_BACKGROUND | HKEY_CURRENT_USER\\\\Software\\\\Classes\\\\Directory\\\\Background\\\\shell | Opens on the background of the Directory |\r\n| DRIVE | HKEY_CURRENT_USER\\\\Software\\\\Classes\\\\Drive\\\\shell | Opens on the drives(think USBs) |\r\n| DESKTOP | Software\\\\Classes\\\\DesktopBackground\\\\shell | Opens on the background of the desktop |\r\n\r\n* * *\r\n\r\nI strongly recommend checking out the [examples folder](examples) for more complicated examples and usage.\r\n\r\nYou can check out the official documentation [here](https://context-menu.readthedocs.io/en/latest/index.html).\r\n\r\n\r\n* * *\r\n\r\n# \ud83c\udfc1 Goals \ud83c\udfc1\r\n\r\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:\r\n\r\n* Support for other Linux distributions\r\n* Better approach to the Linux GNOME integration\r\n* Mac support\r\n* Bypass 16 entry limit on windows\r\n\r\nIf by all means you want to help reach these milestones, see contribution below.\r\n\r\n# \ud83d\ude4c Contribution \ud83d\ude4c\r\n\r\n**I _really_ want to add support for MacOS, but I don't have the experience required to implement it.**\r\n\r\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.\r\n\r\nAny and all help is appreciated, and if you have any questions, feel free to contact me directly.\r\n\r\n# \ud83d\udcd3 Important notes \ud83d\udcd3\r\n\r\n- Almost all the errors I've encountered in testing were when the code and the functions were in the same file. You\r\n should make a separate file for the code or surround it with `if __name__ == '__main__':`.\r\n- On windows, there's currently a 16 entry limit on the context menu.\r\n\r\n# \ud83d\udcbb Freshen - A context_menu project! \ud83d\udcbb\r\n\r\nFeel free to check out a [file sorter](https://github.com/saleguas/freshen) program I made that directly implements this library.\r\n\r\n[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=saleguas&repo=freshen)](https://github.com/saleguas/freshen)\r\n\r\n# \ud83d\udc99 Support \ud83d\udc99\r\n\r\nAll my work is and always will be free and open source. If you'd like to support me, **please consider leaving a \u2b50 star \u2b50**, as it motivates me and the community to keep working on this project.\r\n\r\nThanks for reading!\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Library to create cross-platform native context menus.",
"version": "1.4.1",
"project_urls": {
"Homepage": "https://github.com/saleguas/context_menu"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7da4f928745222809d97b40282cc09b9408e06f42df379aebd10912cec80c3a0",
"md5": "7381008211fb0f294d2c64b0e0cc82d8",
"sha256": "478a1b104b105260ea3deb53c1473b277fe11af4ac6cbcfd9d64abfb6cc94daa"
},
"downloads": -1,
"filename": "context_menu-1.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7381008211fb0f294d2c64b0e0cc82d8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 17893,
"upload_time": "2024-04-12T19:36:30",
"upload_time_iso_8601": "2024-04-12T19:36:30.612682Z",
"url": "https://files.pythonhosted.org/packages/7d/a4/f928745222809d97b40282cc09b9408e06f42df379aebd10912cec80c3a0/context_menu-1.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "adbe276959c4ece0e906ecee0387745dbae7989e09b27c41051046751c4b7775",
"md5": "c53c5ac00043b4b534f1606f9e6ebd75",
"sha256": "47d49c46a9638ab46090787019cdba5e8285862f1487da702a70ffdd82280f6b"
},
"downloads": -1,
"filename": "context_menu-1.4.1.tar.gz",
"has_sig": false,
"md5_digest": "c53c5ac00043b4b534f1606f9e6ebd75",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 22479,
"upload_time": "2024-04-12T19:36:32",
"upload_time_iso_8601": "2024-04-12T19:36:32.045221Z",
"url": "https://files.pythonhosted.org/packages/ad/be/276959c4ece0e906ecee0387745dbae7989e09b27c41051046751c4b7775/context_menu-1.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-12 19:36:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "saleguas",
"github_project": "context_menu",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "context-menu"
}