All pastes #35873 Raw Edit

Untitled

public c v1 · immutable
#35873 ·published 2006-01-05 17:52 UTC
rendered paste body
? plugins/modelines/Makefile.inIndex: gedit/gedit-python-plugin.c===================================================================RCS file: /cvs/gnome/gedit/gedit/gedit-python-plugin.c,vretrieving revision 1.2diff -u -p -r1.2 gedit-python-plugin.c--- gedit/gedit-python-plugin.c	12 Dec 2005 17:27:55 -0000	1.2+++ gedit/gedit-python-plugin.c	5 Jan 2006 17:32:35 -0000@@ -31,7 +31,10 @@  static GObjectClass *parent_class; -static void+static PyTypeObject *_PyGtkWidget_Type;+#define PyGtkWidget_Type (*_PyGtkWidget_Type)++static PyObject * call_python_method (GeditPythonObject *object, 		    GeditWindow       *window, 		    gchar             *method)@@ -42,41 +45,106 @@ call_python_method (GeditPythonObject *o 	if (!PyObject_HasAttrString (object->instance, method)) 	{ 		pyg_gil_state_release (state);-		return;+		return NULL; 	} -	py_ret = PyObject_CallMethod (object->instance,-				      method,-				      "(N)",-				      pygobject_new (G_OBJECT (window)));+	if (window == NULL)+	{+		py_ret = PyObject_CallMethod (object->instance,+					      method,+					      NULL);+	}+	else+	{+		py_ret = PyObject_CallMethod (object->instance,+					      method,+					      "(N)",+					      pygobject_new (G_OBJECT (window)));+	}+	 	if (!py_ret) 		PyErr_Print (); -	Py_XDECREF (py_ret); 	pyg_gil_state_release (state);+	+	return py_ret; }  static void impl_update_ui (GeditPlugin *plugin, 		GeditWindow *window) {-	call_python_method ((GeditPythonObject *) plugin, window, "update_ui");+	PyObject *py_ret = call_python_method ((GeditPythonObject *) plugin, window, "update_ui");+	if (py_ret == NULL)+		G_OBJECT_CLASS (parent_class)->update_ui (plugin, window);+		+	Py_XDECREF (py_ret); }  static void impl_deactivate (GeditPlugin *plugin, 		 GeditWindow *window) {-	call_python_method ((GeditPythonObject *) plugin, window, "deactivate");+	PyObject *py_ret = call_python_method ((GeditPythonObject *) plugin, window, "deactivate");+	if (py_ret == NULL)+		G_OBJECT_CLASS (parent_class)->deactivate (plugin, window);+		+	Py_XDECREF (py_ret); }  static void impl_activate (GeditPlugin *plugin, 	       GeditWindow *window) {-	call_python_method ((GeditPythonObject *) plugin, window, "activate");+	PyObject *py_ret = call_python_method ((GeditPythonObject *) plugin, window, "activate");+	if (py_ret == NULL)+		G_OBJECT_CLASS (parent_class)->activate (plugin, window);+		+	Py_XDECREF (py_ret); } +static GtkWidget *+impl_create_configure_dialog (GeditPlugin *plugin)+{+	GtkWidget *ret;+	PyObject *py_ret = call_python_method ((GeditPythonObject *) plugin, NULL, "create_configure_dialog");+	+	if (py_ret == NULL)+		return G_OBJECT_CLASS (parent_class)->create_configure_dialog (plugin);+	+	/* Check if the type is already known */+	if (_PyGtkWidget_Type == NULL)+	{+		PyObject *module;+    	if ((module = PyImport_ImportModule ("gtk")) != NULL)+    	{+    	    PyObject *moddict = PyModule_GetDict (module);+	+    	    _PyGtkWidget_Type = (PyTypeObject *) PyDict_GetItemString (moddict, "Widget");+    	}+    }+    +    /* Still NULL, we have a problem */+    if (_PyGtkWidget_Type == NULL)+	    return G_OBJECT_CLASS (parent_class)->create_configure_dialog (plugin);+    +    +	if (!PyObject_TypeCheck(py_ret, &PyGtkWidget_Type))+	{+		PyErr_SetString(PyExc_TypeError, "return value for create_configure_dialog is not a GtkWidget");+		PyErr_Print();+		Py_XDECREF (py_ret);+		return G_OBJECT_CLASS (parent_class)->create_configure_dialog (plugin);+	}+	+	ret = GTK_WIDGET (pygobject_get (py_ret));+	+	g_object_ref (ret);+	Py_DECREF (py_ret);+	+	return ret;+}+						 static void  gedit_python_object_init (GeditPythonObject *object) {@@ -116,6 +184,7 @@ gedit_python_object_class_init (GeditPyt 	plugin_class->activate = impl_activate; 	plugin_class->deactivate = impl_deactivate; 	plugin_class->update_ui = impl_update_ui;+	plugin_class->create_configure_dialog = impl_create_configure_dialog; }  GType