Gimp-Forum.net
Python-Fu Gimp 3.2.4. Get the active image - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+--- Thread: Python-Fu Gimp 3.2.4. Get the active image (/Thread-Python-Fu-Gimp-3-2-4-Get-the-active-image)

Pages: 1 2


Python-Fu Gimp 3.2.4. Get the active image - Burcador - 07-21-2026

Hi!

Question about Python-Fu Gimp 3.2.4

How do I get the active image (the one with focus) from all open images?


RE: Python-Fu Gimp 3.2.4. Get the active image - Scallact - 07-21-2026

(07-21-2026, 12:56 PM)Burcador Wrote: Hi!

Question about Python-Fu Gimp 3.2.4

How do I get the active image (the one with focus) from all open images?

Its automatically included into the main function arguments by the initial procedure. In this function:
Code:
def my_function(procedure, run_mode, image, drawables, config, data) :

"image" is the active image when you call the plugin.


What about during operation? - Burcador - 07-21-2026

(07-21-2026, 03:06 PM)Scallact Wrote: def my_function(procedure, run_mode, image, drawables, config, data) :[/code]

"image" is the active image when you call the plugin.

No, not when the plugin is initialized.

My plugin launches a panel with buttons for launching several plugins.

While it's running, several images are open.
I'm switching between them.
The panel is open.

But how do I determine the active image so I can apply the plugin launched by the panel button to it?

The plugin only detects the active image upon startup. What about during operation?


RE: What about during operation? - rich2005 - 07-21-2026

(07-21-2026, 03:51 PM)Burcador Wrote: ....snip,,,,
My plugin launches a panel with buttons for launching several plugins.

That reads like this plugin https://www.chuckhenrich.com/custom-command-panel-gimp/

It is up to the user to choose the alternative image, which then brings up the plugin dialog.

[attachment=14556]

Maybe have a look at the code, there might be something in it that you can apply to your project.


RE: What about during operation? - Burcador - 07-21-2026

(07-21-2026, 04:57 PM)rich2005 Wrote: That reads like this plugin https://www.chuckhenrich.com/custom-command-panel-gimp/
It is up to the user to choose the alternative image, which then brings up the plugin dialog.

The plugin is excellent, thank you.
I'll use it.

However, the author also couldn't find a way to automatically detect the active image.
Instead, he suggests choosing from among the open ones to apply the plugin to, which you launch if you have multiple images.

Basically, I did it in a similar way, except I select the image before launching it.
. . .
But I'd like to find a more elegant way.


RE: Python-Fu Gimp 3.2.4. Get the active image - MrsP-from-C - 07-22-2026

There were feature request about that:

https://gitlab.gnome.org/GNOME/gimp/-/work_items/16502
https://gitlab.gnome.org/GNOME/gimp/-/work_items/6572

so I guess it's not possible yet?


RE: Python-Fu Gimp 3.2.4. Get the active image - Burcador - 07-22-2026

(07-22-2026, 08:25 AM)MrsP-from-C Wrote: There were feature request about that:
https://gitlab.gnome.org/GNOME/gimp/-/work_items/16502
https://gitlab.gnome.org/GNOME/gimp/-/work_items/6572
so I guess it's not possible yet?

That seems to be the case.
All we can do is wait.


RE: Python-Fu Gimp 3.2.4. Get the active image - CmykStudent_ - 07-23-2026

Honestly, I thought we had an PDB call for this as well.

This merge request may be of interest: https://gitlab.gnome.org/GNOME/gimp/-/merge_requests/2923

If merged, getting the active image would be Gimp.context_get_image () in Python.


RE: Python-Fu Gimp 3.2.4. Get the active image - Scallact - 07-23-2026

(Yesterday, 03:04 AM)CmykStudent_ Wrote: Honestly, I thought we had an PDB call for this as well.

This merge request may be of interest: https://gitlab.gnome.org/GNOME/gimp/-/merge_requests/2923

If merged, getting the active image would be Gimp.context_get_image () in Python.

I think there never was. I remember I struggled to get the active image in the python terminal in GIMP 2.10.


RE: Python-Fu Gimp 3.2.4. Get the active image - CmykStudent_ - 07-23-2026

Scallact: Yeah, that seems to be the case. It was just surprising!

At any rate, the code's now merged, so after the next release people can use Gimp.context_get_image () and Gimp.context_set_image () as they like. Thanks everyone here for bringing it up!