不需要当前打开的图像的Gimp Python插件?(通过FileChooserDialog打开/导出/关闭图像)

2024-09-30 16:26:25 发布

您现在位置:Python中文网/ 问答频道 /正文

它需要处理用户可能尚未打开的图像文件。不过,似乎只有在图像已经打开的情况下,我才会启用插件。在打开图像之前,gimp2.8附带的所有Python插件都将被禁用。搜索了很多例子,似乎每个例子都需要在插件执行之前打开一个图像。在

这是一个基本的地狱世界.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 <william@crandell.ws>",
    "William Crandell <william@crandell.ws>",
    "2015",
    "Hello Gimp",
    "*",
    [],
    [],
    plugin_main,
    menu = "<Toolbox>/Hello/"
)

main()

如何在不打开任何图像文件到Gimp的情况下运行?Menu Disabled Visualization

几乎相关的问题GIMP, python-fu: How to disable "Input image" and "Input drawable"


Tags: to图像import插件messagehellogtkmain
1条回答
网友
1楼 · 发布于 2024-09-30 16:26:25

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

Note that I used a Toolbox menu entry field, and emptied the source image type, this way, our plugin appears in the menu, and you can select it even if no image is opened.

重要的部分是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 <william@crandell.ws>",
    "William Crandell <william@crandell.ws>",
    "2015",
    "Hello Gimp",
    "",
    [],
    [],
    plugin_main,
    menu = "<Toolbox>/Hello/"
)

main()

相关问题 更多 >