python怎么合并图标_Python图标重叠问题

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:

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值