Hello,
my name is Thomas and I'm a computer scientist from Berlin, working in
the embedded industry. In my spare time I work in the Geany IDE and Rockbox.
I'm struggling to make pygtk work with a library that provides gir
bindings. I read that pygtk is based on pygobject and therefore I would
expect that pygtk would work together with other GI libraries (perhaps
in a limited fashion).
I attached my files for a reduced test scenario. test.c has a function
that returns a GtkWidget. test.[ch] go into a shared library that is
g-ir-scanned. test.py calls its function via gi. Since the function
returns a GtkWidget this is where things break.
This is the error output (make everything, then run with
GI_TYPELIB_PATH=$PWD python2 test.py):
/usr/lib/python2.7/site-packages/gobject/constants.py:24: Warning:
g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0'
failed
import gobject._gobject
Traceback (most recent call last):
File "test.py", line 11, in <module>
l = Test.label_new("Test Label")
File "/usr/lib/python2.7/site-packages/gi/importer.py", line 68, in
load_module
dynamic_module._load()
File "/usr/lib/python2.7/site-packages/gi/module.py", line 296, in _load
self._overrides_module = importlib.import_module('gi.overrides.' +
self._namespace)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in
import_module
__import__(name)
File "/usr/lib/python2.7/site-packages/gi/overrides/Gtk.py", line
26, in <module>
from gi.repository import GObject
File "/usr/lib/python2.7/site-packages/gi/importer.py", line 68, in
load_module
dynamic_module._load()
File "/usr/lib/python2.7/site-packages/gi/module.py", line 296, in _load
self._overrides_module = importlib.import_module('gi.overrides.' +
self._namespace)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in
import_module
__import__(name)
File "/usr/lib/python2.7/site-packages/gi/overrides/GObject.py",
line 534, in <module>
class Object(GObjectModule.Object):
File "/usr/lib/python2.7/site-packages/gi/module.py", line 222, in
__getattr__
wrapper = metaclass(name, bases, dict_)
TypeError: metaclass conflict: the metaclass of a derived class must be
a (non-strict) subclass of the metaclasses of all its bases
Perhaps I'm doing something wrong, or am I'm miserably misunderstanding
pygtk/pygobject/gi. Can you assist me and lighten me up, please?
Best regards.
all: Test-0.1.typelib
libtest.so: test.c test.h
gcc $(shell pkg-config --cflags glib-2.0 gtk+-2.0) -o libtest.so
-shared -fPIC test.c \
-Wl,-z,defs $(shell pkg-config --libs glib-2.0 gtk+-2.0)
Test-0.1.gir: libtest.so
g-ir-scanner -i Gtk-2.0 $(shell pkg-config --cflags-only-I glib-2.0
gtk+-2.0) \
-L$(shell pwd) -n Test --nsversion 0.1 test.c test.h --library
test --warn-all \
-o Test-0.1.gir
Test-0.1.typelib: Test-0.1.gir
g-ir-compiler Test-0.1.gir -l libtest.so -o Test-0.1.typelib
clean:
rm -f Test-0.1.gir Test-0.1.typelib *.so *.o
#include <glib.h>
#include <gtk/gtk.h>
#include "test.h"
/**
* test_label_new:
* @str: (allow-none): The text of the label
*
* Creates a new label with the given text inside it. You can
* pass %NULL to get an empty label widget.
*
* Returns: (transfer floating): the new #GtkLabel
**/
GtkWidget*
test_label_new (const gchar *str)
{
return gtk_label_new(str);
}
#include <glib.h>
#include <gtk/gtk.h>
GtkWidget* test_label_new (const gchar *str);
import gi
from gi.repository import Test
import gtk
if __name__ == "__main__":
win = gtk.Window()
# this works:
# l = gtk.Label("Test Label")
# this doesn't (test_label_new() is just a wrapper for gtk_label_new()))
l = Test.label_new("Test Label")
win.add(l)
win.show_all()
win.connect("destroy", gtk.main_quit)
gtk.main()
_______________________________________________
python-hackers-list mailing list
python-hackers-list@gnome.org
https://mail.gnome.org/mailman/listinfo/python-hackers-list