简体   繁体   中英

Gimp Python plugin without requiring a currently open image? (Plug is to Open/Export/Close image via FileChooserDialog)

It is desired to work with an image file that a user may have yet to open. Though it seems like I am restricted to enabling the plugin only if an image has already been opened. All the Python plugins that come with Gimp 2.8 are disabled until an image is opened. Searched through many examples and it seems that every example located require an image to already be opened before the plugin can execute.

Here is a basic 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 <william@crandell.ws>",
    "William Crandell <william@crandell.ws>",
    "2015",
    "Hello Gimp",
    "*",
    [],
    [],
    plugin_main,
    menu = "<Toolbox>/Hello/"
)

main()

How can this run without opening any image file into Gimp? 菜单禁用的可视化

Almost related Question GIMP, python-fu: How to disable "Input image" and "Input drawable"

A Quote from 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.

The important part is the imagetypes which is part of the plugin framework see: http://www.gimp.org/docs/python/#plugin_framework

With "*" as the 'image type' the plugin is expecting any image as part of the initial input, meaning the current image (with any type accepted because the wildcard * ) will be supplied as part of the plugin initiation. Changing the type to "" is equivalent to saying no image input during initiation therefore allowing the plug to run without a currently opened image.

#!/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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM