[glade] Migrate from PyGTK to PyGObject introspection-based bindings



commit 69f0d525632625d15756d7e814a4bafd3c23bb7a
Author: Craig Keogh <cskeogh adam com au>
Date:   Wed Mar 2 19:49:19 2011 -0300

    Migrate from PyGTK to PyGObject introspection-based bindings

 configure.ac                  |   25 +++++++++++++++----------
 doc/gladepython.sgml          |   16 +++++++---------
 plugins/python/Makefile.am    |   16 ++++++++--------
 plugins/python/glade-python.c |   31 ++++++++++++++++++++-----------
 4 files changed, 50 insertions(+), 38 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 90de52e..6c7387a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,19 +144,27 @@ AM_CONDITIONAL(HAVE_GTK_UNIX_PRINT, test x"$have_unix_print" = "xyes")
 dnl ================================================================
 dnl Python for optional python dev libs
 dnl ================================================================
+PYGOBJECT_REQS=2.27.0
+PYGOBJECT_REQUIRED_MAJOR=2
+PYGOBJECT_REQUIRED_MINOR=27
+PYGOBJECT_REQUIRED_MICRO=0
+
 AC_ARG_ENABLE(python,
     AS_HELP_STRING([--disable-python], [disable python catalog]),
     check_python=$enableval, check_python=yes)
 
 if test x"$check_python" = x"yes"; then
-  PYGTK_REQUIRED_MAJOR=2
-  PYGTK_REQUIRED_MINOR=10
-  PYGTK_REQUIRED_MICRO=0
-  PKG_CHECK_MODULES(PYGTK, [pygtk-2.0 >= 2.10.0], [have_python=yes],[have_python=no])
+  have_python=yes
+
+  PKG_CHECK_MODULES([PYGOBJECT],[pygobject-2.0 >= ${PYGOBJECT_REQUIRED_MAJOR}.${PYGOBJECT_REQUIRED_MINOR}.${PYGOBJECT_REQUIRED_MICRO}],[have_pygobject=yes],[have_pygobject=no])
 
   AM_CHECK_PYTHON_HEADERS(, [have_python_headers=no])
   AM_CHECK_PYTHON_LIBS(, [have_python_lib=no])
 
+  if test x"$have_pygobject" = x"no"; then
+    have_python=no
+  fi
+
   if test x"$have_python_headers" = x"no"; then
     have_python=no
   fi
@@ -165,13 +173,10 @@ if test x"$check_python" = x"yes"; then
     have_python=no
   fi
 
+  AC_DEFINE_UNQUOTED(PYGOBJECT_REQUIRED_MAJOR, $PYGOBJECT_REQUIRED_MAJOR, pygobject major version required)
+  AC_DEFINE_UNQUOTED(PYGOBJECT_REQUIRED_MINOR, $PYGOBJECT_REQUIRED_MINOR, pygobject minor version required)
+  AC_DEFINE_UNQUOTED(PYGOBJECT_REQUIRED_MICRO, $PYGOBJECT_REQUIRED_MICRO, pygobject micro version required)
 
-  AC_DEFINE_UNQUOTED(PYGTK_REQUIRED_MAJOR, $PYGTK_REQUIRED_MAJOR, Pygtk mayor version required)
-  AC_DEFINE_UNQUOTED(PYGTK_REQUIRED_MINOR, $PYGTK_REQUIRED_MINOR, Pygtk minor version required)
-  AC_DEFINE_UNQUOTED(PYGTK_REQUIRED_MICRO, $PYGTK_REQUIRED_MICRO, Pygtk micro version required)
-
-  AC_SUBST(PYGTK_LIBS)
-  AC_SUBST(PYGTK_CFLAGS)
 else
   have_python=no
 fi
diff --git a/doc/gladepython.sgml b/doc/gladepython.sgml
index c5dcb63..327d13d 100644
--- a/doc/gladepython.sgml
+++ b/doc/gladepython.sgml
@@ -1,4 +1,4 @@
-<refentry id="pythonsupport" revision="7 Nov 2008">
+<refentry id="pythonsupport" revision="26 Feb 2011">
  <refmeta>
    <refentrytitle>Python Gtk widgets support</refentrytitle>
    <refmiscinfo>Glade UI</refmiscinfo>
@@ -12,10 +12,9 @@ How to write and install a catalog for a python widget library
 
  <refsect1>
    <title>Introduction</title>
+   <para>
 Glade supports loading widgets coded in python by linking and running the python
 interpreter from the gladepython catalog plugin.
-   <para>
-
    </para>
 
    <para>
@@ -55,9 +54,9 @@ domain="glade-3" depends="gtk+">
    <para>
 Glade's python interpreter will look up for your widgets in the same
 places it looks
-for regular catalogs plugins, that is $GLADE_ENV_CATALOG_PATH
+for regular catalogs plugins, that is $GLADE_ENV_MODULE_PATH
 enviroment variable
-and `pkg-config --variable=catalogdir gladeui-1.0`
+and `pkg-config --variable=moduledir gladeui-2.0`
 
 So the easiest thing would be to make a symlink in one of those directory, just
 do not forget that the name should be the one specified in your catalog name.
@@ -67,14 +66,13 @@ do not forget that the name should be the one specified in your catalog name.
 pythonplugin.py
      <programlisting>
 <![CDATA[
-import gobject
-import gtk
+from gi.repository import Gtk
 
-class MyBox(gtk.HBox):
+class MyBox(Gtk.HBox):
        __gtype_name__ = 'MyBox'
 
        def __init__(self):
-               gtk.HBox.__init__(self)
+               Gtk.HBox.__init__(self)
 ]]>
      </programlisting>
    </para>
