gedit r6233 - branches/jessevdk-plugins/bindings/python



Author: jessevdk
Date: Sun Apr  6 23:36:42 2008
New Revision: 6233
URL: http://svn.gnome.org/viewvc/gedit?rev=6233&view=rev

Log:
	* bindings/python/Makefile.am:
	* bindings/python/gedit.defs:
	* bindings/python/gedit.override:

	Added bindings for GeditPythonPlugin which are binding to gedit.Plugin
	now (instead of GeditPlugin). GeditPlugin is now bound to gedit.__Plugin
	which should not be used directly. The necessary glue is provided in
	geditplugin.override

	* bindings/python/geditplugin.override: added overrides for the default
	  implementations of the GeditPlugin methods. These methods make sure
	  to chain up to the actual GeditPlugin klass methods (also for 
	  GeditPythonPlugin). This means that the actual default implementations
	  will always be used, unless the method is overloaded in python

	* bindings/python/geditplugins.defs:
	* bindings/python/geditplugins.override:
	
	Added gedit.plugins module which contains bindings for public methods of
	GeditPluginsEngine (gedit.plugins.Engine) and GeditPluginInfo
	(gedit.plugins.PluginInfo). These still need to be refined somewhat and
	also tested.


Added:
   branches/jessevdk-plugins/bindings/python/geditplugin.override
   branches/jessevdk-plugins/bindings/python/geditplugins.defs
   branches/jessevdk-plugins/bindings/python/geditplugins.override
Modified:
   branches/jessevdk-plugins/bindings/python/Makefile.am
   branches/jessevdk-plugins/bindings/python/gedit.defs
   branches/jessevdk-plugins/bindings/python/gedit.override

Modified: branches/jessevdk-plugins/bindings/python/Makefile.am
==============================================================================
--- branches/jessevdk-plugins/bindings/python/Makefile.am	(original)
+++ branches/jessevdk-plugins/bindings/python/Makefile.am	Sun Apr  6 23:36:42 2008
@@ -6,7 +6,8 @@
 nodist_gedit_la_SOURCES = \
 	gedit.c			\
 	geditutils.c	\
-	geditcommands.c
+	geditcommands.c \
+	geditplugins.c
 
 gedit_la_LDFLAGS = \
 	-module -avoid-version
@@ -31,7 +32,7 @@
 $(top_builddir)/gedit/gedit-enum-types.h:
 	cd $(top_builddir)/gedit && $(MAKE) gedit-enum-types.h
 
-gedit.c: gedit.defs gedit.override $(top_builddir)/gedit/gedit-enum-types.h
+gedit.c: gedit.defs gedit.override geditplugin.override $(top_builddir)/gedit/gedit-enum-types.h
 	( cd $(srcdir) && $(PYGTK_CODEGEN) \
 		--register $(PYGTK_DEFSDIR)/pango-types.defs \
 		--register $(PYGTK_DEFSDIR)/gdk-types.defs \
@@ -52,13 +53,20 @@
 		--override $*.override \
 		--prefix py$* $(<F) ) > $@ 
 
+geditplugins.c: geditplugins.defs geditplugins.override
+	( cd $(srcdir) && $(PYGTK_CODEGEN) \
+		--register gedit.defs \
+		--register $(PYGTK_DEFSDIR)/gtk-types.defs \
+		--override $*.override \
+		--prefix py$* $(<F) ) > $@ 
+
 BINDING_GEDIT_HEADERS_SRCDIR_IN = \
 	gedit/gedit-app.h		\
 	gedit/gedit-document.h		\
 	gedit/gedit-encodings.h		\
 	gedit/gedit-plugin.h		\
 	gedit/gedit-view.h		\
-	gedit/gedit-status-bar.h	\
+	gedit/gedit-statusbar.h	\
 	gedit/gedit-tab.h 		\
 	gedit/gedit-panel.h 		\
 	gedit/gedit-window.h 		\
