Reputation: 1351
I am trying to write my own Python plug-in for the GNU Image Manipulation Plug-In. I was following this tutorial at this URL: http://gimpbook.com/scripting/slides/index.html. I changed some of the variable names and named the script something different but basically it is the same script.
The script works when calling it from the interactive GIMP Python shell. I access by doing this with the mouse: "Filters -> Python-Fu -> Console". Here the hello_world()
function works.
However, when I put the plug-in in the .gimp2.8/plugins/
folder or the /usr/lib/gimp/2.0/plug-ins
I am not able to see the plug-in in the Plug-In Browser
after going to Help -> Plug-In Browser
. Does anyone know what I am missing?
Regards,
My source-code for the Python GIMP plug-in is below...
#! /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()
Upvotes: 2
Views: 1915
Reputation: 2804
2 problems with the code stood out to me the function/call mismatched and a missing delimiting comma
(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()
So adding the comma and renaming hello_world
to easier_gimp
allow the plugin to work.
#! /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()
Recently have been created Python based Hello World GIMP plugin examples in this github project
Upvotes: 0
Reputation: 1351
I found out a solution! I read a few tutorials online and switched to a different development environment, Eclipse using the PyDev plug-in. PyDev was able to point out syntax errors in the overly complex register()
function.
#! /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()
This shows up in the Filters -> Python-Fu -> Console -> Browse
. It also shows up in the toolbar under Tools
.
These links helped:
Upvotes: 0
Reputation: 110456
If the script does not show on the menus it means the call to "register" and "main" above is not being run. One possibility is that you have not marked your Python file with the exectutable permission. (Check the file properties, or run chmod 777 myfile.py
on it)
Another possibility is a Python syntax error - that could be difficult to spot giving the listing - to check for syntax errors, try just running the script as a normal Python program from the shell: $ python myfile.py
- that should yield an ImportError
. If you see a SyntaxError
, fix that instead.
And finally, with the plug-in in place, start it from the terminal, instead of the menus - if GIMP found your plug-in but stumbled on an error on it, it should display a Wire read error
on the terminal output: it also could indicate a Python syntax error, or incorrect call to register
(too few or too many parameters). Since by this time you have ruled out syntax errors, double check your parameter count to register
)
It should show up in the menus when you have fixed stuff thus far.
Upvotes: 3