gedit r6781 - in trunk: . plugin-loaders/python plugin-loaders/python/bindings
- From: jessevdk svn gnome org
- To: svn-commits-list gnome org
- Subject: gedit r6781 - in trunk: . plugin-loaders/python plugin-loaders/python/bindings
- Date: Thu, 1 Jan 2009 18:32:50 +0000 (UTC)
Author: jessevdk
Date: Thu Jan 1 18:32:49 2009
New Revision: 6781
URL: http://svn.gnome.org/viewvc/gedit?rev=6781&view=rev
Log:
* plugin-loaders/python/gedit-plugin-loader-python.c:
* plugin-loaders/python/bindings/geditplugin.override:
Fixed constructing plugin object (now works correctly without special
casing the construction). Previously, the GObject was not available
in the __init__ function of the plugin, this has been fixed.
Modified:
trunk/ChangeLog
trunk/plugin-loaders/python/bindings/geditplugin.override
trunk/plugin-loaders/python/gedit-plugin-loader-python.c
Modified: trunk/plugin-loaders/python/bindings/geditplugin.override
==============================================================================
--- trunk/plugin-loaders/python/bindings/geditplugin.override (original)
+++ trunk/plugin-loaders/python/bindings/geditplugin.override Thu Jan 1 18:32:49 2009
@@ -191,15 +191,3 @@
/* pygobject_new handles NULL checking */
return pygobject_new ((GObject *)ret);
}
-%%
-override gedit_plugin_python_new
-static int
-_wrap_gedit_plugin_python_new(PyGObject *self)
-{
- /* explicitly don't create the gobject, because we do that
- in the loader so we can set the install path property
- at construction time */
- return 0;
-}
-%%
-new-constructor GEDIT_TYPE_PLUGIN_PYTHON
Modified: trunk/plugin-loaders/python/gedit-plugin-loader-python.c
==============================================================================
--- trunk/plugin-loaders/python/gedit-plugin-loader-python.c (original)
+++ trunk/plugin-loaders/python/gedit-plugin-loader-python.c Thu Jan 1 18:32:49 2009
@@ -53,7 +53,6 @@
PyObject *type;
PyObject *instance;
gchar *path;
- GType class_type;
} PythonInfo;
static void gedit_plugin_loader_iface_init (gpointer g_iface, gpointer iface_data);
@@ -105,53 +104,62 @@
GeditPluginInfo *info)
{
PythonInfo *pyinfo;
+ PyTypeObject *pytype;
+ PyObject *pyobject;
PyGObject *pygobject;
GeditPlugin *instance;
+ PyObject *emptyarg;
pyinfo = (PythonInfo *)g_hash_table_lookup (loader->priv->loaded_plugins, info);
if (pyinfo == NULL)
return NULL;
+
+ pytype = (PyTypeObject *)pyinfo->type;
+
+ if (pytype->tp_new == NULL)
+ return NULL;
- /* To be able to set the install-path at construction time, we need two
- different strategies. If the py object has a registered gtype, the normal
- construction of the underlying gobject will happen before we can set the
- install-path. Therefore, the following two cases defined:
- 1) The python class has a gtype derived from GeditPluginPython
- The strategy here is to construct the gobject first (with the correct
- gtype, and setting the install-path), and then wrap it
- 2) The python class has the GeditPluginPython gtype (but it is still
- a derived class from the python point of view)
- In this case, we create the python object first, and construct the gobject
- afterwards. The initialize function of the GeditPluginPython bindings
- prevent the early construction of the gobject
- */
- if (pyinfo->class_type != GEDIT_TYPE_PLUGIN_PYTHON)
- {
- GObject *obj = g_object_new (pyinfo->class_type,
- "install-dir", pyinfo->path,
- "data-dir-name", gedit_plugin_info_get_module_name (info),
- NULL);
- pygobject = (PyGObject *)pygobject_new (obj);
- }
- else
- {
- pygobject = (PyGObject *)PyObject_CallObject (pyinfo->type, NULL);
-
- if (pygobject->obj != NULL)
- g_error("GObject for plugin is already initialized!");
-
- pygobject_construct(pygobject,
- "install-dir", pyinfo->path,
- "data-dir-name", gedit_plugin_info_get_module_name (info),
- NULL);
+ emptyarg = PyTuple_New(0);
+ pyobject = pytype->tp_new (pytype, emptyarg, NULL);
+ Py_DECREF (emptyarg);
+
+ if (pyobject == NULL)
+ {
+ g_error ("Could not create instance for %s.", gedit_plugin_info_get_name (info));
+ return NULL;
}
- if (pygobject == NULL || pygobject->obj == NULL)
+ pygobject = (PyGObject *)pyobject;
+
+ if (pygobject->obj != NULL)
{
- g_warning ("Could not create instance for %s.", gedit_plugin_info_get_name (info));
+ Py_DECREF (pyobject);
+ g_error ("Could not create instance for %s (GObject already initialized).", gedit_plugin_info_get_name (info));
return NULL;
}
+
+ pygobject_construct (pygobject,
+ "install-dir", pyinfo->path,
+ "data-dir-name", gedit_plugin_info_get_module_name (info),
+ NULL);
+
+ if (pygobject->obj == NULL)
+ {
+ g_error ("Could not create instance for %s (GObject not constructed).", gedit_plugin_info_get_name (info));
+ Py_DECREF (pyobject);
+
+ return NULL;
+ }
+
+ /* now call tp_init manually */
+ if (PyType_IsSubtype (pyobject->ob_type, pytype) &&
+ pyobject->ob_type->tp_init != NULL)
+ {
+ emptyarg = PyTuple_New(0);
+ pyobject->ob_type->tp_init (pyobject, emptyarg, NULL);
+ Py_DECREF (emptyarg);
+ }
instance = GEDIT_PLUGIN (pygobject->obj);
pyinfo->instance = (PyObject *)pygobject;
@@ -176,7 +184,6 @@
pyinfo = g_new (PythonInfo, 1);
pyinfo->path = g_strdup (path);
pyinfo->type = type;
- pyinfo->class_type = pyg_type_from_object(type);
Py_INCREF (pyinfo->type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]