[gedit/libgpe: 8/18] Update python bindings to work with libgpe.



commit d2ee6028c03dc59cde6acdc3dab3e471a4040d79
Author: Steve Frécinaux <code istique net>
Date:   Sun Nov 1 19:36:23 2009 +0100

    Update python bindings to work with libgpe.

 bindings/python/Makefile.am          |   21 ++--
 bindings/python/gedit.defs           |   73 +------------
 bindings/python/gedit.override       |    3 -
 bindings/python/geditmodule.c        |  205 ++++++++++++++++++++++++++++++++++
 bindings/python/geditplugin.override |  193 --------------------------------
 5 files changed, 219 insertions(+), 276 deletions(-)
---
diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am
index 3903d8e..3de60ca 100644
--- a/bindings/python/Makefile.am
+++ b/bindings/python/Makefile.am
@@ -1,17 +1,23 @@
 ## Process this file with automake to produce Makefile.in
 
-noinst_LTLIBRARIES = \
+pymoduledir = $(libdir)/gedit-2/python
+pymodule_LTLIBRARIES = \
 	gedit.la
 
+gedit_la_SOURCES =		\
+	geditmodule.c
+
 nodist_gedit_la_SOURCES = 	\
 	gedit.c			\
 	geditutils.c		\
 	geditcommands.c
 
 gedit_la_LDFLAGS = \
-	-module -avoid-version
+	-module -avoid-version	\
+	-export-symbol-regex initgedit
 
 gedit_la_LIBADD = \
+	$(top_builddir)/gedit/libgedit-2.20.la	\
 	$(PYTHON_LIB_LOC)       \
 	$(PYTHON_LIBS)		\
 	$(PYTHON_EXTRA_LIBS)	\
@@ -33,8 +39,8 @@ gedit_la_CFLAGS = \
 $(top_builddir)/gedit/gedit-enum-types.h:
 	cd $(top_builddir)/gedit && $(MAKE) gedit-enum-types.h
 
