2013-06-27 67 views
8

我跟着this教程,這就是我想出迄今:瘸子:Python腳本在菜單中沒有顯示

#!/usr/bin/python 
# -*- coding: utf-8 -*- 
#http://www.ibm.com/developerworks/library/os-autogimp/ 

from gimpfu import* 

def plugin_main(timg, tdrawable, maxh=540, maxw=800): 

    currentWidth = tdrawable.width 
    currentHeight = tdrawable.height 

    newWidth = currentWidth 
    newHeight = currentHeight 

    if (maxw < newWidth): 
     newWidth = maxw 
     newHeight = (float(currentHeight)/(float(currentWidth)/newWidth)) 

    if (maxh < newHeight): 
     newHeight = maxh 
     newWidth = (float(currentWidth)/(float(currentHeight)/newHeight)) 

    pdb.gimp_image_scale(timg, newWidth, newHeight) 

register(
     "python_fu_resize", 
     "Saves the image at a maximum width and height", 
     "Saves the image at a maximum width and height", 
     "N N", 
     "N N", 
     "2013", 
     "<Image>/Image/Resize to max...", 
     "*", 
     [], 
     [], 
     plugin_main) 

main() 

但插件woun't在GIMP菜單顯示出來(我使用GIMP 2.8)。給文件chmod a + x權限。文件位置可能是一個問題:/.gimp-2.8/plug-ins/src/resize.py? src是由於日食。

回答

10

如果你的腳本有任何語法錯誤,也不會在菜單中顯示在所有 - 上面的代碼確實有代碼的第一行語法錯誤from gimpfu import* (缺少*之前有一個空格)

檢查語法錯誤的一種簡單方法是嘗試將腳本作爲獨立運行(當它無法在GIMP之外找到「gimpfu」模塊時會失敗,但到那時,語法被解析 - 另一種方法是使用像pyflakes這樣的lint工具來檢查語法

腳本可能包含的其他運行時錯誤應該在運行時出現在彈出窗口中它來自GIMP--在那個階段,你只能更新你的腳本並從菜單重試它。但是,如果從腳本更改輸入或輸出參數,則必須重新啓動GIMP。

是的,在「文件位置」 一個問題 - 你必須把你的代碼在插件在GIMP的首選項中指定的目錄 - 默認情況下,這些都是~/.gimp-2.8/plug-ins//usr/lib[64]/gimp/2.0/plug-ins - 沒有「 src「 - 如果您的IDE不允許您指定放置文件的位置,則必須自己複製它們,或者在GIMP首選項中添加src目錄。

+0

做了一些修改:添加了缺失的空間並將腳本移到了'/ usr/lib/gimp/2.0/plug-ins'中。現在它出現在菜單中。謝謝。 – kyng

+4

調試的另一個提示:從命令行啓動gimp,您可以看到出現的錯誤消息類型。 – kyng

+5

確保腳本是可執行的。運行'$ chmod + x plugin.py'爲我解決了這個問題。 – arunkumar