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
  Run Deskew plugin from Python-Fu console ramonvaldezz 11 3,007 Yesterday 09:00
Last Post: dmig
  Run script on action rchav 2 1,122 Aug 13, 2018 14:57
Last Post: rchav
  Script Fu Errors Gimp 2.10.4 lightsaber jd3481 1 707 Aug 2, 2018 05:13
Last Post: paynekj
  Script-fu script to conversion pdf to image 4ever 12 13,092 Jul 17, 2018 16:01
Last Post: paynekj
  GIMP Resynthesizer Plugin not working Mikkel Andersen 1 687 Jun 26, 2018 16:36
Last Post: paynekj

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS