Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python plugin development
#1
Hello here! 

I've been trying to make a Python plugin for Gimp for two days now. For now, my goal is quite simple, I want to be able to create / duplicate layers, etc. 

So I made my python file, put it in the right folder, registered it, etc. 

Here is the code I got for now: 

Code:
#!/usr/bin/env python

from gimpfu import *


def test_function(image, drawable):
   pdb.gimp_drawable_set_name(drawable, "My new layer name")
   pdb.gimp_message("Test 1")
   
   width = drawable.width
   pdb.gimp_message("Test 2")
   
   height = drawable.height
   pdb.gimp_message("Test 3")
   
   img = gimp.image(width, height, RGB)
   pdb.gimp_message("Test 4")
   
   layer_one = gimp.layer(img, "My layer", width, height, RGB_IMAGE, 100, NORMAL_MODE)
   pdb.gimp_message("Test 5")
   
   img.add_layer(layer_one, 0)
   pdb.gimp_message("Test 6")
   

register(
   "python-fu-test-function",
   "Test script",
   "This is a test script",
   "Me", "Me", "2022",
   "Test",
   "",
   [
       (PF_IMAGE, "image", "takes current image", None),
       (PF_DRAWABLE, "drawable", "Input layer", None)
   ],
   [],
   test_function, menu="<Image>/File")  # second item is menu location

main()

As a result, I got displayed in the warning console: 

"Test 1"
"Test 2"
"Test 3"

And that's it. It seems that the line "img = gimp.image(width, height, RGB)" stops the script (without error message), while nothing seems particularly off with it. 
Actually, this line of code was copy pasted from this documentation (sample, section 2.1).  

As I'm working on this, I have the feeling to be dealing with a development that seems quite random. Not having the possibility to work in a proper development environment is really tiring, each time I'm coming up with something I have to save the python script, go in gimp, launch the script, see if it works, retry...

Do someone have advices on this matter?

Thank you very much.
Reply


Messages In This Thread
Python plugin development - by Milarck - 01-06-2022, 07:26 PM
RE: Python plugin development - by Ottia Tuota - 01-06-2022, 09:00 PM
RE: Python plugin development - by nelo - 01-07-2022, 08:42 AM
RE: Python plugin development - by gasMask - 01-08-2022, 05:06 PM
RE: Python plugin development - by rich2005 - 01-08-2022, 05:31 PM
RE: Python plugin development - by nelo - 01-08-2022, 06:09 PM

Forum Jump: