Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gimp.image_list() vs pdb.gimp_image_list()
#1
➤> pdb.gimp_image_list()
(1, (1,))

➤> gimp.image_list()
[<gimp.Image '[KentsHouse-FamInDen] (imported)'>]

Obviously two different commands (procedures? attributes? properties?), despite their similar names.

The Python Console "Browse" button shows info about pdb.gimp_image_list(), but seems to know nothing about the other. Where is this other command coming from (if not GIMP's internal Procedure DataBase), and how would I know about it if I hadn't just stumbled onto it?

--
Kent
Reply
#2
There is an additional "object" layer in the Python interface. Many things in the PDB also exist as object methods and make the code a lot easier to write (and read...). A general documentation can be found here, but not everything is 100% documented. A good way to find things is to use dir(object) on various objects. You will see fairly obvious equivalents of the PDB functions:
  • read-only attributes that are the equivalents of get*() functions
  • read/write attributes that are the equivalents of get*() and set*() functions
  • plain methods
Reply
#3
(10-07-2018, 10:14 PM)Ofnuts Wrote: There is an additional "object" layer in the Python interface. Many things in the PDB also exist as object methods and make the code a lot easier to write (and read...). A general documentation can be found here, but not everything is 100% documented. A good way to find things is to use dir(object) on various objects. You will see fairly obvious equivalents of the PDB functions:
  • read-only attributes that are the equivalents of get*() functions
  • read/write attributes that are the equivalents of get*() and set*() functions
  • plain methods

So I guess gimp.image_list() is not documented as I don't seem to be able to find docs on it anywhere.

Also, I'm new to GIMP python programming and looking at the PDB many of the procedures (like the pdb.gimp_image_lower_item()) make reference to  parameters like image IMAGE The Image, or item ITEM The Item to lower but nowhere do I seem to be able to find docs on how you get a reference to those parameters.

For example for the referenced procedure, I can't seem to find another procedure to get a reference to the item i want to lower.  Same, same for the reference to the parameter image. 

I see your reference to the gimp.image_list() function which returns a reference to an image and I understand that, but had I not found this post thread, I would still be scratching my head trying to figure out how I get references to parameters that i want to use in PDB procedures.

Hope this make sense.  I usually can figure this type of stuff out with a new programming language after a bit of trial and error, but I'm totally stuck on how to use the PDB when I can't figure out how to get references to objects used as parameters in PDB procedures.

Thanks in advance for any help to solving my problem.
Reply
#4
I agree with the comments by wc.smith. This lack of references creates the greatest problem (and frustration) for anyone beginning to use GIMP Python.
If this were to be resolved, I am certain that there would be many more writers of GIMP plug-ins.
Reply
#5
The API is originally for script-fu and only uses integer "handles" (that are handle to "items", i.e., image components: layers, masks, channels, paths...). For Python, the API creates façade objects, so that instead of using typeless handles and PDB calls everywhere, you can use methods on the facade objects. And for consistency, calls that return a handle in script-fu return a Python object of the adequate type, and calls with arguments that are handel/items in Script-fu are passed the Python objects.

If you do this:
Code:
➤> gimp.image_list()[0].active_layer.__class__.__mro__

You get the class hierarchy:

Code:
(<type 'gimp.Layer'>, <type 'gimp.Drawable'>, <type 'gimp.Item'>, <type 'object'>)

The  gimp.Item defines an ID attribute that is the very same thing as the "handle" of items in script-fu (but you very rarely need to use it), and if  necessary (read: never in practice...) there are gimp._id2drawable, gimp._id2vectors,gimp._id2image methods to obtain a Python object from its plain handle.
Reply
#6
OK.  I think I am beginning to understand the issue here.  I'll work at it a bit to see if I can improve my understanding.
Reply
#7
(10-31-2021, 05:01 PM)wc.smith Wrote: OK.  I think I am beginning to understand the issue here.  I'll work at it a bit to see if I can improve my understanding.

My collection of Gimp Python scripts is here: http://sourceforge.net/projects/gimp-too...s/scripts/

Should help you understand how it all fits together. Quite simple, actually.
Reply
#8
Yes, I have already started checking them out.  I was also unaware of the help() system in the python console.  That has been very beneficial as well, plus doing a lot of dir(this and that) in the console.

Thanks for your assistance.

Warren
Reply


Forum Jump: