2

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_)
Tiger-222
  • 6,677
  • 3
  • 47
  • 60
MaReX
  • 21
  • 3
  • Hello. I'm trying to make your solution work also but I've not succeeded yet. In fact the register key wasn't created. Should I create a DLL from the python file or just run the command `python`? Thanks. – Son Huy TRAN Sep 25 '15 at 08:25

2 Answers2

0

I can't see any issue with your code, but here are a few things to check:

  1. See if the original code from example works (download the icon used in example etc); if not, something is different in your version of windows.
  2. Increase priority to match example, it uses 50 and is not clear how the value affects feature.
  3. Verify that icon has correct format by opening both your icon and example's in icon editor.
Oliver
  • 27,510
  • 9
  • 72
  • 103
0

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.

MaReX
  • 21
  • 3