GNOME Bugzilla – Bug 624303
Introduce an item class in PyGIMP
Last modified: 2012-04-21 04:29:09 UTC
Recently I found that no python plugins were working (which was annoying, since I use OpenRaster loading a fair bit). I eventually determined that it wasn't my Python installation (Python 2.6.5, pygtk 2.21.3). I found that when compiling PyGimp, I would get warnings like this: pygimp-vectors.c: In function 'vs_repr': pygimp-vectors.c:293:5: warning: implicit declaration of function 'gimp_vectors_get_name' pygimp-vectors.c:293:10: warning: assignment makes pointer from integer without a cast pygimp-vectors.c: In function 'vbs_repr': pygimp-vectors.c:473:10: warning: assignment makes pointer from integer without a cast pygimp-vectors.c: In function 'vectors_parasite_find': pygimp-vectors.c:649:5: warning: implicit declaration of function 'gimp_vectors_parasite_find' pygimp-vectors.c:649:5: warning: passing argument 1 of 'pygimp_parasite_new' makes pointer from integer without a cast pygimp.h:107:11: note: expected 'struct GimpParasite *' but argument is of type 'int' pygimp-vectors.c: In function 'vectors_parasite_attach': pygimp-vectors.c:661:5: warning: implicit declaration of function 'gimp_vectors_parasite_attach' pygimp-vectors.c: In function 'vectors_parasite_detach': pygimp-vectors.c:680:5: warning: implicit declaration of function 'gimp_vectors_parasite_detach' pygimp-vectors.c: In function 'vectors_parasite_list': pygimp-vectors.c:697:5: warning: implicit declaration of function 'gimp_vectors_parasite_list' pygimp-vectors.c: In function 'vectors_get_image': pygimp-vectors.c:742:5: warning: implicit declaration of function 'gimp_vectors_get_image' pygimp-vectors.c: In function 'vectors_get_name': pygimp-vectors.c:754:5: warning: passing argument 1 of 'PyString_FromString' makes pointer from integer without a cast /usr/include/python2.6/stringobject.h:63:24: note: expected 'const char *' but argument is of type 'int' pygimp-vectors.c: In function 'vectors_set_name': pygimp-vectors.c:770:5: warning: implicit declaration of function 'gimp_vectors_set_name' pygimp-vectors.c: In function 'vectors_get_visible': pygimp-vectors.c:778:5: warning: implicit declaration of function 'gimp_vectors_get_visible' pygimp-vectors.c: In function 'vectors_set_visible': pygimp-vectors.c:794:5: warning: implicit declaration of function 'gimp_vectors_set_visible' pygimp-vectors.c: In function 'vectors_get_linked': pygimp-vectors.c:802:5: warning: implicit declaration of function 'gimp_vectors_get_linked' pygimp-vectors.c: In function 'vectors_set_linked': pygimp-vectors.c:818:5: warning: implicit declaration of function 'gimp_vectors_set_linked' pygimp-vectors.c: In function 'vectors_get_tattoo': pygimp-vectors.c:826:5: warning: implicit declaration of function 'gimp_vectors_get_tattoo' pygimp-vectors.c: In function 'vectors_set_tattoo': pygimp-vectors.c:842:5: warning: implicit declaration of function 'gimp_vectors_set_tattoo' pygimp-vectors.c: In function 'vectors_repr': pygimp-vectors.c:891:10: warning: assignment makes pointer from integer without a cast pygimp-vectors.c: In function 'pygimp_vectors_new': pygimp-vectors.c:982:5: warning: implicit declaration of function 'gimp_vectors_is_valid' I am assuming the result is, this code compiles alright but crashes at load time. I think this is a fairly simple fix (just update the API usage like the other plugins were.); I'll try to create a patch.
Created attachment 165847 [details] [review] use (PF|PDB)_ITEM instead of _REGION in gimpfu.py so pygimp works again The problem was actually that the PDB_REGION reappropriation had caused gimpfu.py to crash because PDB_REGION constant no longer existed. However, this patch also updates PyGimp to use the new item API. I'd appreciate if someone could review the drawable_attach_new_parasite() changes; I made them fairly blindly based on the changes in commit c6a2eaa5c4f704118e525e478a2faca8c2ff0295) This patch fixes the problems, all python plugins work again :)
Great, thanks :) I'll apply this patch later tonight, but: more drawable/vectors/channels API deprecation is coming in favor of a new uniform item API. The real fix would be of course to introduce a pygimp item class, derive the drawable and item classes from it, and to deprecate the affected pygimp drawable and vectors API too. Are you python-expert enough to try that? I am not :/
I considered the GimpItem subclassing, but do not yet know the required information on implementing C inheritance. http://docs.python.org/c-api/typeobj.html Seems to have the necessary details, so I may attempt it.
(not that that should stop you from committing this patch -- I won't have time to work on the subclassing approach for a solid block of time until the 27th, an pygimp ought to be unbroken in the meantime.)
Applied the patch, leaving the bug open for the item refactoring. commit cebbde5da936600aeb4740f3d7d8b53bb2c12b24 Author: David Gowers <00ai99@gmail.com> Date: Wed Jul 14 16:59:21 2010 +0930 plugins/pygimp: use (PF|PDB)_ITEM instead of _REGION so pygimp works again. Also update vectors and drawable code to use the new GimpItem API. plug-ins/pygimp/gimpfu.py | 8 ++-- plug-ins/pygimp/pygimp-drawable.c | 57 ++++++++++++++++++++---------------- plug-ins/pygimp/pygimp-tile.c | 6 ++-- plug-ins/pygimp/pygimp-vectors.c | 34 +++++++++++----------- 4 files changed, 56 insertions(+), 49 deletions(-)
From what I understand, fixing this is not critical, just very sensible. Putting on Future for now.
PyGIMP is working, there is a PyGIMP item class, gimp.Drawable (and Layer, GroupLayer, Channel) inherit from it - Vectors still not, Palletes, Gradients and Brushes are not wrapped as Python objects (acess to them is via their name as a string using the PDB). I consider this to be fixed - another bug may be opened for making gimp.Vectors inherit from gimp.Item as well.