Post Reply 

Python "gimp-fu" script won't show up in menu

Jan 28, 2014, 11:07 (This post was last modified: Jan 28, 2014 11:16 by MightyPork.)
Post: #1
Python "gimp-fu" script won't show up in menu
Hello,
I've made a simple gimpfu script, and I'm pretty sure it's correct, but it doesn't get loaded by Gimp.

Here is the code:

Code:
#!/usr/bin/env python

from gimpfu import *

def dark_border(img, layer, opacity, thickness):
    
    fg_old = gimp.get_foreground()

    img = gimp.image_list()[0]
    pdb.gimp_image_undo_group_start(img)

    w = img.width
    h = img.height

    thickness = round((w/1920.0)*thickness)

    layer = gimp.Layer(img, "Border", w, h, RGBA_IMAGE, opacity, NORMAL_MODE)
    img.add_layer(layer)

    gimp.set_foreground((0,0,0))

    pdb.gimp_selection_all(img)
    pdb.gimp_selection_shrink(img, thickness)
    pdb.gimp_selection_invert(img)

    pdb.gimp_edit_fill(layer, FOREGROUND_FILL)

    pdb.gimp_selection_none(img)

    gimp.set_foreground(fg_old)
    pdb.gimp_image_undo_group_end(img)
    

# Register with The Gimp
register(
    "dark_border",
    "Dark photo border",
    "Dark photo border",
    "MightyPork",
    "MightyPork",
    "2014",
    "<Image>/FOOBAR/Dark border",
    "*",
    [
        (PF_SLIDER, "opacity", "Border Opacity", 50, (1, 101, 1)),
        (PF_SPINNER, "thickness", "Thickness (in 1080p)", 50, (0, 1000, 1)),
    ],
    [],
    dark_border)
    
main()

Technical stuffs
Gimp 2.8.10
Xubuntu 12.04

I've installed the file into ~/.gimp-2.8/plug-ins and made it executable. I also tried to put it in /usr/lib/gimp/plug-ins and /usr/share/gimp/plug-ins (that folder didn't even exist!). Alas, nothing shows up.

I have "Gimp plugin registry" installed and it works fine (except that it added a ton of bloat to the menubar), and Python-fu console also works perfectly.

Running Gimp from command line yields no error message either.

Please help.
Find all posts by this user
Quote this message in a reply
Jan 28, 2014, 13:04
Post: #2
RE: Python "gimp-fu" script won't show up in menu
(Jan 28, 2014 12:37)ofnuts Wrote:  Hmm. Works for me... (I get "FOOBAR" added in my menu bar).

~/.gimp-2.8/plug-ins is the right spot. Add a print statement in it (outside of cuntion defintions) and it should show up in the terminal if you start Gimp from there.

Also check the ~/.gimp-2.8/pluginrc file. Se if it contains your file. The file is only run for re-registration if found more recent than the timestamp kept in pluginrc when Gimp starts, so you have to exit Gimp completely if you change something to the script registration (other code changes are fine and taken on the fly).

Btw, remove:
Code:
img = gimp.image_list()[0]

By convention the image argument of you script, if it is the first, receives the image from which the script is called. With the line above you run the risk to execute the script on the wrong image.

Hmm... weird.
Now after reboot, it works - all by itself.

Anyway thanks for the tips about img, it's fixed now.
Find all posts by this user
Quote this message in a reply
Jan 28, 2014, 14:27
Post: #3
RE: Python "gimp-fu" script won't show up in menu
(Jan 28, 2014 13:58)ofnuts Wrote:  Because by rebooting you had gimp restart and look at the new version of your script.

Another comment: if you want to save/restore colors/palette/brush/etc... it is more efficient to bracket your whole code between gimp.context_push()/gimp.context_pop().

Okay, I'll try that. As there is pretty much no documentation, I used what I saw in other plugins.
Find all posts by this user
Quote this message in a reply
Jan 28, 2014, 14:57
Post: #4
RE: Python "gimp-fu" script won't show up in menu
(Jan 28, 2014 14:51)ofnuts Wrote:  See http://www.gimp.org/docs/python/index.html

Also, when you use the python-fu console, issue dir(x) on your variables. You may find intersting methods (usually direct transplant of the PDB stuff, so the parameters are easy to figure out, and this makes the code easier to read).

I know that page, it's good reference but nowhere near complete. And for the `dir` command, it's good, but I still haven't figured out how to find what parameters the functions take - __doc__ is useless and help(...) gives just some gibberish, so it's always hit-or-miss, or hunting for usage examples in other scripts.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Does gimp have optical filter imitations? godek 1 294 Dec 11, 2017 11:40
Last Post: paynekj
  plugin save for web in Gimp 2.9.6 Dkk 1 271 Oct 19, 2017 09:02
Last Post: paynekj
  Request for script chlebna 1 238 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 301 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 1 339 Aug 31, 2017 14:32
Last Post: Bertholomäus

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS