Icon overlay issue with Python

2024/11/13 8:42:26

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 win32traceutilfrom win32com.shell import shell, shellcon
import pythoncom
import winerror
import osREG_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):passdef GetOverlayInfo(self):return (os.path.abspath(r'C:\icons\test.ico'), 0, shellcon.ISIOI_ICONFILE)def GetPriority(self):return 0def IsMemberOf(self, fname, attributes):print('ismemberOf', fname, os.path.basename(fname))if os.path.basename(fname) == "hello.text":return winerror.S_OKreturn winerror.E_FAILdef DllRegisterServer():print "Registering %s" % REG_KEYimport _winregkey = _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_KEYimport _winregtry:key = _winreg.DeleteKey(_winreg.HKEY_LOCAL_MACHINE, r"%s\%s" % (REG_PATH, GdClass._reg_progid_))except WindowsError, details:import errnoif details.errno != errno.ENOENT:raiseprint "Unregistration complete: %s" % GdClass._reg_desc_if __name__=='__main__':from win32com.server import registerregister.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:

Answer

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.

https://en.xdnf.cn/q/72185.html

Related Q&A

Comparing NumPy object references

I want to understand the NumPy behavior.When I try to get the reference of an inner array of a NumPy array, and then compare it to the object itself, I get as returned value False.Here is the example:I…

Does using django querysets in templates hit the database?

Do template value tags force django to hit the database when called against a non-context value? For example:{{ request.user.username }} Is the call to show the currently logged in users username. H…

how to randomly sample in 2D matrix in numpy

I have a 2d array/matrix like this, how would I randomly pick the value from this 2D matrix, for example getting value like [-62, 29.23]. I looked at the numpy.choice but it is built for 1d array.The f…

How to update figure in same window dynamically without opening and redrawing in new tab?

I am creating a 3D scatter plot based off a pandas dataframe, and then I want to re-draw it with slightly updated data whenever the user presses a button in my program. I almost have this functionality…

Serializing a C struct in Python and sending over a socket

Im trying to serializing the following C structstruct packet {int id;unsigned char *ce;unsigned char *syms; };in Python and send it over a socket. The number of elements pointed by ce and syms are know…

creating multiple audio streams of an icecast2 server using python-shout

I am trying to create a web radio server to stream 3 sources at once. I am using python to create a source client for icecast2 using the python-shout library. I am not too familiar with the language (p…

Custom Deployment to Azure Websites

I recently started using Gulp.js to package all my CSS and JavaScript into single files, which I then include in my web app. My web app is written in Python (using Flask).I obviously dont want to track…

Python - Gspread Request Error 401

Im currently making a Discord-bot that connects to a Google-spreadsheet (gspread). But after Ive been running it for a while it starts to hand out errors and it cant connect to my gspread anymore (unle…

paramiko server mode port forwarding

I need to implement a ssh server using paramiko that only handles -R port forwarding requests like this:ssh -N -T -R 40005:destination_host:22 [email protected]So far from what i understand ill have to…

Pandas dataframe.hist() change title size on subplot?

I am manipulating DataFrame using pandas, Python. My data is 10000(rows) X 20(columns) and I am visualizing it, like this.df.hist(figsize=(150,150))However, if I make figsize bigger, each of subplots t…