2015-10-02 30 views
1

需要使用用戶可能尚未打開的圖像文件。儘管看起來我只限於在圖像已經打開的情況下啓用插件。 Gimp 2.8附帶的所有Python插件在圖像打開之前都會被禁用。通過很多示例進行搜索,似乎每個定位的示例都需要在插件可以執行之前打開一個圖像。Gimp Python插件不需要當前打開的圖像? (插件是通過FileChooserDialog打開/導出/關閉圖像)

下面是一個基本helloworld.py

#!/usr/bin/env python 

import gtk 
from gimpfu import * 

def plugin_main() : 

    message = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK) 
    message.set_markup("Please Help") 
    message.run() 
    gimp.quit() 

register(
    "helloworld", 
    "Saying Hi", 
    "Saying Hello to the World", 
    "William Crandell <[email protected]>", 
    "William Crandell <[email protected]>", 
    "2015", 
    "Hello Gimp", 
    "*", 
    [], 
    [], 
    plugin_main, 
    menu = "<Toolbox>/Hello/" 
) 

main() 

怎麼可以這樣運行,而無需打開任何圖像文件轉換成瘸子? Menu Disabled Visualization

幾乎相關的問題GIMP, python-fu: How to disable "Input image" and "Input drawable"

回答

1

http://www.exp-media.com/content/extending-gimp-python-python-fu-plugins-part-4

請注意,我用了一個工具箱菜單輸入字段,並清空源 圖像類型,這樣一來報價,我們的插件出現在菜單,即使沒有打開圖像,也可以選擇 。

最重要的部分是作爲插件框架見的一部分imagetypes:http://www.gimp.org/docs/python/#plugin_framework

隨着"*"爲「圖像類型」插件期待任何圖像作爲初始輸入的一部分,這意味着當前的圖像(可接受任何類型,因爲通配符*)將作爲插件啓動的一部分提供。將類型更改爲""相當於在啓動期間沒有圖像輸入,因此允許插頭在沒有當前打開的圖像的情況下運行。

#!/usr/bin/env python 

import gtk 
from gimpfu import * 

def plugin_main() : 

    message = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK) 
    message.set_markup("Thank you Frederic Jaume -> \nhttp://www.exp-media.com/content/extending-gimp-python-python-fu-plugins-part-4") 
    message.run() 
    gimp.quit() 

register(
    "helloworld", 
    "Saying Hi", 
    "Saying Hello to the World", 
    "William Crandell <[email protected]>", 
    "William Crandell <[email protected]>", 
    "2015", 
    "Hello Gimp", 
    "", 
    [], 
    [], 
    plugin_main, 
    menu = "<Toolbox>/Hello/" 
) 

main()