Gimp python plugin failing to register

I’ve been trying to write a python plugin for Gimp for a custom image file format I’m experimenting with. I can’t get the plugin to register. The plugin file’s name does show up briefly in the loading splash-screen, but the exporter doesn’t recognize the extension and the plugin doesn’t show in Gimp’s plug-in browser.

I’m using Gimp 2.1.30 on Windows 10.

Here is my current, non-working plugin. It’s pared down to minimize confounding factors for this problem:


def save_prt(img, drawable, filename, raw_filename):
  pdb.gimp_message("Exporting " + filename)

register(
	"file-prt-save",
	"Save a p-art (.prt) file",
	"Save an image to the p-art (.prt) file format.  This format is useful for storing pixel art with small file sizes.",
	"Jonathan Heard",
	"Jonathan Heard",
	"2023",
	"P-art image",
	"*",
	[
		(PF_IMAGE, "image", "Input image", None),
		(PF_DRAWABLE, "drawable", "Input drawable", None),
		(PF_STRING, "filename", "The name of the file", None),
		(PF_STRING, "raw-filename", "The name of the file", None),
	],
	[],
	save_prt,
    on_query = register_save_handlers,
    menu = '<Save>'
)

main()

Does anyone have an idea as to what might be going wrong?
Thanks!

Several things:

  • You are missing a python “shebang” (at least if you expect to run on Unix/OSX:
#!/usr/bin/env python2
  • You are missing the gimpfu import:
from gimpfu import *
  • You don’t provide a body for register_save_handlers, you normally need something like:
def register_save_handlers():
    gimp.register_save_handler('file-prt-save', 'prt', '')

It is much easier to debug these scripts on Linux/OSX but here are some tips to ease your life on Windows: Debugging python-fu scripts in Windows

PS: " It’s pared down to minimize confounding factors for this problem": the danger of doing so is that you could remove the problem part. When you call for help, it is often because you are not looking at the right spot.

Thank you for replying with this information! I’ve obviously missed some basic stuff. I got to where I was by working out a basic export function in the console. I then studyied “file-openraster.py” for how to register the function for file export. When I said that I’d pared down my code, I just meant that I swapped my export function with a console message, after which I did confirm that the problem remained.

I’ll continue to study “file-openraster.py” as I must be still missing something. It’s just that there is a lot of code that is not useful for what I’m trying to do, making it tricky to sport important things like “register_save_handlers”.

Thanks for the link, the final suggestion of “Routing python outputs to file” seems like it might help.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.