Znalazłem kilka przykładów i tematów na tym forum o sposobie implementacji obsługi nakładki ikon z Pythonem 2.7 & pakiet win32com, ale to nie działa dla mnie i nie rozumiem dlaczego.Problem nakładki ikon z Pythonem
Tworzę bibliotekę DLL i nie mam błędu podczas jej rejestracji. Próbowałem również bezpośrednio ze skryptem, ale jest taki sam. To tak, jakby klasa nigdy nie była wywoływana.
Oto kod:
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)
Cześć i dzięki za odpowiedź. Testowałem z plikiem dziennika, a także win32traceutil. Komunikaty rejestracyjne/unregitracyjne są rejestrowane. Wpisy w rejestrze są tworzone na podstawie:
1/HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Explorer \ ShellIconOverlayIdentifiers \ GD.TestServer 2/HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Shell Extensions \ Approved 3/bezpośrednio w katalogu głównym.
Dodałem również kilka dzienników wewnątrz metod getOverlayInfo, GetPriority i isMemberOf, ale nie widzę śladu podczas przeglądania eksploratora.
Moja konfiguracja to: Python 2.7 pywin32-214.win32-py2.7.exe Windows XP SP 2
Można pobrać cały kod here:
Zapisywanie wpisów w pliku dziennika w celu sprawdzenia, które funkcje są rzeczywiście wywoływane (jeśli w ogóle). Szczególnie interesujące są tutaj połączenia z 'DllRegisterServer'. – AndiDog
Link do kodu jest uszkodzony! – mtasic85