[rhythmbox] Remove PyGTK code, use g-i instead
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] Remove PyGTK code, use g-i instead
- Date: Fri, 4 Feb 2011 13:11:14 +0000 (UTC)
commit d0f6a75ad659c097e11129c61ec642d8e5bcf9af
Author: Jonathan Matthew <jonathan d14n org>
Date: Wed Feb 2 22:44:01 2011 +1000
Remove PyGTK code, use g-i instead
configure.ac | 20 ++-----
shell/Makefile.am | 4 +-
shell/main.c | 1 -
shell/rb-python-module.c | 147 +++++++++-------------------------------------
shell/rb-python-plugin.c | 39 ++++++------
5 files changed, 55 insertions(+), 156 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 87d511f..8c7dfae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -690,34 +690,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])
@@ -730,7 +723,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 1ef5beb..192f2d9 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
diff --git a/shell/main.c b/shell/main.c
index 1de1c5f..eeb4c76 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..82d4882 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,17 @@ 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 *gi;
struct sigaction old_sigint;
gint res;
char *argv[] = { "rb", "rhythmdb", NULL };
@@ -139,23 +119,6 @@ rb_python_module_init_python (void)
PySys_SetArgv (1, argv);
- /* pygtk.require("2.0") */
- pygtk = PyImport_ImportModule ("pygtk");
- if (pygtk == NULL) {
- g_warning ("Could not import pygtk");
- PyErr_Print();
- return;
- }
-
- mdict = PyModule_GetDict (pygtk);
- require = PyDict_GetItemString (mdict, "require");
- PyObject_CallObject (require, Py_BuildValue ("(S)", PyString_FromString ("2.0")));
- if (PyErr_Occurred ()) {
- g_warning ("pygtk.require(2.0) failed");
- PyErr_Print();
- return;
- }
-
/* import gobject */
if (pygobject_init (2, 16, 0) == NULL) {
g_warning ("Could not initialize pygobject");
@@ -166,48 +129,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 +146,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 +177,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 +211,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 +277,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..a1aa600 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_IsInstance (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]