Python plugin dev: getting picked color from gimpui.PickButton.color-picked event callback?
This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
Python plugin dev: getting picked color from gimpui.PickButton.color-picked event callback? | Viet Nguyen | 05 Feb 23:20 |
Python plugin dev: getting picked color from gimpui.PickButton.color-picked event callback? | Joao S. O. Bueno | 05 Feb 23:54 |
Python plugin dev: getting picked color from gimpui.PickButton.color-picked event callback? | Viet Nguyen | 06 Feb 00:16 |
Python plugin dev: getting picked color from gimpui.PickButton.color-picked event callback?
My goal is to write behavior where a click on my special pick button will
1. Modify layer visibility
2. Run the normal pick tool
3. Do something with the picked color
I'm trying to do this as a Python plugin so I'm trying to implement this using `gimpui.PickButton` and adding event callbacks for `clicked` and `color-picked`. I'm using `pydoc gimpui` as a reference.
Unfortunately the Python API apparently has obscured the color data structure that gets passed to the `color-picked` event callback. It passes it as a `gobject.gpointer` which is just an intractable pointer (see http://developer.gimp.org/api/2.0/libgimpwidgets/GimpPickButton.html#GimpPickButton-color-pickedand https://developer.gnome.org/glib/2.37/glib-Basic-Types.html#gpointer). I don't know of any way to pull out the triple double union in Python.
A simpler solution would be to simply "activate" the standard color picker, but I can't figure out how to do that with the API available. I would appreciate any help and/or ideas on this.
Thanks!
Viet
Python plugin dev: getting picked color from gimpui.PickButton.color-picked event callback?
You are really trying something very different than what the current
GIMP-Python integration is thought of to do:
You are using gobject introspection to call functions that up to now
have only been called from native-code
plug-ins (normally in C), and have no provision to be called from
Python or other language supported
by gobject introspection but for the automatic generation of the bindings.
I am in fact surprised you could get this far.
GIMP-Python plug-ins, AKA python-fu, are designed to around a python-module
that is delivered with GIMP, and comunicates with GIMP through the
"Procedural database" (PDB).
The module does have some higher level constructs, such as images,
layers, layer-groups,
but these are just rebuilt on the Python side from values such as
numeric and string IDs fetched
from GIMP through pdb calls.
That said, you can see all your available API by going to help->PDB
browser on GIMP.
(Open any .py file that comes with GIMP to see how the plug-ins are
registered and created,
if yours go on a completely different way by trying to use the libgimp API)
Now, plug-ins in GIMP - neither the ones built using native code - are
not supposed
to be able to change the active tool while running - so, to get
exactly what you want is impossible.
You can make a Python plug-in that will display a custom gtk+ window,
change a layer's visibility,
and display instructions for the user to change to the color picker
tool (maybe your hack with gobject
can do that, but I would not trust it across GIMP versions/platforms),
and pick a color.
At this time, the plug-in can read the picked color with a call to
pdb.gimp_context_get_foreground .
js -> wrote:
My goal is to write behavior where a click on my special pick button will
1. Modify layer visibility 2. Run the normal pick tool
3. Do something with the picked colorI'm trying to do this as a Python plugin so I'm trying to implement this using `gimpui.PickButton` and adding event callbacks for `clicked` and `color-picked`. I'm using `pydoc gimpui` as a reference.
Unfortunately the Python API apparently has obscured the color data structure that gets passed to the `color-picked` event callback. It passes it as a `gobject.gpointer` which is just an intractable pointer (see http://developer.gimp.org/api/2.0/libgimpwidgets/GimpPickButton.html#GimpPickButton-color-pickedand https://developer.gnome.org/glib/2.37/glib-Basic-Types.html#gpointer). I don't know of any way to pull out the triple double union in Python.
A simpler solution would be to simply "activate" the standard color picker, but I can't figure out how to do that with the API available. I would appreciate any help and/or ideas on this.
Thanks!
Viet _______________________________________________ gimp-developer-list mailing list
List address: gimp-developer-list@gnome.org List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list List archives: https://mail.gnome.org/archives/gimp-developer-list
Python plugin dev: getting picked color from gimpui.PickButton.color-picked event callback?
Thanks Joao, I appreciate the reply!
Your solution at the end is what I planned on falling back on in case a more integrated solution didn't pan out. It would have been nice for simple UX reasons, but I wasn't really aware of the limits of GIMP plug-in writing with Python. I did feel like I was swimming beyond the safe waters of "Documentation Bay".
Are the Python hooks for `gimpui` and company there as a sort of "future
features" to be fleshed out? Also, I've been working on a Ubuntu machine
and writing my plugin using
http://gimpbook.com/scripting/gimp-script-templates/life.py as a scaffold.
I don't have a Windows install yet so I'm wondering how portable will the
GTK interface be on a Windows machine?
Thanks again!
Viet
On Wed, Feb 5, 2014 at 3:54 PM, Joao S. O. Bueno wrote:
You are really trying something very different than what the current GIMP-Python integration is thought of to do: You are using gobject introspection to call functions that up to now have only been called from native-code plug-ins (normally in C), and have no provision to be called from Python or other language supported
by gobject introspection but for the automatic generation of the bindings.I am in fact surprised you could get this far.
GIMP-Python plug-ins, AKA python-fu, are designed to around a python-module that is delivered with GIMP, and comunicates with GIMP through the "Procedural database" (PDB).
The module does have some higher level constructs, such as images, layers, layer-groups,
but these are just rebuilt on the Python side from values such as numeric and string IDs fetched
from GIMP through pdb calls.That said, you can see all your available API by going to help->PDB browser on GIMP.
(Open any .py file that comes with GIMP to see how the plug-ins are registered and created,
if yours go on a completely different way by trying to use the libgimp API)Now, plug-ins in GIMP - neither the ones built using native code - are not supposed
to be able to change the active tool while running - so, to get exactly what you want is impossible.You can make a Python plug-in that will display a custom gtk+ window, change a layer's visibility,
and display instructions for the user to change to the color picker tool (maybe your hack with gobject
can do that, but I would not trust it across GIMP versions/platforms), and pick a color.
At this time, the plug-in can read the picked color with a call to pdb.gimp_context_get_foreground .js -> wrote:
My goal is to write behavior where a click on my special pick button will
1. Modify layer visibility 2. Run the normal pick tool
3. Do something with the picked colorI'm trying to do this as a Python plugin so I'm trying to implement this using `gimpui.PickButton` and adding event callbacks for `clicked` and `color-picked`. I'm using `pydoc gimpui` as a reference.
Unfortunately the Python API apparently has obscured the color data structure that gets passed to the `color-picked` event callback. It
passes
it as a `gobject.gpointer` which is just an intractable pointer (see
http://developer.gimp.org/api/2.0/libgimpwidgets/GimpPickButton.html#GimpPickButton-color-pickedand
https://developer.gnome.org/glib/2.37/glib-Basic-Types.html#gpointer). I don't know of any way to pull out the triple double union in Python.
A simpler solution would be to simply "activate" the standard color
picker,
but I can't figure out how to do that with the API available. I would appreciate any help and/or ideas on this.
Thanks!
Viet _______________________________________________ gimp-developer-list mailing list
List address: gimp-developer-list@gnome.org List membership:https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives: https://mail.gnome.org/archives/gimp-developer-list