@@ -72,11 +80,16 @@
 BINDING_COMMANDS_HEADERS_SRCDIR_IN = \
 	gedit/gedit-commands.h
 
+BINDING_PLUGINS_HEADERS_SRCDIR_IN = \
+	gedit/gedit-plugins-engine.h \
+	gedit/gedit-plugin-info.h
+	
 BINDING_HEADERS_BUILDDIR_IN = 
 
 BINDING_GEDIT_HEADERS_SRCDIR	:= $(addprefix $(top_srcdir)/,$(BINDING_GEDIT_HEADERS_SRCDIR_IN))
 BINDING_UTILS_HEADERS_SRCDIR	:= $(addprefix $(top_srcdir)/,$(BINDING_UTILS_HEADERS_SRCDIR_IN))
 BINDING_COMMANDS_HEADERS_SRCDIR	:= $(addprefix $(top_srcdir)/,$(BINDING_COMMANDS_HEADERS_SRCDIR_IN))
+BINDING_PLUGINS_HEADERS_SRCDIR	:= $(addprefix $(top_srcdir)/,$(BINDING_PLUGINS_HEADERS_SRCDIR_IN))
 
 BINDING_HEADERS_BUILDDIR	:= $(addprefix $(top_builddir)/,$(BINDING_HEADERS_BUILDDIR_IN))
 
@@ -84,11 +97,12 @@
 	$(PYGTK_H2DEF) $(sort $(BINDING_GEDIT_HEADERS_SRCDIR) $(BINDING_HEADERS_BUILDDIR)) > gedit.defs.new
 	$(PYGTK_H2DEF) $(sort $(BINDING_UTILS_HEADERS_SRCDIR) $(BINDING_HEADERS_BUILDDIR)) > geditutils.defs.new
 	$(PYGTK_H2DEF) $(sort $(BINDING_COMMANDS_HEADERS_SRCDIR) $(BINDING_HEADERS_BUILDDIR)) > geditcommands.defs.new
-
+	$(PYGTK_H2DEF) $(sort $(BINDING_PLUGINS_HEADERS_SRCDIR) $(BINDING_HEADERS_BUILDDIR)) > geditplugins.defs.new
 BUILT_SOURCES = \
 	gedit.c		\
 	geditutils.c	\
-	geditcommands.c
+	geditcommands.c \
+	geditplugins.c
 
 EXTRA_DIST = \
 	gedit.override		\
@@ -96,7 +110,9 @@
 	geditutils.override	\
 	geditutils.defs		\
 	geditcommands.override \
-	geditcommands.defs
+	geditcommands.defs \
+	geditplugins.override \
+	geditplugins.defs
 
 CLEANFILES = $(BUILT_SOURCES)
 

Modified: branches/jessevdk-plugins/bindings/python/gedit.defs
==============================================================================
--- branches/jessevdk-plugins/bindings/python/gedit.defs	(original)
+++ branches/jessevdk-plugins/bindings/python/gedit.defs	Sun Apr  6 23:36:42 2008
@@ -21,13 +21,20 @@
   (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 "GeditPythonPlugin")
+  (gtype-id "GEDIT_TYPE_PYTHON_PLUGIN")
+)
+
 (define-object Statusbar
   (in-module "Gedit")
   (parent "GtkStatusbar")
@@ -655,6 +662,20 @@
   (return-type "GtkWidget*")
 )
 
