| 1 |
# A sample context menu handler. |
# Derived from Python24\Lib\site-packages\win32comext\shell\demos\servers\context_menu.py |
| 2 |
# Adds a 'Hello from Python' menu entry to .py files. When clicked, a |
# >> a bit more complex << |
| 3 |
# simple message box is displayed. |
|
| 4 |
# |
# Acknowledgements to Mark Hammond for his "Python for Windows extensions" |
| 5 |
# To demostrate: |
# http://python.net/crew/mhammond/ |
| 6 |
# * Execute this script to register the context menu. |
|
| 7 |
# * Open Windows Explorer, and browse to a directory with a .py file. |
# ... and Michael Dunn for his |
| 8 |
# * Right-Click on a .py file - locate and click on 'Hello from Python' on |
# "The Complete Idiot's Guide to Writing Shell Extensions"-series at "The Code Project" |
| 9 |
# the context menu. |
# http://www.codeproject.com/shell/shellextguideindex.asp |
| 10 |
|
|
| 11 |
|
# You're great guys! |
| 12 |
|
|
|
# see also: http://www.codeproject.com/shell/ShellExtGuide2.asp |
|
| 13 |
|
|
| 14 |
import pythoncom |
import pythoncom |
| 15 |
from win32com.shell import shell, shellcon |
from win32com.shell import shell, shellcon |
| 21 |
IShellExtInit_Methods = ["Initialize"] |
IShellExtInit_Methods = ["Initialize"] |
| 22 |
|
|
| 23 |
class ShellExtension: |
class ShellExtension: |
| 24 |
_reg_progid_ = "Python.ShellExtension.ContextMenu" |
_reg_progid_ = "Mess.ShellExtension.ContextMenu" |
| 25 |
_reg_name_ = "MessClient" |
_reg_name_ = "MessClient" |
| 26 |
_reg_desc_ = "Mess Shell Extension" |
_reg_desc_ = "Mess Shell Extension" |
| 27 |
_reg_clsid_ = "{CED0336C-C9EE-4a7f-8D7F-C660393C381F}" |
_reg_clsid_ = "{CED0336C-C9EE-4a7f-8D7F-C660393C381F}" |
| 157 |
|
|
| 158 |
# extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html) |
# extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html) |
| 159 |
|
|
| 160 |
# for folders |
# for directory background |
| 161 |
background_key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Directory\\Background\\shellex") |
background_key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Directory\\Background\\shellex") |
| 162 |
background_subkey = _winreg.CreateKey(background_key, "ContextMenuHandlers") |
background_subkey = _winreg.CreateKey(background_key, "ContextMenuHandlers") |
| 163 |
background_subkey2 = _winreg.CreateKey(background_subkey, ShellExtension._reg_name_) |
background_subkey2 = _winreg.CreateKey(background_subkey, ShellExtension._reg_name_) |
| 184 |
# extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html) |
# extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html) |
| 185 |
|
|
| 186 |
try: |
try: |
| 187 |
|
# for directory background |
| 188 |
|
background_key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT, |
| 189 |
|
"Directory\\Background\\shellex\\ContextMenuHandlers\\" + ShellExtension._reg_name_) |
| 190 |
# for folders |
# for folders |
| 191 |
folder_key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT, |
folder_key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT, |
| 192 |
"Folder\\shellex\\ContextMenuHandlers\\" + ShellExtension._reg_name_) |
"Folder\\shellex\\ContextMenuHandlers\\" + ShellExtension._reg_name_) |