-gedit.c: gedit.defs gedit.override geditplugin.override geditmessage.override $(top_builddir)/gedit/gedit-enum-types.h
-	( cd $(srcdir) && $(PYGTK_CODEGEN) \
+gedit.c: gedit.defs gedit.override geditmessage.override $(top_builddir)/gedit/gedit-enum-types.h
+	$(AM_V_GEN) ( cd $(srcdir) && $(PYGTK_CODEGEN) \
 		--register $(PYGTK_DEFSDIR)/pango-types.defs \
 		--register $(PYGTK_DEFSDIR)/gdk-types.defs \
 		--register $(PYGTK_DEFSDIR)/gtk-types.defs \
@@ -43,12 +49,12 @@ gedit.c: gedit.defs gedit.override geditplugin.override geditmessage.override $(
 		--prefix py$* $(<F) ) > $@ 
 
 geditutils.c: geditutils.defs geditutils.override
-	( cd $(srcdir) && $(PYGTK_CODEGEN) \
+	$(AM_V_GEN) ( cd $(srcdir) && $(PYGTK_CODEGEN) \
 		--override $*.override \
 		--prefix py$* $(<F) ) > $@ 
 
 geditcommands.c: geditcommands.defs geditcommands.override gedit.defs
-	( cd $(srcdir) && $(PYGTK_CODEGEN) \
+	$(AM_V_GEN) ( cd $(srcdir) && $(PYGTK_CODEGEN) \
 		--register gedit.defs \
 		--register $(PYGTK_DEFSDIR)/gtk-types.defs \
 		--override $*.override \
@@ -103,8 +109,7 @@ EXTRA_DIST = \
 	geditutils.defs		\
 	geditcommands.override 	\
 	geditcommands.defs	\
-	geditmessage.override	\
-	geditplugin.override
+	geditmessage.override
 
 CLEANFILES = $(BUILT_SOURCES)
 
diff --git a/bindings/python/gedit.defs b/bindings/python/gedit.defs
index 17a8450..7811bac 100644
--- a/bindings/python/gedit.defs
+++ b/bindings/python/gedit.defs
@@ -35,20 +35,13 @@
   (gtype-id "GEDIT_TYPE_PANEL")
 )
 
-(define-object __Plugin
+(define-object Plugin
   (in-module "Gedit")
   (parent "GObject")
   (c-name "GeditPlugin")
   (gtype-id "GEDIT_TYPE_PLUGIN")
 )
 
-(define-object Plugin
-  (in-module "Gedit")
-  (parent "GeditPlugin")
-  (c-name "GeditPluginPython")
-  (gtype-id "GEDIT_TYPE_PLUGIN_PYTHON")
-)
-
 (define-object Statusbar
   (in-module "Gedit")
   (parent "GtkStatusbar")
@@ -660,70 +653,6 @@
   (return-type "GType")
 )
 
-(define-method get_install_dir
-  (of-object "GeditPlugin")
-  (c-name "gedit_plugin_get_install_dir")
-  (return-type "gchar*")
-)
-
-(define-method get_data_dir
-  (of-object "GeditPlugin")
-  (c-name "gedit_plugin_get_data_dir")
-  (return-type "gchar*")
-)
-
-(define-method activate
-  (of-object "GeditPlugin")
-  (c-name "gedit_plugin_activate")
-  (return-type "none")
-  (parameters
-    '("GeditWindow*" "window")
-  )
-)
-
-(define-method deactivate
-  (of-object "GeditPlugin")
-  (c-name "gedit_plugin_deactivate")
-  (return-type "none")
-  (parameters
-    '("GeditWindow*" "window")
-  )
-)
-
-(define-method update_ui
-  (of-object "GeditPlugin")
-  (c-name "gedit_plugin_update_ui")
-  (return-type "none")
-  (parameters
-    '("GeditWindow*" "window")
-  )
-)
-
-(define-method is_configurable
-  (of-object "GeditPlugin")
-  (c-name "gedit_plugin_is_configurable")
-  (return-type "gboolean")
-)
-
-(define-method create_configure_dialog
-  (of-object "GeditPlugin")
-  (c-name "gedit_plugin_create_configure_dialog")
-  (return-type "GtkWidget*")
-)
-
-;; From ../gedit/gedit-plugin-python.h
-
-(define-function gedit_plugin_python_get_type
-  (c-name "gedit_plugin_python_get_type")
-  (return-type "GType")
-)
-
-(define-function gedit_plugin_python_new
-  (c-name "gedit_plugin_python_new")
-  (is-constructor-of "GeditPluginPython")
-  (return-type "GeditPluginPython*")
-)
-
 ;; From ../../gedit/gedit-status-bar.h
 
 (define-method flash_message
diff --git a/bindings/python/gedit.override b/bindings/python/gedit.override
index afc67ca..a1a6d7b 100644
--- a/bindings/python/gedit.override
+++ b/bindings/python/gedit.override
@@ -12,8 +12,6 @@ headers
 #include <gedit/gedit-debug.h>
 #include <gedit/gedit-help.h>
 
-#include "gedit-plugin-python.h"
-
 void pygedit_register_classes (PyObject *d); 
 void pygedit_add_constants (PyObject *module, const gchar *strip_prefix);
 
@@ -62,7 +60,6 @@ _helper_wrap_gobject_gslist (const GSList *list)
 }
 %%
 include
-  geditplugin.override
   geditmessage.override
 %%
 modulename gedit 
diff --git a/bindings/python/geditmodule.c b/bindings/python/geditmodule.c
new file mode 100644
index 0000000..8a04ca8
--- /dev/null
+++ b/bindings/python/geditmodule.c
@@ -0,0 +1,205 @@
+/*
+ * geditmodule.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2009 - Steve Frécinaux
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#include <Python.h>
+#include <pyglib.h>
+#include <pygobject.h>
+#include <pygtk/pygtk.h>
+
+#include "config.h"
+
+/* Exported by pygedit module */
+void pygedit_register_classes (PyObject *d);
+void pygedit_add_constants (PyObject *module, const gchar *strip_prefix);
+extern PyMethodDef pygedit_functions[];
+
+/* Exported by pygeditutils module */
+void pygeditutils_register_classes (PyObject *d);
+extern PyMethodDef pygeditutils_functions[];
+
+/* Exported by pygeditcommands module */
+void pygeditcommands_register_classes (PyObject *d);
+extern PyMethodDef pygeditcommands_functions[];
+
+static gboolean
+init_pygtk_check (int major, int minor, int micro)
+{
+	PyObject *gtk, *mdict, *version, *required_version;
+
+	init_pygtk ();
+
+	gtk = PyImport_ImportModule ("gtk");
+	mdict = PyModule_GetDict (gtk);
+	version = PyDict_GetItemString (mdict, "pygtk_version");
+	if (!version)
+	{
+		PyErr_SetString (PyExc_ImportError,
+				 "PyGObject version too old");
+		return FALSE;
+	}
+
+	required_version = Py_BuildValue ("(iii)", major, minor, micro);
+
+	if (PyObject_Compare (version, required_version) == -1)
+	{
+		PyErr_SetString (PyExc_ImportError,
+				 "PyGObject version too old");
+		Py_DECREF (required_version);
+		return FALSE;
+	}
+
+	Py_DECREF (required_version);
+	return TRUE;
+}
+
+static void
+old_gtksourceview_init (void)
+{
+	PyErr_SetString (PyExc_ImportError,
+			 "gtksourceview module not allowed, use gtksourceview2");
+}
+
+static gboolean
+init_pygtksourceview (int major, int minor, int micro)
+{
+	PyObject *gtksourceview, *mdict, *version, *required_version;
+
+	gtksourceview = PyImport_ImportModule ("gtksourceview2");
+	if (gtksourceview == NULL)
+	{
+		PyErr_SetString (PyExc_ImportError,
+				 "could not import gtksourceview");
+		return FALSE;
+	}
+
+	mdict = PyModule_GetDict (gtksourceview);
+	version = PyDict_GetItemString (mdict, "pygtksourceview2_version");
+	if (!version)
+	{
+		PyErr_SetString (PyExc_ImportError,
+				 "PyGtkSourceView version too old");
+		return FALSE;
+	}
+
+	required_version = Py_BuildValue ("(iii)", major, minor, micro);
+
+	if (PyObject_Compare (version, required_version) == -1)
+	{
+		PyErr_SetString (PyExc_ImportError,
+				 "PyGtkSourceView version too old");
+		Py_DECREF (required_version);
+		return FALSE;
+	}
+
+	Py_DECREF (required_version);
+
+	/* Create a dummy 'gtksourceview' module to prevent
+	 * loading of the old 'gtksourceview' modules that
+	 * has conflicting symbols with the gtksourceview2 module.
+	 * Raise an exception when trying to import it.
+	 */
+	PyImport_AppendInittab ("gtksourceview", old_gtksourceview_init);
+
+	return TRUE;
+}
+
+static gboolean
+init_pylibgpe (int major, int minor, int micro)
+{
+	PyObject *libgpe, *mdict, *version, *required_version;
+
+	libgpe = PyImport_ImportModule ("libgpe");
+	if (libgpe == NULL)
+	{
+		PyErr_SetString (PyExc_ImportError,
+				 "could not import libgpe");
+		return FALSE;
+	}
+
+	mdict = PyModule_GetDict (libgpe);
+	version = PyDict_GetItemString (mdict, "version");
+	required_version = Py_BuildValue ("(iii)", major, minor, micro);
+
+	if (PyObject_Compare (version, required_version) == -1)
+	{
+		PyErr_SetString (PyExc_ImportError,
+				 "libgpe version too old");
+		Py_DECREF (required_version);
+		return FALSE;
+	}
+
+	Py_DECREF (required_version);
+
+	return TRUE;
+}
+
+static gboolean
+init_pygedit (void)
+{
+	PyObject *gedit, *geditutils, *geditcommands;
+	PyObject *mdict, *mdict2, *tuple;
+
+	/* import gedit */
+	gedit = Py_InitModule ("gedit", pygedit_functions);
+	mdict = PyModule_GetDict (gedit);
+	pygedit_register_classes (mdict);
+	pygedit_add_constants (gedit, "GEDIT_");
+
+	/* Set version */
+	tuple = Py_BuildValue ("(iii)",
+			       GEDIT_MAJOR_VERSION,
+			       GEDIT_MINOR_VERSION,
+			       GEDIT_MICRO_VERSION);
+	PyDict_SetItemString (mdict, "version", tuple);
+	Py_DECREF (tuple);
+
+	/* import gedit.utils */
+	geditutils = Py_InitModule ("gedit.utils", pygeditutils_functions);
+	mdict2 = PyModule_GetDict (geditutils);
+	pygeditutils_register_classes (mdict2);
+
+	PyDict_SetItemString (mdict, "utils", geditutils);
+
+	/* import gedit.commands */
+	geditcommands = Py_InitModule ("gedit.commands", pygeditcommands_functions);
+	mdict2 = PyModule_GetDict (geditcommands);
+	pygeditutils_register_classes (geditcommands);
+
+	PyDict_SetItemString (mdict, "commands", geditcommands);
+}
+
+DL_EXPORT(void)
+initgedit (void)
+{
+	init_pygobject_check (2, 11, 5);
+
+	if (!init_pygtk_check (2, 4, 0))
+		return;
+
+	if (!init_pygtksourceview (0, 8, 0))
+		return;
+
+	if (!init_pylibgpe (2, 28, 0))
+		return;
+
+	init_pygedit ();
+}



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