Python的图标叠加问题

我在这个论坛上find了一些关于如何使用Python 2.7和win32com软件包来实现一个图标叠加处理程序的例子和主题,但是这对我不起作用,我不明白为什么。

我创build了DLL,并且在注册时没有错误。 我也直接尝试了脚本,但它是一样的。 这就像这个class从来没有打过电话一样。

这里是代码:

import win32traceutil from win32com.shell import shell, shellcon import pythoncom import winerror import os REG_PATH =r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers' REG_KEY = "GdIconOverlayTest" class GdClass: _reg_clsid_='{512AE200-F075-41E6-97DD-48ECA4311F2E}' _reg_progid_='GD.TestServer' _reg_desc_='gd desc' _public_methods_ = ['GetOverlayInfo','GetPriority','IsMemberOf'] _com_interfaces_=[shell.IID_IShellIconOverlayIdentifier, pythoncom.IID_IDispatch] def __init__(self): pass def GetOverlayInfo(self): return (os.path.abspath(r'C:\icons\test.ico'), 0, shellcon.ISIOI_ICONFILE) def GetPriority(self): return 0 def IsMemberOf(self, fname, attributes): print('ismemberOf', fname, os.path.basename(fname)) if os.path.basename(fname) == "hello.text": return winerror.S_OK return winerror.E_FAIL def DllRegisterServer(): print "Registering %s" % REG_KEY import _winreg key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, REG_PATH) subkey = _winreg.CreateKey(key, GdClass._reg_progid_) _winreg.SetValueEx(subkey, None, 0, _winreg.REG_SZ, GdClass._reg_clsid_) print "Registration complete: %s" % GdClass._reg_desc_ def DllUnregisterServer(): print "Unregistering %s" % REG_KEY import _winreg try: key = _winreg.DeleteKey(_winreg.HKEY_LOCAL_MACHINE, r"%s\%s" % (REG_PATH, GdClass._reg_progid_)) except WindowsError, details: import errno if details.errno != errno.ENOENT: raise print "Unregistration complete: %s" % GdClass._reg_desc_ if __name__=='__main__': from win32com.server import register register.UseCommandLine(GdClass, finalize_register = DllRegisterServer, finalize_unregister = DllUnregisterServer) 

嗨,谢谢你的回答。 我已经testing了一个日志文件,也win32traceutil。 注册/不注册消息被logging。 registry项也在下面创build:

1 / HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ ShellIconOverlayIdentifiers \ GD.TestServer 2 / HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Shell Extensions \ Approved 3 /直接在类的根下。

我还在方法getOverlayInfo,GetPriority和isMemberOf中添加了一些日志,但是当我浏览资源pipe理器时,我看不到跟踪信息。

我的configuration是:Python 2.7 pywin32-214.win32-py2.7.exe Windows XP SP 2

你可以在这里下载所有的代码:

问题解决了。 我想有些东西是初始化不好,但现在它起作用了。

我的愿望是使像dropBox服务。

我需要能够根据其上传状态更新给定文件的图标。 我将为每个状态创建一个类(上传,上传,失败),实现IID_IShellIconOverlayIdentifier接口。 但是之后…

我应该把当前正在上传/ failed_to_upload的文件列表写在本地文件中检查每个文件是否存在到isMemberOf方法中,以确定要显示的好图标? 是这样做的最好的方法,或者它是更好的例子来存储注册表中的一个键内的所有文件路径?

谢谢你的帮助。