[python-win32] Overlay Icon Question...

Andrea Gavana andrea.gavana at gmail.com
Tue Apr 15 18:25:16 CEST 2008


Hi Tim & All,

On Tue, Apr 15, 2008 at 3:20 PM, Tim Golden wrote:
>
> Andrea Gavana wrote:
> > Yes, thank you, it helps a lot... although I still have some doubts.
> > These are my modifications of the class Roger posted:
> >
> > class SIOI(object):
> >     _reg_clsid_='{02844251-42C2-44CA-B43D-424FCE4F4660}'
> >     _reg_progid_='K-SVR.IShellIconOverlayIdentifier'
> >     _reg_desc_='Python implementation of IShellIconOverlayIdentifier'
> >     _public_methods_ = ['GetOverlayInfo','GetPriority','IsMemberOf']
> >     _com_interfaces_=[shell.IID_IShellIconOverlayIdentifier,
> > pythoncom.IID_IDispatch]
> >     __name__ = "SIOI"
> >
> >     def __init__(self, fileNames):
> >         self.fileNames = fileNames
> >
> >     def AddFile(self, fileName):
> >         if fileName not in self.fileNames:
> >             self.fileNames.append(fileName)
> >
> >     def RemoveFile(self, fileName):
> >         if fileName in self.fileNames:
> >             self.fileNames.remove(fileName)
> >
> >     def GetOverlayInfo(self):
> >         return (r'icons/KSVROverlay.ico', 0, shellcon.ISIOI_ICONFILE)
> >
> >     def GetPriority(self):
> >         return 50
> >
> >     def IsMemberOf(self, fname, attributes):
> >         if fname in self.fileNames:
> >             return winerror.S_OK
> >         return winerror.E_FAIL
>
> Hmmm... Let's see how to explain this. Basically, this class
> isn't one you instantiate within your own program as you've
> done here. The instantiation is done by the underlying shell
> integration mechanism. Think of it as a Windows Service,
> running permanently. You don't start it with your app; it's
> either running or it's not, regardless of what apps are running.
>
> If you want it to adjust its overlays according to some changing
> data characteristics, you're going to have to establish some kind
> of mechanism by which the COM server which the class represents
> can request the latest list of filenames from some other piece of
> running code (or from a file or whatever).
>
> That more-or-less also explains the error you reported in your
> later email: the underlying mechanism expects an unadulterated
> __init__, not one which you've altered to pass in your filenames.
>
> Sorry if this isn't very clear; I did warn that this was not the easiest
> part of Windows programming to get into. What it means is that
> your app comes in two pieces:
>
> 1) This Namespace Extension which determines -- somehow -- when
> an icon requires an overlay and responds appropriately to requests
> from the shell. You register it on its own and leave it alone.
>
> 2) The main app, doing whatever it's doing, possibly cooperating with
> the Icon Overlay extension, for example by writing a list of filenames to
> a file from time to time.

Thank you a lot, now everything is perfectly clear. I made this class
communicate with the registry where I store a file name (in which I
have all my files for which I want the overlay icon), and it works
like a charm, with IsMemberOf checking this particular registry key
and returning the appropriate value if the file name is in my list of
files.
It works very well from the command line, but not at all once I
compile it py2exe... there is no traceback, no error in the setup.py,
no exception in the exe file, but the COM server is never started
(i.e., the IsMemberOf method of the SIOI class is never invoked or
called).

Is there anything special I should do in order to make this thing work
in an executable created by py2exe?

Thank you so much for your help, it's invaluable!

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/


More information about the python-win32 mailing list