diff --git a/plugins/python/Makefile.am b/plugins/python/Makefile.am
index 8abc73a..3e6456f 100644
--- a/plugins/python/Makefile.am
+++ b/plugins/python/Makefile.am
@@ -11,16 +11,16 @@ gladepythondir = $(pkglibdir)/modules
 libgladepython_la_SOURCES = glade-python.c
 libgladepython_la_CPPFLAGS = $(AM_CPPFLAGS)
 libgladepython_la_CFLAGS = \
-        -DG_LOG_DOMAIN=\"GladeUI-PYTHON\" \
-	-I$(top_srcdir)                  \
-	-I$(top_builddir)                \
-	$(PYTHON_INCLUDES)      \
-	$(PYGTK_CFLAGS)            \
-	$(GTK_CFLAGS)                    \
-	$(PLUGINS_WARN_CFLAGS)           \
+	-DG_LOG_DOMAIN=\"GladeUI-PYTHON\" \
+	-I$(top_srcdir)                   \
+	-I$(top_builddir)                 \
+	$(PYTHON_INCLUDES)                \
+	$(GTK_CFLAGS)                     \
+	$(PYGOBJECT_CFLAGS)               \
+	$(PLUGINS_WARN_CFLAGS)            \
 	$(AM_CPPFLAGS)
 libgladepython_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS)
-libgladepython_la_LIBADD = $(libgladeui) $(PYTHON_LIBS)
+libgladepython_la_LIBADD = $(libgladeui) $(PYTHON_LIBS) $(PYGOBJECT_LIBS)
 
 if PLATFORM_WIN32
 libgladepython_la_LDFLAGS += -no-undefined
diff --git a/plugins/python/glade-python.c b/plugins/python/glade-python.c
index d746730..a5a3456 100644
--- a/plugins/python/glade-python.c
+++ b/plugins/python/glade-python.c
@@ -30,7 +30,7 @@ static void
 python_init (void)
 {
   char *argv[1];
-
+  
   if (Py_IsInitialized ())
     return;
 
@@ -42,7 +42,7 @@ python_init (void)
 }
 
 static void
-glade_python_init_pygtk_check (gint req_major, gint req_minor, gint req_micro)
+glade_python_init_pygobject_check (gint req_major, gint req_minor, gint req_micro)
 {
   PyObject *gobject, *mdict, *version;
   int found_major, found_minor, found_micro;
@@ -51,7 +51,7 @@ glade_python_init_pygtk_check (gint req_major, gint req_minor, gint req_micro)
 
   gobject = PyImport_ImportModule ("gobject");
   mdict = PyModule_GetDict (gobject);
-  version = PyDict_GetItemString (mdict, "pygtk_version");
+  version = PyDict_GetItemString (mdict, "pygobject_version");
   if (!version)
     {
       PyErr_SetString (PyExc_ImportError, "PyGObject version too old");
@@ -75,16 +75,19 @@ static void
 glade_python_setup ()
 {
   gchar *command;
+  const gchar *module_path;
 
   Py_SetProgramName (PACKAGE_NAME);
 
   /* Initialize the Python interpreter */
   python_init ();
 
-  /* Check and init pygobject >= 2.12.0 */
+  /* Check and init pygobject */
+
   PyErr_Clear ();
-  glade_python_init_pygtk_check (PYGTK_REQUIRED_MAJOR, PYGTK_REQUIRED_MINOR,
-                                 PYGTK_REQUIRED_MICRO);
+  glade_python_init_pygobject_check (PYGOBJECT_REQUIRED_MAJOR,
+                                     PYGOBJECT_REQUIRED_MINOR,
+                                     PYGOBJECT_REQUIRED_MICRO);
   if (PyErr_Occurred ())
     {
       PyObject *ptype, *pvalue, *ptraceback;
@@ -92,8 +95,8 @@ glade_python_setup ()
       g_warning ("Unable to load pygobject module >= %d.%d.%d, "
                  "please make sure it is in python's path (sys.path). "
                  "(use PYTHONPATH env variable to specify non default paths)\n%s",
-                 PYGTK_REQUIRED_MAJOR, PYGTK_REQUIRED_MINOR,
-                 PYGTK_REQUIRED_MICRO, PyString_AsString (pvalue));
+                 PYGOBJECT_REQUIRED_MAJOR, PYGOBJECT_REQUIRED_MINOR,
+                 PYGOBJECT_REQUIRED_MICRO, PyString_AsString (pvalue));
       PyErr_Clear ();
       Py_Finalize ();
       return;
@@ -102,9 +105,15 @@ glade_python_setup ()
   pyg_disable_warning_redirections ();
 
   /* Set path */
-  command = g_strdup_printf ("import sys; sys.path+=['.', '%s', '%s'];\n",
-                             g_getenv (GLADE_ENV_CATALOG_PATH),
-                             glade_app_get_modules_dir ());
+  module_path = g_getenv (GLADE_ENV_MODULE_PATH);
+  if (module_path == NULL)
+    command = g_strdup_printf ("import sys; sys.path+=['%s'];\n",
+                               glade_app_get_modules_dir ());
+  else
+    command = g_strdup_printf ("import sys; sys.path+=['%s', '%s'];\n",
+                               module_path,
+                               glade_app_get_modules_dir ());
+
   PyRun_SimpleString (command);
   g_free (command);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]