It is currently Sat Jul 06, 2024 9:25 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [SOLVED] Cannot get a Python plug-in to show up in GIMP
PostPosted: Fri Mar 15, 2013 10:08 pm  (#1) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
I have a simple python plug-in that I am trying for my first effort in plug-ins and I can't get it to show up in my GIMP 2.8 running on XP Pro. One of the things I am seeing is that the script name shows up after console.py in the splash screen as it starts up. Also, I wonder does the script file name have to be a certain form, or is that just Script-Fu?

Here is the script,


from gimpfu import *

def test_image( size, color ) :
   img = gimp.Image(size, size, RGB)
   layer = gimp.Layer(img, "Uni Layer", size, size,
        RGB_IMAGE, 100, NORMAL_MODE)
   img.disable_undo()
   img.add_layer(layer, 0)
   gimp.set_background()
   pdb.gimp_edit_fill(layer_one, BACKGROUND_FILL)
   pdb.gimp_display_new(img)
   pdb.gimp_image_undo_enable(img)

register(
   "test_image",
   "This is a test",
   "This is a test",
   "Name Test",
   "Name Test",
   "Date Test",
   "<Image>/MyScripts/Test Image",
   "*",
   [
      (PF_VALUE, "size", 100),
      (PF_COLOR, "color", "Image", (255, 127, 0)),
   ],
   [],
   test_image,
   )

main()


Any and all tips or clues would be appreciated.


Last edited by Grafx on Sat Mar 16, 2013 11:36 pm, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:04 am  (#2) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Grafx python scripts are plugins not scripts could you tell me where you installed the file and the file name

I know little about python but your file doesn't look right

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 5:24 am  (#3) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Your PF_VALUE statement is wrong. You have left out the text label:

      (PF_VALUE, "size", "Size Label", 100),


(You have another problem after this is fixed, but there's value in you learning this for yourself rather than me telling you now)

Kevin


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 10:39 am  (#4) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
Graechan wrote:
Grafx python scripts are plugins not scripts could you tell me where you installed the file and the file name

I know little about python but your file doesn't look right


They are installed where they are supposed to be installed, in the plug-ins directory. What doesn't look right about the file?

paynekj wrote:
Your PF_VALUE statement is wrong. You have left out the text label:

(You have another problem after this is fixed, but there's value in you learning this for yourself rather than me telling you now)

Kevin


Fixing the label was enough to get the plug-in to show up in GIMP.

But now when I try to run it, I notice two things. First, the plug-in is greyed out until you load an image. I used a Script-fu example as the basis of this Python plug-in and it does not require an image to be loaded in order to work. The other thing is that when I am able to run the script, I get an error,

TypeError: test_image() takes exactly 2 arguments (4 given)


I've seen this kind of error before in other plug-ins I've tried, it's a complete mystery. I don't see where I am providing 4 arguments.


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 11:18 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
Python scripts assume to operate on an image (defined automatically by python interface) UNLESS you specify that you do not want it; to do that you have to replace the image type (which you defined as "*" which means an image of any type) with "" (which means no image at all).
Try and let know

_________________
"Where am I ?"


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 11:32 am  (#6) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
dinasset wrote:
Python scripts assume to operate on an image (defined automatically by python interface) UNLESS you specify that you do not want it; to do that you have to replace the image type (which you defined as "*" which means an image of any type) with "" (which means no image at all).
Try and let know


No that didn't do it. It still is grayed out until I load an image.


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 11:42 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
I copied your script and - once modified as indicated on the previous messages - it is not greyed out on my menu, I could launch it without opening an image (I still get the error you mentioned)

_________________
"Where am I ?"


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:04 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
to avoid the error on number of parameters, you need to define the image and the drawable in the def line: "def test_image( mynewimg, mynewlayer, size, color ) :"
then you get other types of errors...sigh

_________________
"Where am I ?"


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:11 pm  (#9) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Grafx wrote:
dinasset wrote:
Python scripts assume to operate on an image (defined automatically by python interface) UNLESS you specify that you do not want it; to do that you have to replace the image type (which you defined as "*" which means an image of any type) with "" (which means no image at all).
Try and let know


No that didn't do it. It still is grayed out until I load an image.


If you change the register statement in any way you have to re-start GIMP to make it notice. Once you have the register statement fixed, you can just re-run the script after any other change.

As dinasset says, the image and drawable arguments are implicitly supplied so your function definition has to include them.

Kevin


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:19 pm  (#10) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
I am seeing some very unusual behavior in GIMP.

I tried moving the menu location in the plug-in to <Image>/Filters/Languages/Python-Fu/Test/Test Image and when I restarted GIMP, the menu was still in the old location and it was not in the new location. This is bizarre, because how would GIMP know where to keep the menu in the old location? I should say that the user I work under in XP Pro is a non-administrative user for security purposes. So I logged out and into a administrative privileges user and booted up GIMP and found that the menu had moved to the new location (after I copied the plug-ins from the other user to this user). And also in the plug-in display, I found two new requests for inputs that did not show up in the plug-in display for the other non-administrative user and so I have further clues as to what the error message means.

I logged back into the non-administrative user and found that the menu still had not moved to the new location.

Something is horribly wrong. Anybody have any idea what it is?


Top
 Post subject: Are implicit arguments a Python feature in GIMP only?
PostPosted: Sat Mar 16, 2013 12:23 pm  (#11) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
paynekj wrote:
As dinasset says, the image and drawable arguments are implicitly supplied so your function definition has to include them.


Could you provide a Python language tutorial reference for this? Or is it peculiar to Python under GIMP?


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:28 pm  (#12) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Grafx wrote:
I am seeing some very unusual behavior in GIMP.

I tried moving the menu location in the plug-in to <Image>/Filters/Languages/Python-Fu/Test/Test Image and when I restarted GIMP, the menu was still in the old location and it was not in the new location. This is bizarre, because how would GIMP know where to keep the menu in the old location? I should say that the user I work under in XP Pro is a non-administrative user for security purposes. So I logged out and into a administrative privileges user and booted up GIMP and found that the menu had moved to the new location (after I copied the plug-ins from the other user to this user). And also in the plug-in display, I found two new requests for inputs that did not show up in the plug-in display for the other non-administrative user and so I have further clues as to what the error message means.

I logged back into the non-administrative user and found that the menu still had not moved to the new location.

Something is horribly wrong. Anybody have any idea what it is?


The file pluginrc contains a datestamp that marks the last modification time and registration details for each of the plug-ins so that GIMP doesn't have to re-register them every time it starts. So I'd check if your non-administrative user has their own pluginrc file and that they have the rights to change it. : c:\Documents and Settings\username\.gimp-2.8\pluginrc


Top
 Post subject: Re: Are implicit arguments a Python feature in GIMP only?
PostPosted: Sat Mar 16, 2013 12:28 pm  (#13) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Grafx wrote:
paynekj wrote:
As dinasset says, the image and drawable arguments are implicitly supplied so your function definition has to include them.


Could you provide a Python language tutorial reference for this? Or is it peculiar to Python under GIMP?


It's GIMP specific behaviour.


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:31 pm  (#14) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
IMHO, the problem of the menu location is due to the file "pluginrc" under ...userid/gimp-2.8;
just rename it to oldpluginrc and restart gimp with you usual userid; you should find the plug-in under the new menu

_________________
"Where am I ?"


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:42 pm  (#15) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
you can find some useful info in the attached pdf


Attachments:
GIMP Python Documentation.zip [103 KiB]
Downloaded 79 times

_________________
"Where am I ?"
Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:45 pm  (#16) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
dinasset wrote:
IMHO, the problem of the menu location is due to the file "pluginrc" under ...userid/gimp-2.8;
just rename it to oldpluginrc and restart gimp with you usual userid; you should find the plug-in under the new menu


That worked. What is going on? Am I going to have to deal with this again in the future?


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 12:46 pm  (#17) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
dinasset wrote:
you can find some useful info in the attached pdf


This web page has the same information:

http://www.gimp.org/docs/python/index.html

Could you show me where this peculiarity is explained in this documentation?


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 1:10 pm  (#18) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Grafx wrote:
dinasset wrote:
you can find some useful info in the attached pdf


This web page has the same information:

http://www.gimp.org/docs/python/index.html

Could you show me where this peculiarity is explained in this documentation?


It's not explained, it's just something that you have to learn by experience or by example.

Regarding the pluginrc problem, did you check the permissions on the file before you deleted it?


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 1:17 pm  (#19) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
paynekj wrote:
It's not explained, it's just something that you have to learn by experience or by example.


That's pretty bad. It should be documented.

paynekj wrote:
Regarding the pluginrc problem, did you check the permissions on the file before you deleted it?


Yes, I explained previously that the file had the correct permissions. I did not delete it, I renamed it as you suggested.

About the function arguments issue, here is a plug-in that works fine and has a similar argument problem. My plug-in uses a lot of the code from this example.

#!/usr/bin/env python

#   Gimp-Python - allows the writing of Gimp plugins in Python.
#   Copyright (C) 1997  James Henstridge <james@daa.com.au>
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

import math
from gimpfu import *

def sphere(radius, light, shadow, foo, bg_colour, sphere_colour):
    if radius < 1:
        radius = 1

    width = int(radius * 3.75)
    height = int(radius * 2.5)

    gimp.context_push()

    img = gimp.Image(width, height, RGB)

    drawable = gimp.Layer(img, "Sphere Layer", width, height,
                          RGB_IMAGE, 100, NORMAL_MODE)

    radians = light * math.pi / 180

    cx = width / 2
    cy = height / 2

    light_x = cx + radius * 0.6 * math.cos(radians)
    light_y = cy - radius * 0.6 * math.sin(radians)

    light_end_x = cx + radius * math.cos(math.pi + radians)
    light_end_y = cy - radius * math.sin(math.pi + radians)

    offset = radius * 0.1

    img.disable_undo()
    img.insert_layer(drawable)

    gimp.set_foreground(sphere_colour)

    gimp.set_background(bg_colour)
    pdb.gimp_edit_fill(drawable, BACKGROUND_FILL)

    gimp.set_background(20, 20, 20)

    if (light >= 45 and light <= 75 or light <= 135 and
        light >= 105) and shadow:
        shadow_w = radius * 2.5 * math.cos(math.pi + radians)
        shadow_h = radius * 0.5
        shadow_x = cx
        shadow_y = cy + radius * 0.65

        if shadow_w < 0:
            shadow_x = cx + shadow_w
            shadow_w = -shadow_w

        pdb.gimp_ellipse_select(img, shadow_x, shadow_y, shadow_w, shadow_h,
                                CHANNEL_OP_REPLACE, True, True, 7.5)
        pdb.gimp_edit_bucket_fill(drawable, BG_BUCKET_FILL,
                                  MULTIPLY_MODE, 100, 0, False, 0, 0)

    pdb.gimp_ellipse_select(img, cx - radius, cy - radius, 2 * radius,
                            2 * radius, CHANNEL_OP_REPLACE, True, False, 0)
    pdb.gimp_edit_blend(drawable, FG_BG_RGB_MODE, NORMAL_MODE, GRADIENT_RADIAL,
                        100, offset, REPEAT_NONE, False, False, 0, 0, True,
                        light_x, light_y, light_end_x, light_end_y)

    pdb.gimp_selection_none(img)

    img.enable_undo()

    disp = gimp.Display(img)

    gimp.context_pop()


register(
    "python-fu-sphere",
    "Simple sphere with drop shadow",
    "Simple sphere with drop shadow",
    "James Henstridge",
    "James Henstridge",
    "1997-1999, 2007",
    "_Sphere",
    "",
    [
        (PF_INT, "radius", "Radius for sphere", 100),
        (PF_SLIDER, "light", "Light angle", 45, (0,360,1)),
        (PF_TOGGLE, "shadow", "Shadow?", 1),
        (PF_RADIO, "foo", "Test", "foo", (("Foo", "foo"), ("Bar", "bar"))),
        (PF_COLOR, "bg-color", "Background", (1.0, 1.0, 1.0)),
        (PF_COLOR, "sphere-color", "Sphere", "orange")
    ],
    [],
    sphere,
    menu="<Image>/Filters/Languages/Python-Fu/Test")

main()


I notice this has a gimp.context_push() and gimp.context_pop(). I tried applying them in the same place in my test plug-in and it crashed.

What else is different? Why does this work and mine not?


Top
 Post subject: Re: Cannot get a Python plug-in to show up in GIMP
PostPosted: Sat Mar 16, 2013 1:24 pm  (#20) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14816
Location: roma, italy
pluginrc problem:
it is something that ALWAYS happens to me when modifying the path of a plug-in; I submitted in this chat-line the problem already, but no other person here did verify that problem, so you are the first who confirms I'm not a ... single unlucky gimper!
BTW, changing the menu path of a plug-in is a rare event, so you (as me) we can survive!

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 29 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Unable to get simple python plugin to show up

8

No new posts use in python of plug-in lighting

4

No new posts Attachment(s) GIMP Python-Fu Plug-in template

4

No new posts GIMP 2.10 doesn't install my python plug-ins

1

No new posts Plug-in crashes after OS upgrade: python version mismatch? maybe?

4



* Login  



Powered by phpBB3 © phpBB Group