【问题标题】:Why Does My GIMP Python Plug-In Not Work on My Ubuntu Linux Box?为什么我的 GIMP Python 插件无法在我的 Ubuntu Linux Box 上运行?
【发布时间】:2015-09-15 21:27:00
【问题描述】:

我正在尝试为 GNU Image Manipulation Plug-In 编写我自己的 Python 插件。我在这个 URL 上关注本教程:http://gimpbook.com/scripting/slides/index.html。我更改了一些变量名称并将脚本命名为不同的名称,但基本上它是相同的脚本。

从交互式 GIMP Python shell 调用该脚本时该脚本有效。我用鼠标访问:“Filters -> Python-Fu -> Console”。 hello_world() 函数在这里起作用。

但是,当我将插件放在.gimp2.8/plugins/ 文件夹或/usr/lib/gimp/2.0/plug-ins 中时,我在转到Help -> Plug-In Browser 后无法看到Plug-In Browser 中的插件。有谁知道我错过了什么?

问候,

我的 Python GIMP 插件源代码如下...

#! /usr/bin/env python 


from gimpfu import * 

def hello_world(initstr, font, size, color):
    img = gimp.Image(1, 1, RGB) 
    gimp.set_foreground(color)
    layer = pdb.gimp_text_fontname(img, None, 0, 0, initstr, 10, True, size, PIXELS, font) 
    img.resize(layer.width, layer.height, 0, 0)
    gimp.Display(img) 

register( 
  "pythonic_easier_gimp",
  "Hello Gimp Image", "Hello gimp image",
  "My Name", "My Name", "2015", 
  "Easier gimp...",
  "",
  [ 
     (PF_STRING, "string", "String", 'Hello, Gimp!'),
     (PF_FONT, "font", "Font face", "Sans")
     (PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
     (PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))

  ], 
  [], 
  easier_gimp, menu="<Image>/File/Create")


main()

【问题讨论】:

    标签: python linux gimp


    【解决方案1】:

    如果脚本没有显示在菜单上,则意味着上面的“注册”和“主”调用没有运行。一种可能性是您没有使用可执行权限标记您的 Python 文件。 (检查文件属性,或者在上面运行chmod 777 myfile.py

    另一种可能性是 Python 语法错误 - 给出列表时可能很难发现 - 要检查语法错误,请尝试从 shell 将脚本作为普通 Python 程序运行:$ python myfile.py - 这应该会产生一个 @ 987654323@。如果您看到 SyntaxError,请改正它。

    最后,安装好插件后,从终端启动它,而不是从菜单启动 - 如果 GIMP 找到了您的插件但偶然发现了错误,它应该在终端上显示 Wire read error输出:它也可能表示 Python 语法错误,或对 register 的错误调用(参数太少或太多)。由于此时您已排除语法错误,请仔细检查您的参数计数是否为register)

    到目前为止,当您修复了一些内容时,它应该会显示在菜单中。

    【讨论】:

    • 感谢@jsbueno 的有用回复。 :D 我能够以某种方式自己解决这个问题,这需要阅读 Internet 上的大量帖子并对其进行编码和测试。在下面查看我的解决方案。这实际上有效,但完全没有意义。 :D :/ :D
    • 并非毫无意义:如果您尝试从控制台使用 Python 运行它,正如我所指出的,您看到的错误消息将指向违规调用的语法错误。
    • 或者更确切地说,你会遇到“元组对象不可调用”错误,但它会指出查找错误的正确行。
    • 当您说“...从控制台使用 Python 运行它”时。你的意思是像gimp script.py 还是只是python script.py
    • 另外,我的意思是我编写的插件毫无意义,因为它只打印“willy wonka”。
    【解决方案2】:

    我找到了解决方案!我在线阅读了一些教程并切换到不同的开发环境,使用 PyDev 插件的 Eclipse。 PyDev 能够指出过于复杂的register() 函数中的语法错误。

    #! /usr/bin/env python 
    
    from gimpfu import *
    
    def wonka():
        img = gimp.Image(1, 1, RGB)
        gimp.set_foreground('purple')
        layer = pdb.gimp_text_fontname(img, None, 0, 0, 'Willy Wonka!', 10, True, 90, PIXELS, 'comic sans')
        img.resize(layer.width, layer.height, 0, 0)
        gimp.Display(img)
    
    
    
    register(
             "wonka",
             "Prints a message from Willy Wonka",
             "Prints a message from Willy Wonka",
             "User3870315",
             "User3870315",
             "2015",
    
             "<Toolbox>/Tools/Wonka",
             "",
             [],
             [],
             wonka)
    
    
    main()
    

    这显示在Filters -&gt; Python-Fu -&gt; Console -&gt; Browse 中。它还显示在Tools 下的工具栏中。

    这些链接有帮助:

    【讨论】:

      【解决方案3】:

      代码的 2 个问题对我来说很突出,函数/调用不匹配以及缺少分隔逗号

      (PF_FONT, "font", "Font face", "Sans") #<--missing comma
      
      def hello_world(initstr, font, size, color): #<--Defined function hello_world()
      easier_gimp, menu="<Image>/File/Create") #<--plugin calls easier_gimp()
      

      所以添加逗号并将hello_world 重命名为easier_gimp 允许插件工作。

      #! /usr/bin/env python
      
      
      from gimpfu import *
      
      def easier_gimp(initstr, font, size, color):
          img = gimp.Image(1, 1, RGB)
          gimp.set_foreground(color)
          layer = pdb.gimp_text_fontname(img, None, 0, 0, initstr, 10, True, size, PIXELS, font)
          img.resize(layer.width, layer.height, 0, 0)
          gimp.Display(img)
      
      register(
        "pythonic_easier_gimp",
        "Hello Gimp Image", "Hello gimp image",
        "My Name", "My Name", "2015",
        "Easier gimp...",
        "",
        [
           (PF_STRING, "string", "String", 'Hello, Gimp!'),
           (PF_FONT, "font", "Font face", "Sans"),
           (PF_SPINNER, "size", "Font size", 50, (1, 3000, 1)),
           (PF_COLOR, "color", "Text color", (1.0, 0.0, 0.0))
      
        ],
        [],
        easier_gimp, menu="<Image>/File/Create")
      
      
      main()
      

      最近在this github project创建了基于Python的Hello World GIMP插件示例

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-10
        • 1970-01-01
        • 2014-09-18
        • 2017-02-16
        • 1970-01-01
        • 2021-06-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多