【问题标题】:Making win32com overlay icons example work使 win32com 覆盖图标示例工作
【发布时间】:2014-11-21 07:28:19
【问题描述】:

我正在尝试进行类似于 Dropbox 文件夹同步的操作,但在添加叠加图标时遇到了问题。我检查了以下指南:

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

之后,我对 Golden 的示例进行了两次轻微修改: 1. 在 IsMemberOf-method 中,我想在桌面上的一个文件夹中添加一个覆盖图标,其中包含一个文件“kala.txt”。 2. 在 GetOverlayInfo 方法中,我将路径更改为指向我下载的图标。

运行代码后,我检查了注册表,密钥在那里,但图标不会显示。 我在 32 位 windows xp 虚拟机上。

代码:

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_)

【问题讨论】:

  • 你好。我正在尝试使您的解决方案也有效,但我还没有成功。事实上,注册密钥并没有被创建。我应该从 python 文件创建一个 DLL 还是只运行命令python?谢谢。

标签: python pywin32 win32com shell-icons


【解决方案1】:

我看不出您的代码有任何问题,但这里有几件事需要检查:

  1. 查看示例中的原始代码是否有效(下载示例中使用的图标等);如果不是,则您的 Windows 版本有所不同。
  2. 增加匹配示例的优先级,它使用50,不清楚该值如何影响特征。
  3. 通过在图标编辑器中打开您的图标和示例来验证图标的格式是否正确。

【讨论】:

    【解决方案2】:

    我解决了这个问题:

    在注册处理程序之前,必须删除现有的同名处理程序。这可以通过运行 > regedit > 浏览到 Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\ > 删除相同的命名处理程序来完成。

    之后可以添加新的处理程序。

    要使处理程序工作,您必须终止进程 explorer.exe 并重新启动它。

    【讨论】:

      猜你喜欢
      • 2013-02-15
      • 1970-01-01
      • 2016-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 2020-08-06
      • 1970-01-01
      相关资源
      最近更新 更多