I'm trying to make something similar as dropbox folder synchronization and I'm having problems with adding overlay icons. I checked the following guides:
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
After that I made just tw slight modifications to Golden's example: 1. in IsMemberOf-method I want to add an overlay icon to only one folder in my desktop containing a file 'kala.txt'. 2. in GetOverlayInfo-method I changed the path to point to an icon that I have in my downloads.
After running the code I checked the registry, and the key is there, but the icon won't show. I'm on a 32-bit windows xp virtual machine.
The code:
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_)
I solved the problem:
Before registering a handler, it is neccessary to remove existing same named handler. This can be done by run > regedit > browse to Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\ > remove the same named handler.
After this it's possible to add a new handler.
To make the handler work, you must kill process explorer.exe and restart it.