18 |
|
|
19 |
class ShellExtension: |
class ShellExtension: |
20 |
_reg_progid_ = "Python.ShellExtension.ContextMenu" |
_reg_progid_ = "Python.ShellExtension.ContextMenu" |
21 |
_reg_desc_ = "Python Sample Shell Extension (context menu)" |
_reg_name_ = "MessClient" |
22 |
|
_reg_desc_ = "Mess Shell Extension" |
23 |
_reg_clsid_ = "{CED0336C-C9EE-4a7f-8D7F-C660393C381F}" |
_reg_clsid_ = "{CED0336C-C9EE-4a7f-8D7F-C660393C381F}" |
24 |
_com_interfaces_ = [shell.IID_IShellExtInit, shell.IID_IContextMenu] |
_com_interfaces_ = [shell.IID_IShellExtInit, shell.IID_IContextMenu] |
25 |
_public_methods_ = IContextMenu_Methods + IShellExtInit_Methods |
_public_methods_ = IContextMenu_Methods + IShellExtInit_Methods |
78 |
def GetCommandString(self, cmd, typ): |
def GetCommandString(self, cmd, typ): |
79 |
return "Hello from Python!!" |
return "Hello from Python!!" |
80 |
|
|
81 |
|
|
82 |
def DllRegisterServer(): |
def DllRegisterServer(): |
83 |
import _winreg |
import _winreg |
84 |
key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, |
|
85 |
"Python.File\\shellex") |
|
86 |
subkey = _winreg.CreateKey(key, "ContextMenuHandlers") |
|
87 |
subkey2 = _winreg.CreateKey(subkey, "PythonSample") |
# extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html) |
88 |
_winreg.SetValueEx(subkey2, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_) |
|
89 |
|
# for folders |
90 |
|
folder_key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Folder\\shellex") |
91 |
|
folder_subkey = _winreg.CreateKey(folder_key, "ContextMenuHandlers") |
92 |
|
folder_subkey2 = _winreg.CreateKey(folder_subkey, ShellExtension._reg_name_) |
93 |
|
_winreg.SetValueEx(folder_subkey2, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_) |
94 |
|
|
95 |
|
# for files |
96 |
|
file_key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "*\\shellex") |
97 |
|
file_subkey = _winreg.CreateKey(file_key, "ContextMenuHandlers") |
98 |
|
file_subkey2 = _winreg.CreateKey(file_subkey, ShellExtension._reg_name_) |
99 |
|
_winreg.SetValueEx(file_subkey2, None, 0, _winreg.REG_SZ, ShellExtension._reg_clsid_) |
100 |
|
|
101 |
print ShellExtension._reg_desc_, "registration complete." |
print ShellExtension._reg_desc_, "registration complete." |
102 |
|
|
103 |
|
|
104 |
def DllUnregisterServer(): |
def DllUnregisterServer(): |
105 |
import _winreg |
import _winreg |
106 |
|
|
107 |
|
# extended (via http://mail.python.org/pipermail/python-list/2003-December/198390.html) |
108 |
|
|
109 |
try: |
try: |
110 |
key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT, |
# for folders |
111 |
"Python.File\\shellex\\ContextMenuHandlers\\PythonSample") |
folder_key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT, |
112 |
|
"Folder\\shellex\\ContextMenuHandlers\\" + ShellExtension._reg_name_) |
113 |
|
# for files |
114 |
|
file_key = _winreg.DeleteKey(_winreg.HKEY_CLASSES_ROOT, |
115 |
|
"*\\shellex\\ContextMenuHandlers\\" + ShellExtension._reg_name_) |
116 |
except WindowsError, details: |
except WindowsError, details: |
117 |
import errno |
import errno |
118 |
if details.errno != errno.ENOENT: |
if details.errno != errno.ENOENT: |