[rhythmbox/gobject-introspection: 6/34] remove pygtk and static bindings, load gi at runtime
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox/gobject-introspection: 6/34] remove pygtk and static bindings, load gi at runtime
- Date: Wed, 14 Jul 2010 05:56:35 +0000 (UTC)
commit 6ab772050572a08e338511e439d542358efdf4ac
Author: Jonathan Matthew <jonathan d14n org>
Date: Thu Jul 8 14:14:44 2010 +1000
remove pygtk and static bindings, load gi at runtime
bindings/Makefile.am | 4 --
configure.ac | 20 ++-----
shell/Makefile.am | 16 +++---
shell/main.c | 1 -
shell/rb-python-module.c | 132 ++++++++++------------------------------------
shell/rb-python-plugin.c | 39 +++++++-------
6 files changed, 63 insertions(+), 149 deletions(-)
---
diff --git a/bindings/Makefile.am b/bindings/Makefile.am
index 322fb92..da5fc80 100644
--- a/bindings/Makefile.am
+++ b/bindings/Makefile.am
@@ -1,9 +1,5 @@
SUBDIRS =
-if ENABLE_PYTHON
-SUBDIRS += python
-endif
-
if ENABLE_VALA
SUBDIRS += vala
endif
diff --git a/configure.ac b/configure.ac
index c207827..24ace4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -679,34 +679,27 @@ if test "x$have_python" != "xno"; then
AC_SUBST([PYTHON_CFLAGS])
AC_SUBST([PYTHON_EXTRA_LIBS])
- PYGTK_REQUIRED=2.8.0
GST_PYTHON_REQUIRED=0.10.1
-
- PKG_CHECK_MODULES([PYGTK], [
- pygtk-2.0 >= $PYGTK_REQUIRED] \
+ PKG_CHECK_MODULES([PYGOBJECT], [
gst-python-0.10 >= $GST_PYTHON_REQUIRED
- pygobject-2.0 >= $PYGOBJECT_REQUIRED,
+ pygobject-2.0 >= $PYGOBJECT_REQUIRED],
[],
[
have_python=no
if test "x$enable_python" = "xyes"; then
- AC_MSG_ERROR([$PYGTK_PKG_ERRORS])
+ AC_MSG_ERROR([$PYGOBJECT_PKG_ERRORS])
elif test "x$enable_python" = "xautodetect"; then
enable_python=no
- AC_MSG_WARN([$PYGTK_PKG_ERRORS])
+ AC_MSG_WARN([$PYGOBJECT_PKG_ERRORS])
AC_MSG_WARN([Disabling python support])
fi
])
- AC_SUBST([PYGTK_CFLAGS])
- AC_SUBST([PYGTK_LIBS])
+ AC_SUBST([PYGOBJECT_CFLAGS])
+ AC_SUBST([PYGOBJECT_LIBS])
fi
if test "x$have_python" != "xno"; then
- AC_MSG_CHECKING([for pygtk defs])
- PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0`
- AC_MSG_RESULT([$PYGTK_DEFSDIR])
-
AC_MSG_CHECKING([for gst-python defs])
GST_PYTHON_DEFSDIR=`$PKG_CONFIG --variable=defsdir gst-python-0.10`
AC_MSG_RESULT([$GST_PYTHON_DEFSDIR])
@@ -719,7 +712,6 @@ if test "x$have_python" != "xno"; then
PYGOBJECT_H2DEF="$PYTHON `$PKG_CONFIG --variable=codegendir pygobject-2.0`/h2def.py"
AC_MSG_RESULT([$PYGOBJECT_H2DEF])
- AC_SUBST([PYGTK_DEFSDIR])
AC_SUBST([GST_PYTHON_DEFSDIR])
AC_SUBST([PYGOBJECT_CODEGEN])
AC_SUBST([PYGOBJECT_H2DEF])
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 6a0aa81..86afe13 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -139,9 +139,9 @@ librhythmbox_core_la_SOURCES += \
rb-python-plugin.h \
rb-python-plugin.c
-INCLUDES += $(PYGTK_CFLAGS) $(PYTHON_CFLAGS)
+INCLUDES += $(PYGOBJECT_CFLAGS) $(PYTHON_CFLAGS)
-librhythmbox_core_la_LIBADD += $(PYTHON_LIBS) $(top_builddir)/bindings/python/rb.la
+librhythmbox_core_la_LIBADD += $(PYTHON_LIBS)
endif
rb-shell-glue.h: rb-shell.xml Makefile
@@ -282,12 +282,12 @@ introspection_sources = \
widgets/rb-uri-dialog.h \
widgets/rb-uri-dialog.c
-Rhythmbox-0.12.gir: librhythmbox-core.la
-Rhythmbox_0_12_gir_INCLUDES = GObject-2.0 Gio-2.0 Gtk-2.0 Gst-0.10 libxml2-2.0
-Rhythmbox_0_12_gir_CFLAGS = $(RHYTHMBOX_CFLAGS_NOWARN) $(TOTEM_PLPARSER_CFLAGS) $(DBUS_CFLAGS) $(GUDEV_CFLAGS) -I..
-Rhythmbox_0_12_gir_LIBS = librhythmbox-core.la
-Rhythmbox_0_12_gir_FILES = $(addprefix $(top_srcdir)/,$(introspection_sources))
-INTROSPECTION_GIRS += Rhythmbox-0.12.gir
+Rhythmbox-0.13.gir: librhythmbox-core.la
+Rhythmbox_0_13_gir_INCLUDES = GObject-2.0 Gio-2.0 Gtk-2.0 Gst-0.10 libxml2-2.0
+Rhythmbox_0_13_gir_CFLAGS = $(RHYTHMBOX_CFLAGS_NOWARN) $(TOTEM_PLPARSER_CFLAGS) $(DBUS_CFLAGS) $(GUDEV_CFLAGS) -I..
+Rhythmbox_0_13_gir_LIBS = librhythmbox-core.la
+Rhythmbox_0_13_gir_FILES = $(addprefix $(top_srcdir)/,$(introspection_sources))
+INTROSPECTION_GIRS += Rhythmbox-0.13.gir
girdir = $(datadir)/gir-1.0
dist_gir_DATA = $(INTROSPECTION_GIRS)
diff --git a/shell/main.c b/shell/main.c
index 215141d..595fc50 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -33,7 +33,6 @@
/* pyconfig.h usually defines _XOPEN_SOURCE */
#undef _XOPEN_SOURCE
#define NO_IMPORT_PYGOBJECT
-#define NO_IMPORT_PYGTK
#include <pygobject.h>
#include "rb-python-module.h"
diff --git a/shell/rb-python-module.c b/shell/rb-python-module.c
index 1995a42..1349d5c 100644
--- a/shell/rb-python-module.c
+++ b/shell/rb-python-module.c
@@ -35,7 +35,6 @@
#endif
#include <pygobject.h>
-#include <pygtk/pygtk.h>
#include <signal.h>
@@ -71,36 +70,19 @@ enum
PROP_MODULE
};
-/* Exported by pyrhythmdb module */
-void pyrhythmdb_register_classes (PyObject *d);
-void pyrhythmdb_add_constants (PyObject *module, const gchar *strip_prefix);
-extern PyMethodDef pyrhythmdb_functions[];
-
-/* Exported by pyrb module */
-void pyrb_register_classes (PyObject *d);
-void pyrb_add_constants (PyObject *module, const gchar *strip_prefix);
-extern PyMethodDef pyrb_functions[];
-
-/* We retreive this to check for correct class hierarchy */
-static PyTypeObject *PyRBPlugin_Type;
-
static gboolean python_init_successful;
G_DEFINE_TYPE (RBPythonModule, rb_python_module, G_TYPE_TYPE_MODULE);
-static void
-actually_init_pygtk (void)
-{
- init_pygtk ();
-}
-
void
rb_python_module_init_python (void)
{
- PyObject *pygtk, *mdict, *require;
- PyObject *rb, *rhythmdb, *gtk, *pygtk_version, *pygtk_required_version;
+ PyObject *mdict;
PyObject *gettext, *install, *gettext_args;
PyObject *sys_path;
+ PyObject *pygtk;
+ PyObject *require;
+ PyObject *gi;
struct sigaction old_sigint;
gint res;
char *argv[] = { "rb", "rhythmdb", NULL };
@@ -166,48 +148,8 @@ rb_python_module_init_python (void)
/* disable pyg* log hooks, since ours is more interesting */
pyg_disable_warning_redirections ();
- /* import gtk */
- actually_init_pygtk ();
- if (PyErr_Occurred ()) {
- g_warning ("Could not initialize pygtk");
- PyErr_Print();
- return;
- }
-
pyg_enable_threads ();
- gtk = PyImport_ImportModule ("gtk");
- if (gtk == NULL) {
- g_warning ("Could not import gtk");
- PyErr_Print();
- return;
- }
-
- mdict = PyModule_GetDict (gtk);
- pygtk_version = PyDict_GetItemString (mdict, "pygtk_version");
- pygtk_required_version = Py_BuildValue ("(iii)", 2, 8, 0);
- if (PyObject_Compare (pygtk_version, pygtk_required_version) == -1) {
- g_warning("PyGTK %s required, but %s found.",
- PyString_AsString (PyObject_Repr (pygtk_required_version)),
- PyString_AsString (PyObject_Repr (pygtk_version)));
- Py_DECREF (pygtk_required_version);
- return;
- }
- Py_DECREF (pygtk_required_version);
-
- /* import rhythmdb */
- rhythmdb = Py_InitModule ("rhythmdb", pyrhythmdb_functions);
- mdict = PyModule_GetDict (rhythmdb);
-
- pyrhythmdb_register_classes (mdict);
- if (PyErr_Occurred ()) {
- g_warning ("unable to register rhythmdb classes");
- PyErr_Print();
- return;
- }
-
- pyrhythmdb_add_constants (rhythmdb, "RHYTHMDB_");
-
/* import rb */
paths = rb_get_plugin_paths ();
sys_path = PySys_GetObject ("path");
@@ -223,46 +165,13 @@ rb_python_module_init_python (void)
paths = g_list_delete_link (paths, paths);
}
- rb = PyImport_ImportModule ("rb");
-
- if (rb == NULL) {
- g_warning ("could not import python module 'rb'");
- PyErr_Print ();
- return;
- }
-
- /* add pyrb_functions */
- for (res = 0; pyrb_functions[res].ml_name != NULL; res++) {
- PyObject *func;
-
- func = PyCFunction_New (&pyrb_functions[res], rb);
- if (func == NULL) {
- g_warning ("unable to create object for function '%s'", pyrb_functions[res].ml_name);
- PyErr_Print ();
- return;
- }
- if (PyModule_AddObject (rb, pyrb_functions[res].ml_name, func) < 0) {
- g_warning ("unable to insert function '%s' in 'rb' module", pyrb_functions[res].ml_name);
- PyErr_Print ();
- return;
- }
- }
- mdict = PyModule_GetDict (rb);
-
- pyrb_register_classes (mdict);
- if (PyErr_Occurred ()) {
- g_warning ("unable to register rb classes");
+ /* import gi */
+ gi = PyImport_ImportModule ("gi");
+ if (gi == NULL) {
+ g_warning ("Could not import gi");
PyErr_Print();
return;
}
- pyrb_add_constants (rb, "RB_");
-
- /* Retreive the Python type for rb.Plugin */
- PyRBPlugin_Type = (PyTypeObject *) PyDict_GetItemString (mdict, "Plugin");
- if (PyRBPlugin_Type == NULL) {
- PyErr_Print ();
- return;
- }
/* i18n support */
gettext = PyImport_ImportModule ("gettext");
@@ -287,6 +196,7 @@ rb_python_module_load (GTypeModule *gmodule)
RBPythonModulePrivate *priv = RB_PYTHON_MODULE_GET_PRIVATE (gmodule);
PyObject *main_module, *main_locals, *locals, *key, *value;
PyObject *module, *fromlist;
+ PyObject *pygtype, *pytype;
Py_ssize_t pos = 0;
main_module = PyImport_AddModule ("__main__");
@@ -320,20 +230,34 @@ rb_python_module_load (GTypeModule *gmodule)
return FALSE;
}
+ pygtype = pyg_type_wrapper_new (RB_TYPE_PLUGIN);
+ pytype = PyObject_GetAttrString (pygtype, "pytype");
+ if (pytype == NULL) {
+ g_warning ("Unable to create python wrapper type for RBPlugin");
+ return FALSE;
+ }
+
locals = PyModule_GetDict (module);
while (PyDict_Next (locals, &pos, &key, &value))
{
if (!PyType_Check(value))
continue;
- if (PyObject_IsSubclass (value, (PyObject*) PyRBPlugin_Type))
- {
+ switch (PyObject_IsSubclass (value, pytype)) {
+ case 1:
priv->type = rb_python_object_get_type (gmodule, value);
+ Py_DECREF (pygtype);
return TRUE;
+ case 0:
+ continue;
+ case -1:
+ PyErr_Print ();
+ continue;
}
}
- rb_debug ("failed to find any rb.Plugin-derived classes in python plugin");
+ rb_debug ("failed to find any RBPlugin-derived classes in python plugin");
+ Py_DECREF (pygtype);
return FALSE;
}
@@ -372,8 +296,10 @@ rb_python_module_new_object (RBPythonModule *module)
RBPythonObject *object;
PyGILState_STATE state;
- if (priv->type == 0)
+ if (priv->type == 0) {
+ g_warning ("Can't create an instance, we don't have a type");
return NULL;
+ }
state = pyg_gil_state_ensure ();
rb_debug ("Creating object of type %s", g_type_name (priv->type));
diff --git a/shell/rb-python-plugin.c b/shell/rb-python-plugin.c
index 3217c44..b8f5c53 100644
--- a/shell/rb-python-plugin.c
+++ b/shell/rb-python-plugin.c
@@ -73,28 +73,29 @@ call_python_method (RBPythonObject *object,
static gboolean
check_py_object_is_gtk_widget (PyObject *py_obj)
{
- static PyTypeObject *_PyGtkWidget_Type = NULL;
-
- if (_PyGtkWidget_Type == NULL)
- {
- PyObject *module;
-
- if ((module = PyImport_ImportModule ("gtk")))
- {
- PyObject *moddict = PyModule_GetDict (module);
- _PyGtkWidget_Type = (PyTypeObject *) PyDict_GetItemString (moddict, "Widget");
- }
-
- if (_PyGtkWidget_Type == NULL)
- {
- PyErr_SetString(PyExc_TypeError, "could not find python gtk widget type");
- PyErr_Print();
+ PyObject *pygtype, *pytype;
+ gboolean ret;
+
+ pygtype = pyg_type_wrapper_new (GTK_TYPE_WIDGET);
+ pytype = PyObject_GetAttrString (pygtype, "pytype");
+ if (pytype == NULL) {
+ g_warning ("Unable to create python wrapper type for GtkWidget");
+ return FALSE;
+ }
- return FALSE;
- }
+ ret = FALSE;
+ switch (PyObject_IsSubclass (py_obj, pytype)) {
+ case 1:
+ ret = TRUE;
+ break;
+ case -1:
+ PyErr_Print ();
+ case 0:
+ break;
}
- return PyObject_TypeCheck (py_obj, _PyGtkWidget_Type) ? TRUE : FALSE;
+ Py_DECREF (pygtype);
+ return ret;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]