+;; From ../../gedit/gedit-python-plugin.h
+
+(define-function gedit_python_plugin_get_type
+  (c-name "gedit_python_plugin_get_type")
+  (return-type "GType")
+)
+
+(define-function gedit_python_plugin_new
+  (c-name "gedit_python_plugin_new")
+  (is-constructor-of "GeditPythonPlugin")
+  (return-type "GObject*")
+)
+
+
 ;; From ../../gedit/gedit-status-bar.h
 
 (define-method flash_message

Modified: branches/jessevdk-plugins/bindings/python/gedit.override
==============================================================================
--- branches/jessevdk-plugins/bindings/python/gedit.override	(original)
+++ branches/jessevdk-plugins/bindings/python/gedit.override	Sun Apr  6 23:36:42 2008
@@ -6,6 +6,7 @@
 
 #include "gedit-language-manager.h"
 #include "gedit-plugin.h"
+#include "gedit-python-plugin.h"
 #include "gedit-app.h"
 #include "gedit-encodings.h"
 #include "gedit-enum-types.h"
@@ -59,6 +60,9 @@
     return py_list;
 }
 %%
+include
+  geditplugin.override
+%%
 modulename gedit 
 %%
 import gtk.Widget as PyGtkWidget_Type
@@ -435,3 +439,19 @@
     return Py_None;
 }
 %%
+override gedit_python_plugin_new
+static int
+_wrap_gedit_python_plugin_new(PyGObject *self)
+{
+	pygobject_construct (self, NULL);
+
+	if (!self->obj) {
+		PyErr_SetString (PyExc_RuntimeError, "could not create gedit.Plugin object");
+		return -1;
+	}
+	
+	_gedit_python_plugin_set_instance(GEDIT_PYTHON_PLUGIN(self->obj), (PyObject *)self);
+	return 0;
+}
+%%
+new-constructor GEDIT_TYPE_PYTHON_PLUGIN

