我尝试制作与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方法中我想在我的桌面中只有一个文件夹添加一个叠加图标,其中包含一个文件' 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_)
答案 0 :(得分:0)
我无法看到您的代码存在任何问题,但有以下几点需要检查:
答案 1 :(得分:0)
我解决了这个问题:
在注册处理程序之前,必须删除现有的相同命名处理程序。这可以通过运行>完成。 regedit>浏览到Software \ Microsoft \ Windows \ CurrentVersion \ Explorer \ ShellIconOverlayIdentifiers \>删除相同的命名处理程序。
在此之后,可以添加新的处理程序。
要使处理程序正常工作,必须终止进程explorer.exe并重新启动它。