【问题标题】:Windows 7 - Right-click context cascade menu for Python [closed]Windows 7 - Python的右键单击上下文级联菜单[关闭]
【发布时间】:2013-08-02 02:37:57
【问题描述】:

我正在尝试为 *.zip 文件添加上下文菜单。使用必要参数启动我的 python 脚本。

我已添加注册以下密钥:

[HKEY_CLASSES_ROOT\WinZip\shell\SSSeracher] "MUIVerb"="SSSearcher Script" "SubCommands"="SSSearcher.Rule1;SSSearcher.Rule2;SSSearcher.Rule3;SSSearcher.Custom;SSSearcher.Config"
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule1] @="Rule #1"
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule1\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"1\""
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule2] @="Rule #2"
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule2\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"2\""
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule3] @="Rule #3"
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Rule3\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"3\""
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Custom] @="Custom rule"
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Custom\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"4\""
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Custom] @="Custom rule"
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Custom\command] @="C:\\APPS\\python\\Scripts\\sssearcher.py \"%1\" \"4\""
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Config] @="Config File"
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\SSSearcher.Config\command] @="vim C:\\APPS\\python\\Scripts\\sssearcher.pyc"

因为菜单显示点击那些绝对没有任何作用。

我一直在关注本教程: http://msdn.microsoft.com/en-us/library/windows/desktop/hh127467%28v=vs.85%29.aspx

我缺少一些东西,但不幸的是我找不到答案。你能帮我解决这个问题吗?

【问题讨论】:

    标签: python windows shell cascade


    【解决方案1】:

    我刚刚执行了这些步骤,它似乎可以工作:

    1) 首先找到HKEY_CLASSES_ROOT下的.zip键。

    2) 选择它并查看它的默认值。在我的情况下,默认值为CompressedFolder:

    3) 现在向下导航到 CompressedFolder\shell(或您默认的 .zip 文件),它也包含在 HKEY_CLASSES_ROOT 下:

    4) 右键单击​​ shell 并添加一个新密钥,在我的例子中,我添加了一个名为 MyCommand 的密钥。向此键添加一个名为 command 的子键。 MyCommand 将是出现在上下文菜单上的命令的名称。

    5) 接下来编辑command 子项mycommand 的(Deafult) 条目的值,添加您希望执行的操作。就我而言,我想打开一个 python 文件,告诉我有关文件的详细信息:

    这是python脚本:

    import os
    import sys
    
    def main():
        st = os.stat(sys.argv[1])
        print st
        raw_input()
    
    if __name__ == '__main__':
        main()
    

    它位于 C:\info.py

    这是我添加到默认值的条目:

    python C:\\info.py %1

    这就是它的全部内容,现在如果您要右键单击一个 zip 文件,您应该会看到您添加的命令:

    点击后给出:

    希望这就是你所追求的。如果您想添加更多命令,只需在 shell 键下添加更多子键,就像我们对 MyCommand 所做的那样。

    更新 - 级联菜单

    a) 为了添加级联菜单,请导航到上述步骤 3 中所述的键。在我的情况下,这是位于 HKEY_CLASSES_ROOT 下的CompressedFolder\shell。在这里添加一个带有您选择的名称的密钥,在我的例子中,我使用了CascadeMenu。向此键添加 2 个条目:

    • MUIVerb - 这是将出现在级联菜单中的名称。就我而言,我使用了MyCascadeMenu
    • SubCommands - 这是一个以分号分隔的命令列表。将命令命名为您喜欢的任何名称,在我的例子中,我使用了python.info。使用“|”如果需要分隔符,则在命令之间,例如 command1;|;command2

    b) 接下来我们需要告诉 windows 这个命令实际上做了什么。导航至:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\Shell

    在此处添加一个带有命令名称的键。在我的情况下,密钥称为python.info。将键的默认值设置为您希望出现在上下文菜单中的名称。就我而言,我使用了"File Info"

    c) 现在为您的命令添加一个子键,称为command。将此命令的默认条目更改为您希望执行的命令。就我而言,我已将其设置为 python C:\\info.py %1

    d) 我们现在完成了,右键单击 .zip 文件以查看您新创建的上下文菜单:

    【讨论】:

    • 是的,这很有效,我更早知道了。但问题是我真的需要它作为级联菜单。太糟糕了,我不能在这里截屏,因为不记得我的旧帐户了,不得不在这里登录 FB 帐户。 :(
    • 好的@KonradKnitter 我已经更新了答案,告诉你如何生成级联菜单。这就是你所追求的吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多