Added: branches/jessevdk-plugins/bindings/python/geditplugin.override
==============================================================================
--- (empty file)
+++ branches/jessevdk-plugins/bindings/python/geditplugin.override	Sun Apr  6 23:36:42 2008
@@ -0,0 +1,193 @@
+%%
+headers
+  #include "gedit-plugin.h"
+  #include "gedit-window.h"
+%%
+override gedit_plugin_activate kwargs
+static PyObject *
+_wrap_gedit_plugin_activate(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+	gpointer klass, klass2;
+	static char *kwlist[] = { "window", NULL };
+	PyGObject *window;
+	PyObject *cls = ((PyObject *)self)->ob_type; // FIXME
+	
+	if (!PyArg_ParseTupleAndKeywords (args, 
+					  kwargs,
+					  "O!:GeditPlugin.activate", 
+					  kwlist,
+					  &PyGeditWindow_Type, 
+					  &window))
+		return NULL;
+
+	klass = g_type_class_ref (pyg_type_from_object (cls));
+	
+	if (GEDIT_IS_PYTHON_PLUGIN_CLASS (klass))
+	{
+		klass2 = g_type_class_peek_parent (klass);
+		g_type_class_unref (klass);
+		klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2));
+	}
+
+	if (GEDIT_PLUGIN_CLASS (klass)->activate)
+		GEDIT_PLUGIN_CLASS (klass)->activate (GEDIT_PLUGIN (self->obj), 
+						      GEDIT_WINDOW (window->obj));
+	else {
+		PyErr_SetString (PyExc_NotImplementedError, 
+				 "virtual method GeditPlugin.activate not implemented");
+		g_type_class_unref (klass);
+		return NULL;
+	}
+
+	g_type_class_unref (klass);
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+%%
+override gedit_plugin_deactivate kwargs
+static PyObject *
+_wrap_gedit_plugin_deactivate(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+	gpointer klass, klass2;
+	static char *kwlist[] = {"window", NULL};
+	PyGObject *window;
+	PyObject *cls = ((PyObject *)self)->ob_type;
+
+	if (!PyArg_ParseTupleAndKeywords (args, 
+					  kwargs,
+					  "O!:GeditPlugin.deactivate", 
+					  kwlist,
+					  &PyGeditWindow_Type, 
+					  &window))
+		return NULL;
+
+	klass = g_type_class_ref (pyg_type_from_object (cls));
+
+	if (GEDIT_IS_PYTHON_PLUGIN_CLASS (klass))
+	{
+		klass2 = g_type_class_peek_parent (klass);
+		g_type_class_unref (klass);
+		klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2));
+	}
+	
+	if (GEDIT_PLUGIN_CLASS (klass)->deactivate)
+		GEDIT_PLUGIN_CLASS (klass)->deactivate (GEDIT_PLUGIN (self->obj), 
+							GEDIT_WINDOW (window->obj));
+	else {
+		PyErr_SetString (PyExc_NotImplementedError, 
+				 "virtual method GeditPlugin.deactivate not implemented");
+		g_type_class_unref (klass);
+		return NULL;
+	}
+
+	g_type_class_unref (klass);
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+%%
+override gedit_plugin_update_ui kwargs
+static PyObject *
+_wrap_gedit_plugin_update_ui (PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+	gpointer klass, klass2;
+	static char *kwlist[] = {"window", NULL};
+	PyGObject *window;
+	PyObject *cls = ((PyObject *)self)->ob_type;
+
+	if (!PyArg_ParseTupleAndKeywords (args, 
+					  kwargs,
+					  "O!:GeditPlugin.update_ui", 
+					  kwlist,
+					  &PyGeditWindow_Type, 
+					  &window))
+		return NULL;
+
+	klass = g_type_class_ref (pyg_type_from_object (cls));
+
+	if (GEDIT_IS_PYTHON_PLUGIN_CLASS (klass))
+	{
+		klass2 = g_type_class_peek_parent (klass);
+		g_type_class_unref (klass);
+		klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2));
+	}
+	
+	if (GEDIT_PLUGIN_CLASS (klass)->update_ui)
+		GEDIT_PLUGIN_CLASS (klass)->update_ui (GEDIT_PLUGIN (self->obj), 
+						       GEDIT_WINDOW (window->obj));
+	else {
+		PyErr_SetString (PyExc_NotImplementedError, 
+				 "virtual method GeditPlugin.update_ui not implemented");
+		g_type_class_unref (klass);
+		return NULL;
+	}
+
+	g_type_class_unref (klass);
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+%%
+override gedit_plugin_is_configurable
+static PyObject *
+_wrap_gedit_plugin_is_configurable (PyGObject *self)
+{
+	int ret;
+	gpointer klass, klass2;
+	PyObject *cls = ((PyObject *)self)->ob_type;
+
+	klass = g_type_class_ref (pyg_type_from_object (cls));
+
+	if (GEDIT_IS_PYTHON_PLUGIN_CLASS (klass))
+	{
+		klass2 = g_type_class_peek_parent (klass);
+		g_type_class_unref (klass);
+		klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2));
+	}
+	
+	if (GEDIT_PLUGIN_CLASS (klass)->is_configurable)
+		ret = GEDIT_PLUGIN_CLASS (klass)->is_configurable (GEDIT_PLUGIN (self->obj));
+	else {
+		PyErr_SetString (PyExc_NotImplementedError, 
+				 "virtual method GeditPlugin.is_configurable not implemented");
+		g_type_class_unref (klass);
+		return NULL;
+	}
+
+	g_type_class_unref (klass);
+	return PyBool_FromLong (ret);
+}
+
+%%
+override gedit_plugin_configure_dialog
+static PyObject *
+_wrap_gedit_plugin_create_configure_dialog (PyGObject *self)
+{
+	GtkWidget *ret;
+	gpointer klass, klass2;
+	PyObject *cls = ((PyObject *)self)->ob_type;
+
+	klass = g_type_class_ref(pyg_type_from_object (cls));
+
+	if (GEDIT_IS_PYTHON_PLUGIN_CLASS (klass))
+	{
+		klass2 = g_type_class_peek_parent (klass);
+		g_type_class_unref (klass);
+		klass = g_type_class_ref (G_TYPE_FROM_CLASS (klass2));
+	}
+	
+	if (GEDIT_PLUGIN_CLASS (klass)->create_configure_dialog)
+		ret = GEDIT_PLUGIN_CLASS (klass)->create_configure_dialog (GEDIT_PLUGIN (self->obj));
+	else {
+		PyErr_SetString (PyExc_NotImplementedError, 
+				 "virtual method GeditPlugin.create_configure_dialog not implemented");
+		g_type_class_unref (klass);
+		return NULL;
+	}
+
+	g_type_class_unref (klass);
+
+	/* pygobject_new handles NULL checking */
+	return pygobject_new ((GObject *)ret);
+}

