You are here

Python: Using GIMP pdb functions vs. GIMP objects

I'm experimenting with writing some GIMP Python plugins, and have a programming style question before getting too involved. I have had success getting a few plugins up and running. For example, I have written a plugin that dumps the contents of the pdb to an xml-file, and have written a C# "viewer" for it that duplicates GIMP's PDB Browser so I can peruse the pdb outside of GIMP. Python, however, is not my first language. I'm using GIMP 2.8 on Win7.

It seems to me that there are often two ways of doing the same task. For example, I can create a new vectors by using...

pdb.gimp_vectors_new( image, name )
or gimp.Vectors( image, name )

Another example - the foreground colour can be set using...

pdb.gimp_context_set_foreground( colour )
or gimp.set_foreground( colour )

Similarly, I can access an image's vectors using...

( num, ids ) = pdb.gimp_image_get_vectors( image )
or vectors = image.vectors

Here, however, it seems the ids (INT32s) returned by the pdb function need to be converted into the actual vectors objects, using gimp.Vectors.from_id( id ), since almost every pdb function dealing with vectors do not accept the INT32 id. It seems to make more sense to just use image.vectors.

While there is a gimp.Image, gimp.Layer, gimp.Vectors, etc., there does not seem to be gimp.Brush, gimp.Context, etc. Thus while some taks can be handled using GIMP objects, other tasks require the use of pdb.gimp_... functions.

So after all this rambling, my question is this:

Is it better coding practice to consistently use the pdb.gimp_... functions directly, or, where possible, use the GIMP objects like image.vectors (which would be my preference)?

This is not much of an answer but the question took some shells of my eyes.
I ran into some problems the other day trying to use a "new" vectors function instead of a deprecated one and couldn't get it working. Now I understand.
To try to give you an answer anyway: I'm inclined to go with you and go for the "objects" solution. Somehow a bit confusing because of the inconsistencies but in the end much more straight forward.
I wonder how others think about it.



Not much interest in this topic! Anyway, I wrote myself a little PDB viewer program in C# that basically duplicates GIMP's PDB Browser. As a stand-alone program, it can be run independently of GIMP. If anyone is interested, it can be found at

The PDB browser looks very handy to me. Unfortunately I can't get it to run. It generates the following error:
GIMP_PDB_Viewer.exe is not a valid Win32 application.
I'm still running WinXP by the way (no .NET 4.5). That couldn't be the problem could it?

Subscribe to Comments for "Python: Using GIMP pdb functions vs. GIMP objects"