【发布时间】:2014-11-21 07:28:19
【问题描述】:
我正在尝试进行类似于 Dropbox 文件夹同步的操作,但在添加叠加图标时遇到了问题。我检查了以下指南:
http://timgolden.me.uk/python/win32_how_do_i/add-my-own-icon-overlays.html http://msdn.microsoft.com/en-us/library/bb776858%28VS.85%29.aspx?topic=306117
之后,我对 Golden 的示例进行了两次轻微修改: 1. 在 IsMemberOf-method 中,我想在桌面上的一个文件夹中添加一个覆盖图标,其中包含一个文件“kala.txt”。 2. 在 GetOverlayInfo 方法中,我将路径更改为指向我下载的图标。
运行代码后,我检查了注册表,密钥在那里,但图标不会显示。 我在 32 位 windows xp 虚拟机上。
代码:
import os
from win32com.shell import shell, shellcon
import winerror
class IconOverlay:
_reg_clsid_ = '{642A09BF-DE34-4251-A0C2-588CCE0DB935}'
_reg_progid_ = 'TJG.PythonPackagesOverlayHandler'
_reg_desc_ = 'Icon Overlay Handler to indicate Python packages'
_public_methods_ = ['GetOverlayInfo', 'GetPriority', 'IsMemberOf']
_com_interfaces_ = [shell.IID_IShellIconOverlayIdentifier]
def GetOverlayInfo(self):
return (r'C:\Users\Administrator\Downloads\netvibes.ico', 0, shellcon.ISIOI_ICONFILE)
def GetPriority(self):
return 1
def IsMemberOf(self, fname, attributes):
if os.path.exists(os.path.join(fname, 'kala.txt')):
return winerror.S_OK
return winerror.E_FAIL
if __name__=='__main__':
import win32api
import win32con
import win32com.server.register
win32com.server.register.UseCommandLine (IconOverlay)
keyname = r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\PyPackageOverlay'
key = win32api.RegCreateKey (win32con.HKEY_LOCAL_MACHINE, keyname)
win32api.RegSetValue (key, None, win32con.REG_SZ, IconOverlay._reg_clsid_)
【问题讨论】:
-
你好。我正在尝试使您的解决方案也有效,但我还没有成功。事实上,注册密钥并没有被创建。我应该从 python 文件创建一个 DLL 还是只运行命令
python?谢谢。
标签: python pywin32 win32com shell-icons