Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python-Fu - pdb.query ; how to filter to readable output
Caveat: I'm new to Python & Object-Oriented Programming (and not particularly skilled with GIMP)

I'm trying to learn a little about automating GIMP, and found this tutorial:

I was able to do the first little example, finding the python console within GIMP, and learned quite a bit, enough to do some experimenting on my own.

One thing I wanted to experiment with was setting the grid color, and I guessed at several properties ("attributes"?) of the object (?) "pdb" (which I googled to discover was GIMP's "procedural database", which I take to mean the database of scriptable procedures within GIMP), but none of my attempts (like "pdb.gimp_image_grid_set_fgcolor()" or pdb.gimp_image_grid_set_foreground_color()", etc) worked. So I figured there must be a way to list all the attributes ("properties"?) of an object, and after quite a bit of googling, came up with two [relatively easy, one-liner) possibilities:




(I see they produce different info, so I'm unclear as to which, if either, will be my better option, but that's a question for later).

The problem is that both commands give too much information to look through efficiently.

So I did yet more googling, and came up with:


hoping to just get the items mentioning "grid", but all that returned was a bunch of "grid"s.

In bash, I'd try something like "pdb.query() | grep grid" (which might or might not give me usable results).

So, my questions:

1. Which is better and why, pdb.query() or dir(pdb), or are neither of these suitable for learning about the attributes/properties of an object?

2. Is there a better way of learning about the properties/attributes of an object (to figure out what attribute/property to tinker with to change the color of the grid a la the tutorial mentioned above?

3. How do I list all the attributes/properties of an object that has a lot of these attributes/properties and filter the results or present them in a way that is digestible, particularly as it relates to the output of "pdb.query" or "dir(pdb)"?



I thought to try the more complete string:


and that returned five hits. The tutorial gave me three of them, so I just did a brute-force search, going through the alphabet::


resulted in nothing.


gave me a hit. So I moved on to the next charavter, starting the alphabet over again at "a":


Getting another successful hit, I guessed this was going to be "background", so I tried


worked, and


worked. Continuing like this, I found the two missing attributes/properties are:




With further experimenting (googling didn't reveal the syntax), I found I can set the color with either:

pdb.gimp_image_grid_set_foreground_color(theImage, "red")


pdb.gimp_image_grid_set_foreground_color(theImage, "#FF0000")

But brute-force searching is a dirty hack; I need to know how to properly find the attributes/properties of an abject, and how to use them.


In Gimp's Python console, it the "Browse" button,this opens another dialog with a left pane where you can list/search procedures, and a right pane that documents the procedure parameters. The "Apply" biutton inserts a sample called in the console window.

Stop everything, and find a tutorial on Python'c "comprehensions". Comprehensions are very nice way to create lists arrays, and can be used to filter existing lists/arrays, for instance:

[p for p in dir(pdb) if 'image' in p]

PS: The tutorial you mention is awful IMHO.
Ah, great! That "Browse" button is great.

I googled (well, duckduckgo'd) "Python's comprehension", and took a look at

Whereas I can kind of follow what's being said in that tutorial, it's heavy slogging (i.e, <i>work</i>); I think I'll just make a mental not for now to absorb "comprehensions" as I mature in the use of Python, and just continue <i>play</i>ing for now so I don't lose interest. After recovering a bit from the brain-hurt of that site I found, I may muster up the courage to search for an easier-to-comprehend explanation.

Your code example is great, too! I don't completely comprehend what it's doing, but I get the gist, and can probably adapt it as needed in the future, to some extent.

I've found that a lot of tutorials are awful; this was one that at least got me started. But it wasn't long before I realized I wasn't really getting out of it what I needed. Still, it got my feet wet.

And finally, how does one go about suggesting corrections to the information presented by the "Browse" button. In this case, for the two "set color" commands:

1) the info window says the commands "get" the color rather than "set" the color,

2) the command is shown as hyphenated rather than underscored,

3) there really should be an example of how the command is called (the syntax)

If a Joe User such as myself could help to make GIMP/Python/Linux better make by making those corrections (or filing a bug against the documentation, etc), I'd like to help contribute to making things better.

Thanks for your reply! You've made things better, and I appreciate it!

1) which call(s) exactly? For bugs reports see
2) Pervasive problem. The command names are the names used in Script-fu. All this help is generated automatically from the
registration information.
3) hit the Apply button in the help, and see what you get in the Python console window.
(10-07-2018, 10:02 PM)Ofnuts Wrote: 1) which call(s) exactly? For bugs reports see




2) Pervasive problem. The command names are the names used in Script-fu. All this help is generated automatically from the registration information.

Since posting that, I've discovered it's pervasive, as if by design. If I understand you, the commands were originally hyphenated in Script-Fu, and when "copied" to PythonFu, they were converted to underscores, without converting the corresponding documentation. It helps me to understand that.

3) hit the Apply button in the help, and see what you get in the Python console window.

That helped, but not a lot. The result was:

pdb.gimp_image_grid_set_foreground_color(image, fgcolor)

What I believe would have been better is something like:


After having set a variable (such as "theImage") with the name of the image to modify (such as with "theImage = gimp.image_list()[0]"):

pdb.gimp_image_grid_set_foreground_color(theImage, "#FF0000")


pdb.gimp_image_grid_set_foreground_color(theImage, "red")

Of course, others might disagree.


Forum Jump: