Python 的图标重叠问题
我在这个论坛上找到了一些关于如何使用 Python 2.7 和 2.7 实现图标覆盖处理程序的示例和主题。 win32com 包,但它对我不起作用,我不明白为什么。
我创建了DLL,注册时没有错误。我也尝试过直接使用脚本,但结果是一样的。就像这个班级从未被调用过一样。
这是代码:
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)
您好,感谢您的回答。 我已经使用日志文件和 win32traceutil 进行了测试。记录注册/取消注册消息。注册表项也在以下位置创建:
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 方法中添加了一些日志,但当我浏览浏览器时看不到任何痕迹。
我的配置是: Python 2.7 pywin32-214.win32-py2.7.exe Windows XP SP 2
您可以在此处下载所有代码:
I found some examples and topics on this forum about the way to implement an icon overlay handler with Python 2.7 & the win32com package but it does not work for me and I don't understand why.
I create the DLL and I have no error when I register it. I have also tried directly with the script but it's the same. It's like the class is never called.
Here is the code:
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)
Hi and thanks for your answer.
I have tested with a log file and also win32traceutil. The registration/unregitration messages are logged. The registry entries are also created under:
1/HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\GD.TestServer
2/ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved
3/ directly under class root.
I have also added some logs inside the methods getOverlayInfo, GetPriority and isMemberOf but I can't see a trace when I browse through the explorer.
My configuration is:
Python 2.7
pywin32-214.win32-py2.7.exe
Windows XP SP 2
You can download all the code here:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题解决了。我猜有些东西初始化得很糟糕,但现在它可以工作了。
我的愿望是做类似 dropBox 的服务。
我需要能够根据给定文件的上传状态更新其图标。我将为每个状态(上传、上传、失败)创建一个类,该类将实现 IID_IShellIconOverlayIdentifier 接口。但是然后...
我是否应该在本地文件中写入当前正在上传/failed_to_upload 的文件列表,检查每个文件是否存在到 isMemberOf 方法中以确定要显示的好图标?这是最好的方法吗?或者例如将所有文件路径存储在注册表中的一个键内会更好吗?
感谢您的帮助。
problem solved. i guess something was badly initialized but now it works.
My wish is to make something like the dropBox service.
i need to be able to update the icon of a given file according to its upload status. I will create a class for each state (uploading, uploaded, failed) that will implements the IID_IShellIconOverlayIdentifier interface. But then...
should i write the list of files that are currently uploading/failed_to_upload in local files the check the presence of each file into the isMemberOf method to determine the good icon to display? Is it the best way to do that or it would be better for instance to store all the file path inside a key in the registry?
Thanks for your help.