Added: branches/jessevdk-plugins/bindings/python/geditplugins.defs
==============================================================================
--- (empty file)
+++ branches/jessevdk-plugins/bindings/python/geditplugins.defs	Sun Apr  6 23:36:42 2008
@@ -0,0 +1,161 @@
+;; -*- scheme -*-
+
+; object definitions ...
+(define-object Engine
+  (in-module "Gedit")
+  (parent "GObject")
+  (c-name "GeditPluginsEngine")
+  (gtype-id "GEDIT_TYPE_PLUGINS_ENGINE")
+)
+
+(define-boxed PluginInfo
+  (in-module "Gedit")
+  (c-name "GeditPluginInfo")
+  (gtype-id "GEDIT_TYPE_PLUGIN_INFO")
+  (copy-func "gedit_plugin_info_copy")
+  (release-func "gedit_plugin_info_free")
+)
+
+
+;; From gedit-plugin-info.h
+
+(define-function gedit_plugin_info_get_type
+  (c-name "gedit_plugin_info_get_type")
+  (return-type "GType")
+)
+
+(define-method is_active
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_is_active")
+  (return-type "gboolean")
+)
+
+(define-method is_available
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_is_available")
+  (return-type "gboolean")
+)
+
+(define-method is_configurable
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_is_configurable")
+  (return-type "gboolean")
+)
+
+(define-method get_name
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_get_name")
+  (return-type "const-gchar*")
+)
+
+(define-method get_module_name
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_get_module_name")
+  (return-type "const-gchar*")
+)
+
+(define-method get_description
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_get_description")
+  (return-type "const-gchar*")
+)
+
+(define-method get_icon_name
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_get_icon_name")
+  (return-type "const-gchar*")
+)
+
+(define-method get_authors
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_get_authors")
+  (return-type "const-gchar**")
+)
+
+(define-method get_website
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_get_website")
+  (return-type "const-gchar*")
+)
+
+(define-method get_copyright
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_get_copyright")
+  (return-type "const-gchar*")
+)
+
+(define-method get_plugin
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_get_plugin")
+  (return-type "GeditPlugin*")
+)
+
+(define-method copy
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_copy")
+  (return-type "GeditPluginInfo*")
+)
+
+(define-method free
+  (of-object "GeditPluginInfo")
+  (c-name "gedit_plugin_info_free")
+  (return-type "none")
+)
+
+
+;; From gedit-plugins-engine.h
+
+(define-function gedit_plugins_engine_get_type
+  (c-name "gedit_plugins_engine_get_type")
+  (return-type "GType")
+)
+
+(define-function engine_get_default
+  (c-name "gedit_plugins_engine_get_default")
+  (return-type "GeditPluginsEngine*")
+)
+
+(define-method get_plugin_list
+  (of-object "GeditPluginsEngine")
+  (c-name "gedit_plugins_engine_get_plugin_list")
+  (return-type "const-GList*")
+)
+
+(define-method activate_plugin
+  (of-object "GeditPluginsEngine")
+  (c-name "gedit_plugins_engine_activate_plugin")
+  (return-type "gboolean")
+  (parameters
+    '("GeditPluginInfo*" "info")
+  )
+)
+
+(define-method deactivate_plugin
+  (of-object "GeditPluginsEngine")
+  (c-name "gedit_plugins_engine_deactivate_plugin")
+  (return-type "gboolean")
+  (parameters
+    '("GeditPluginInfo*" "info")
+  )
+)
+
+(define-method configure_plugin
+  (of-object "GeditPluginsEngine")
+  (c-name "gedit_plugins_engine_configure_plugin")
+  (return-type "none")
+  (parameters
+    '("GeditPluginInfo*" "info")
+    '("GtkWindow*" "parent")
+  )
+)
+
+(define-method get_plugin
+  (of-object "GeditPluginsEngine")
+  (c-name "gedit_plugins_engine_get_plugin")
+  (return-type "GeditPlugin*")
+  (parameters
+    '("const-gchar*" "name")
+  )
+)
+
+

