A simple and intuitive way to add your custom scripts to the windows right click contextmenu.
Project description
pywin_contextmenu
A simple and intuitive way to add your custom scripts to your windows right click contextmenu.
Usage
import pywin_contextmenu as pycm
# create a group
group1 = pycm.ContextMenuGroup("My python scripts")
# convert your script into executable command
script_cmd = pycm.python_script_cmd("scripts/clean_empty_folders.py", rel_path = True, hide_terminal = True)
# create the item
item1 = pycm.ContextMenuItem("Clean empty folders", script_cmd)
# add item to the group
group1.add_item(item1)
# get root_key
rk = pycm.get_root(pycm.UserType.CURR_USER, pycm.RootType.DIR_BG)
# Create the group and test
pycm.create_group(rk, group1)
API
The script depends on two main classes ContextMenuItem
and ContextMenuGroup
.
ContextMenuItem
This is the menu item which triggers and launches the command when clicked in the contextmenu. The signature of this class is
ContextMenuItem(
item_name, # name of the item to be shown
command, # command to be executed when selected
item_reg_key = "", # registry key associated with the item
# (if not given will be treated as item_name)
icon = "" # path to an icon to be shown with the item
)
ContextMenuGroup
This class groups multiple items and subgroups.
ContextMenuGroup(
group_name, # name of the group to be shown
group_reg_key = "", # registry key associated with the group
icon = "" # path to an icon to be shown with the group
)
For adding items or groups to a group instance call add_item method of the class.
ContextMenuGroup.add_item(item)
# or
ContextMenuGroup.add_item(subgroup)
Methods available
RootType
- anEnum
for chosing where the context menu item/group will be displayedUserType
- anEnum
for chosing whether to add the context menu for current user or for all usersget_root(user_type: UserType, root_type: RootType, file_type: str)
- creates/opens the registry key for the selected user_type and root_type. If theroot_type
isRootType.FILE
thenfile_type
argument is required and indicates the file extention.python_script_cmd(script_path, rel_path = False, hide_terminal = False)
- a utility function to convert a givenscript_path
to an executable command.create_item(root_key, item: ContextMenuItem)
- adds theitem
to the context menucreate_group(root_key, group: ContextMenuGroup)
- adds thegroup
to the context menudelete_item(root_key, item_reg_key)
- deletes theitem_reg_key
at the givenroot_key
registry. Warning: Please ensure you're not deleting the keys at the top level registry keys (e.g.HKEY_CLASSES_ROOT
,HKEY_CURRENT_USER
etc.)
© Naveen Namani
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
Built Distribution
Close
Hashes for pywin_contextmenu-2020.9.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51e6aa1e3d470af3fd803292841e7bb33c139cb53fdba4ac914283ccca566404 |
|
MD5 | 3ee4679c8be66d3fa8a105ccc3b6a9c9 |
|
BLAKE2b-256 | 5d421eb91df55d7ebc02d017eb9cef53b542a2b2226e482dd27e4624b30ea359 |
Close
Hashes for pywin_contextmenu-2020.9.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ddd92f278fea5afb05c351ed75a214810ee133883e326905851ec6fe8d6f3ee |
|
MD5 | ef250d703c46437894c6e53888ff51ab |
|
BLAKE2b-256 | 59f1b8c385c17422486bb77e9578de669d4a7df91bea1c3f64b2f325fabde325 |