Added: branches/jessevdk-plugins/bindings/python/geditplugins.override
==============================================================================
--- (empty file)
+++ branches/jessevdk-plugins/bindings/python/geditplugins.override	Sun Apr  6 23:36:42 2008
@@ -0,0 +1,98 @@
+%%
+headers
+#define NO_IMPORT_PYGOBJECT
+#include "pygobject.h"
+#include <pygtk/pygtk.h>
+
+#include "gedit-plugins-engine.h"
+#include "gedit-plugin.h"
+#include "gedit-plugin-info.h"
+
+static PyObject *
+_helper_wrap_string_list (const gchar **list)
+{
+	PyObject *py_list;
+	PyObject *item;
+
+	if ((py_list = PyList_New (0)) == NULL) {
+		return NULL;
+	}
+
+	while (*list) {
+		item = Py_BuildValue ("s", *list);
+		
+		if (item == NULL) {
+			Py_DECREF (py_list);
+			return NULL;
+		}
+		
+		PyList_Append(py_list, item);
+		Py_DECREF(item);
+		++list;
+	}
+	
+	return py_list;
+}
+
+static PyObject *
+_helper_get_plugin_instance (PyObject *pyinfo)
+{
+	/*GeditPluginInfo *info;
+	GeditPlugin *plugin;
+	GeditPythonObject *obj;
+	
+	info = pyg_boxed_get(pyinfo, GeditPluginInfo);
+	plugin = gedit_plugin_info_get_plugin(info);*/
+	
+	/* There are three different cases to take into consideration:
+	   	1. The plugin is an actual GeditPythonPlugin (then the instance
+	   	   of that plugin is the actual python object)
+	   	2. The plugin is a C plugin, with python bindings (wrap the
+	   	   plugin as the python class)
+	   	3. The plugin is a C plugin, but doesn't have any bindings,
+	   	   in which case we return NULL
+	 */
+	 
+	/* Determine if this is a python plugin */
+	/*if (G_TYPE_FROM_INSTANCE(plugin) != GEDIT_TYPE_PLUGIN)
+	{
+		obj = (GeditPythonObject *)plugin;
+		Py_INCREF(obj->instance);
+		
+		return obj->instance;
+	}*/
+	 
+	/* Determine if the plugin has python bindings */
+}
+
+%%
+modulename gedit.plugins
+%%
+import gtk.Window as PyGtkWindow_Type
+import gobject.GObject as PyGObject_Type
+%%
+ignore-glob
+  _*
+  *_get_type
+  gedit_plugins_engine_get_plugin_list
+%%
+override gedit_plugin_info_get_authors
+PyObject *
+_wrap_gedit_plugin_info_get_authors (PyGObject *self)
+{
+    const gchar **list;
+    PyObject *py_list;
+
+    list = gedit_plugin_info_get_authors (GEDIT_PLUGIN_INFO (self->obj));
+
+    py_list = _helper_wrap_string_list (list);
+
+    return py_list;
+}
+%%
+override gedit_plugin_info_get_plugin
+static PyObject *
+_wrap_gedit_plugin_info_get_plugin(PyObject *self)
+{
+	return _helper_get_plugin_instance(self);
+}



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