This commit is contained in:
Perberos
2011-11-07 16:46:58 -03:00
commit 528c1e5ff5
532 changed files with 709826 additions and 0 deletions

7
plugin-loaders/Makefile.am Executable file
View File

@@ -0,0 +1,7 @@
SUBDIRS = c
if ENABLE_PYTHON
SUBDIRS += python
endif
-include $(top_srcdir)/git.mk

24
plugin-loaders/c/Makefile.am Executable file
View File

@@ -0,0 +1,24 @@
# C plugin loader
loaderdir = $(libdir)/gedit-2/plugin-loaders
INCLUDES = \
-I$(top_srcdir) \
$(GEDIT_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS) \
-DGEDIT_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
loader_LTLIBRARIES = libcloader.la
NOINST_H_FILES = \
gedit-plugin-loader-c.h
libcloader_la_SOURCES = \
gedit-plugin-loader-c.c \
$(NOINST_H_FILES)
libcloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS)
libcloader_la_LIBADD = $(GEDIT_LIBS)
-include $(top_srcdir)/git.mk

View File

@@ -0,0 +1,182 @@
/*
* gedit-plugin-loader-c.c
* This file is part of gedit
*
* Copyright (C) 2008 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gedit-plugin-loader-c.h"
#include <gedit/gedit-object-module.h>
#define GEDIT_PLUGIN_LOADER_C_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_PLUGIN_LOADER_C, GeditPluginLoaderCPrivate))
struct _GeditPluginLoaderCPrivate
{
GHashTable *loaded_plugins;
};
static void gedit_plugin_loader_iface_init (gpointer g_iface, gpointer iface_data);
GEDIT_PLUGIN_LOADER_REGISTER_TYPE (GeditPluginLoaderC, gedit_plugin_loader_c, G_TYPE_OBJECT, gedit_plugin_loader_iface_init);
static const gchar *
gedit_plugin_loader_iface_get_id (void)
{
return "C";
}
static GeditPlugin *
gedit_plugin_loader_iface_load (GeditPluginLoader *loader,
GeditPluginInfo *info,
const gchar *path)
{
GeditPluginLoaderC *cloader = GEDIT_PLUGIN_LOADER_C (loader);
GeditObjectModule *module;
const gchar *module_name;
GeditPlugin *result;
module = (GeditObjectModule *)g_hash_table_lookup (cloader->priv->loaded_plugins, info);
module_name = gedit_plugin_info_get_module_name (info);
if (module == NULL)
{
/* For now we force all modules to be resident */
module = gedit_object_module_new (module_name,
path,
"register_gedit_plugin",
TRUE);
/* Infos are available for all the lifetime of the loader.
* If this changes, we should use weak refs or something */
g_hash_table_insert (cloader->priv->loaded_plugins, info, module);
}
if (!g_type_module_use (G_TYPE_MODULE (module)))
{
g_warning ("Could not load plugin module: %s", gedit_plugin_info_get_name (info));
return NULL;
}
/* TODO: for now we force data-dir-name = module-name... if needed we can
* add a datadir field to the plugin descriptor file.
*/
result = (GeditPlugin *)gedit_object_module_new_object (module,
"install-dir", path,
"data-dir-name", module_name,
NULL);
if (!result)
{
g_warning ("Could not create plugin object: %s", gedit_plugin_info_get_name (info));
g_type_module_unuse (G_TYPE_MODULE (module));
return NULL;
}
g_type_module_unuse (G_TYPE_MODULE (module));
return result;
}
static void
gedit_plugin_loader_iface_unload (GeditPluginLoader *loader,
GeditPluginInfo *info)
{
//GeditPluginLoaderC *cloader = GEDIT_PLUGIN_LOADER_C (loader);
/* this is a no-op, since the type module will be properly unused as
the last reference to the plugin dies. When the plugin is activated
again, the library will be reloaded */
}
static void
gedit_plugin_loader_iface_init (gpointer g_iface,
gpointer iface_data)
{
GeditPluginLoaderInterface *iface = (GeditPluginLoaderInterface *)g_iface;
iface->get_id = gedit_plugin_loader_iface_get_id;
iface->load = gedit_plugin_loader_iface_load;
iface->unload = gedit_plugin_loader_iface_unload;
}
static void
gedit_plugin_loader_c_finalize (GObject *object)
{
GeditPluginLoaderC *cloader = GEDIT_PLUGIN_LOADER_C (object);
GList *infos;
GList *item;
/* FIXME: this sanity check it's not efficient. Let's remove it
* once we are confident with the code */
infos = g_hash_table_get_keys (cloader->priv->loaded_plugins);
for (item = infos; item; item = item->next)
{
GeditPluginInfo *info = (GeditPluginInfo *)item->data;
if (gedit_plugin_info_is_active (info))
{
g_warning ("There are still C plugins loaded during destruction");
break;
}
}
g_list_free (infos);
g_hash_table_destroy (cloader->priv->loaded_plugins);
G_OBJECT_CLASS (gedit_plugin_loader_c_parent_class)->finalize (object);
}
static void
gedit_plugin_loader_c_class_init (GeditPluginLoaderCClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gedit_plugin_loader_c_finalize;
g_type_class_add_private (object_class, sizeof (GeditPluginLoaderCPrivate));
}
static void
gedit_plugin_loader_c_class_finalize (GeditPluginLoaderCClass *klass)
{
}
static void
gedit_plugin_loader_c_init (GeditPluginLoaderC *self)
{
self->priv = GEDIT_PLUGIN_LOADER_C_GET_PRIVATE (self);
/* loaded_plugins maps GeditPluginInfo to a GeditObjectModule */
self->priv->loaded_plugins = g_hash_table_new (g_direct_hash,
g_direct_equal);
}
GeditPluginLoaderC *
gedit_plugin_loader_c_new ()
{
GObject *loader = g_object_new (GEDIT_TYPE_PLUGIN_LOADER_C, NULL);
return GEDIT_PLUGIN_LOADER_C (loader);
}

View File

@@ -0,0 +1,60 @@
/*
* gedit-plugin-loader-c.h
* This file is part of gedit
*
* Copyright (C) 2008 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GEDIT_PLUGIN_LOADER_C_H__
#define __GEDIT_PLUGIN_LOADER_C_H__
#include <gedit/gedit-plugin-loader.h>
G_BEGIN_DECLS
#define GEDIT_TYPE_PLUGIN_LOADER_C (gedit_plugin_loader_c_get_type ())
#define GEDIT_PLUGIN_LOADER_C(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_PLUGIN_LOADER_C, GeditPluginLoaderC))
#define GEDIT_PLUGIN_LOADER_C_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_PLUGIN_LOADER_C, GeditPluginLoaderC const))
#define GEDIT_PLUGIN_LOADER_C_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_PLUGIN_LOADER_C, GeditPluginLoaderCClass))
#define GEDIT_IS_PLUGIN_LOADER_C(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_PLUGIN_LOADER_C))
#define GEDIT_IS_PLUGIN_LOADER_C_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_PLUGIN_LOADER_C))
#define GEDIT_PLUGIN_LOADER_C_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_PLUGIN_LOADER_C, GeditPluginLoaderCClass))
typedef struct _GeditPluginLoaderC GeditPluginLoaderC;
typedef struct _GeditPluginLoaderCClass GeditPluginLoaderCClass;
typedef struct _GeditPluginLoaderCPrivate GeditPluginLoaderCPrivate;
struct _GeditPluginLoaderC {
GObject parent;
GeditPluginLoaderCPrivate *priv;
};
struct _GeditPluginLoaderCClass {
GObjectClass parent_class;
};
GType gedit_plugin_loader_c_get_type (void) G_GNUC_CONST;
GeditPluginLoaderC *gedit_plugin_loader_c_new(void);
/* All the loaders must implement this function */
G_MODULE_EXPORT GType register_gedit_plugin_loader (GTypeModule * module);
G_END_DECLS
#endif /* __GEDIT_PLUGIN_LOADER_C_H__ */

View File

@@ -0,0 +1,36 @@
# C plugin loader
SUBDIRS = bindings
loaderdir = $(libdir)/gedit-2/plugin-loaders
INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir) \
-I$(top_srcdir)/gedit \
-I$(top_builddir)/gedit \
$(GEDIT_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS) \
$(PYGTK_CFLAGS) \
$(PYTHON_CFLAGS) \
-DGEDIT_PLUGINS_LIBS_DIR=\"$(GEDIT_PLUGINS_LIBS_DIR)\" \
-DGEDIT_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
loader_LTLIBRARIES = libpythonloader.la
NOINST_H_FILES = \
gedit-plugin-loader-python.h \
gedit-plugin-python.h
libpythonloader_la_SOURCES = \
gedit-plugin-loader-python.c \
gedit-plugin-python.c \
$(NOINST_H_FILES)
libpythonloader_la_LDFLAGS = $(LOADER_LIBTOOL_FLAGS)
libpythonloader_la_LIBADD = \
$(GEDIT_LIBS) \
bindings/gedit.la
-include $(top_srcdir)/git.mk

View File

@@ -0,0 +1,115 @@
## Process this file with automake to produce Makefile.in
noinst_LTLIBRARIES = \
gedit.la
nodist_gedit_la_SOURCES = \
gedit.c \
geditutils.c \
geditcommands.c
gedit_la_LDFLAGS = \
-module -avoid-version
gedit_la_LIBADD = \
$(PYTHON_LIB_LOC) \
$(PYTHON_LIBS) \
$(PYTHON_EXTRA_LIBS) \
$(PYGTK_LIBS)
gedit_la_CFLAGS = \
-I$(top_srcdir) \
-I$(top_builddir) \
-I$(top_srcdir)/gedit \
-I$(top_builddir)/gedit \
-I$(top_srcdir)/plugin-loaders/python \
-I$(top_builddir)/plugin-loaders/python \
$(GEDIT_CFLAGS) \
$(NO_STRICT_ALIASING_CFLAGS) \
$(PYGTK_CFLAGS) \
$(PYTHON_CFLAGS) \
$(AM_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) \
--register $(PYGTK_DEFSDIR)/pango-types.defs \
--register $(PYGTK_DEFSDIR)/gdk-types.defs \
--register $(PYGTK_DEFSDIR)/gtk-types.defs \
--register $(PYGTK_DEFSDIR)/gtksourceview2.defs \
--register $(PYGOBJECT_DEFSDIR)/gio-types.defs \
--override $*.override \
--prefix py$* $(<F) ) > $@
geditutils.c: geditutils.defs geditutils.override
( cd $(srcdir) && $(PYGTK_CODEGEN) \
--override $*.override \
--prefix py$* $(<F) ) > $@
geditcommands.c: geditcommands.defs geditcommands.override gedit.defs
( 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 \
plugin-loaders/python/gedit-plugin-python.h \
gedit/gedit-view.h \
gedit/gedit-statusbar.h \
gedit/gedit-tab.h \
gedit/gedit-panel.h \
gedit/gedit-window.h \
gedit/gedit-help.h \
gedit/gedit-debug.h \
gedit/gedit-message-type.h \
gedit/gedit-message.h \
gedit/gedit-message-bus.h \
gedit/gedit-language-manager.h
BINDING_UTILS_HEADERS_SRCDIR_IN = \
gedit/gedit-utils.h
BINDING_COMMANDS_HEADERS_SRCDIR_IN = \
gedit/gedit-commands.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_HEADERS_BUILDDIR := $(addprefix $(top_builddir)/,$(BINDING_HEADERS_BUILDDIR_IN))
regenerate-python-binding:
$(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
BUILT_SOURCES = \
gedit.c \
geditutils.c \
geditcommands.c
EXTRA_DIST = \
gedit.override \
gedit.defs \
geditutils.override \
geditutils.defs \
geditcommands.override \
geditcommands.defs \
geditmessage.override \
geditplugin.override
CLEANFILES = $(BUILT_SOURCES)
dist-hook:
cd $(distdir); rm -f $(BUILT_SOURCES)
-include $(top_srcdir)/git.mk

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,461 @@
%%
headers
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include <gedit/gedit-language-manager.h>
#include <gedit/gedit-plugin.h>
#include <gedit/gedit-app.h>
#include <gedit/gedit-encodings.h>
#include <gedit/gedit-enum-types.h>
#include <gedit/gedit-statusbar.h>
#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);
static PyObject *
_helper_wrap_gobject_glist (const GList *list)
{
PyObject *py_list;
const GList *tmp;
if ((py_list = PyList_New(0)) == NULL) {
return NULL;
}
for (tmp = list; tmp != NULL; tmp = tmp->next) {
PyObject *py_obj = pygobject_new(G_OBJECT(tmp->data));
if (py_obj == NULL) {
Py_DECREF(py_list);
return NULL;
}
PyList_Append(py_list, py_obj);
Py_DECREF(py_obj);
}
return py_list;
}
static PyObject *
_helper_wrap_gobject_gslist (const GSList *list)
{
PyObject *py_list;
const GSList *tmp;
if ((py_list = PyList_New(0)) == NULL) {
return NULL;
}
for (tmp = list; tmp != NULL; tmp = tmp->next) {
PyObject *py_obj = pygobject_new(G_OBJECT(tmp->data));
if (py_obj == NULL) {
Py_DECREF(py_list);
return NULL;
}
PyList_Append(py_list, py_obj);
Py_DECREF(py_obj);
}
return py_list;
}
%%
include
geditplugin.override
geditmessage.override
%%
modulename gedit
%%
import gtk.Widget as PyGtkWidget_Type
import gobject.GObject as PyGObject_Type
import gtk.gdk.Screen as PyGdkScreen_Type
import gtk.VBox as PyGtkVBox_Type
import gtk.Window as PyGtkWindow_Type
import gtk.Image as PyGtkImage_Type
import gtk.Statusbar as PyGtkStatusbar_Type
import gtksourceview2.Buffer as PyGtkSourceBuffer_Type
import gtksourceview2.View as PyGtkSourceView_Type
import gtksourceview2.Language as PyGtkSourceLanguage_Type
import gtksourceview2.LanguageManager as PyGtkSourceLanguageManager_Type
%%
ignore-glob
*_get_type
gedit_document_error_quark
gedit_panel_add_item_with_stock_icon
%%
override gedit_app_create_window kwargs
static PyObject *
_wrap_gedit_app_create_window(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "screen", NULL};
PyGObject *screen = NULL;
GeditWindow *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|O!", kwlist,
&PyGdkScreen_Type, &screen))
return NULL;
ret = gedit_app_create_window(GEDIT_APP(self->obj),
screen ? GDK_SCREEN(screen->obj) : NULL);
/* pygobject_new handles NULL checking */
return pygobject_new((GObject *)ret);
}
%%
override gedit_app_get_windows
static PyObject *
_wrap_gedit_app_get_windows(PyGObject *self)
{
const GList *list;
PyObject *py_list;
list = gedit_app_get_windows (GEDIT_APP (self->obj));
py_list = _helper_wrap_gobject_glist (list);
return py_list;
}
%%
override gedit_app_get_views
static PyObject *
_wrap_gedit_app_get_views(PyGObject *self)
{
GList *list;
PyObject *py_list;
list = gedit_app_get_views (GEDIT_APP (self->obj));
py_list = _helper_wrap_gobject_glist (list);
g_list_free (list);
return py_list;
}
%%
override gedit_app_get_documents
static PyObject *
_wrap_gedit_app_get_documents(PyGObject *self)
{
GList *list;
PyObject *py_list;
list = gedit_app_get_documents (GEDIT_APP (self->obj));
py_list = _helper_wrap_gobject_glist (list);
g_list_free (list);
return py_list;
}
%%
override gedit_window_get_documents
static PyObject *
_wrap_gedit_window_get_documents(PyGObject *self)
{
GList *list;
PyObject *py_list;
list = gedit_window_get_documents (GEDIT_WINDOW (self->obj));
py_list = _helper_wrap_gobject_glist (list);
g_list_free(list);
return py_list;
}
%%
override gedit_window_get_unsaved_documents
static PyObject *
_wrap_gedit_window_get_unsaved_documents(PyGObject *self)
{
GList *list;
PyObject *py_list;
list = gedit_window_get_unsaved_documents (GEDIT_WINDOW (self->obj));
py_list = _helper_wrap_gobject_glist (list);
g_list_free(list);
return py_list;
}
%%
override gedit_window_get_views
static PyObject *
_wrap_gedit_window_get_views(PyGObject *self)
{
GList *list;
PyObject *py_list;
list = gedit_window_get_views (GEDIT_WINDOW (self->obj));
py_list = _helper_wrap_gobject_glist (list);
g_list_free(list);
return py_list;
}
%%
override gedit_window_close_tabs kwargs
static PyObject *
_wrap_gedit_window_close_tabs (PyGObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "tabs", NULL };
PyObject *list, *item;
GList *glist = NULL;
int len, i;
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
"O:GeditWindow.close_tabs", kwlist,
&list))
return NULL;
if (!PySequence_Check (list))
{
PyErr_SetString (PyExc_TypeError,
"first argument must be a sequence");
return NULL;
}
len = PySequence_Length (list);
for (i = 0; i < len; i++)
{
item = PySequence_GetItem (list, i);
Py_DECREF(item);
if (!pygobject_check (item, &PyGeditTab_Type))
{
PyErr_SetString (PyExc_TypeError,
"sequence item not a Gtkwidget object");
g_list_free (glist);
return NULL;
}
glist = g_list_append (glist, pygobject_get (item));
}
gedit_window_close_tabs (GEDIT_WINDOW (self->obj), glist);
g_list_free (glist);
Py_INCREF (Py_None);
return Py_None;
}
%%
override gedit_document_get_search_text
static PyObject *
_wrap_gedit_document_get_search_text(PyGObject *self)
{
PyObject *tuple, *string;
guint flags;
gchar *ret;
ret = gedit_document_get_search_text (GEDIT_DOCUMENT (self->obj), &flags);
tuple = PyTuple_New(2);
if (ret) {
string = PyString_FromString(ret);
PyTuple_SetItem(tuple, 0, string);
} else {
Py_INCREF(Py_None);
PyTuple_SetItem(tuple, 0, Py_None);
}
PyTuple_SetItem(tuple, 1, PyInt_FromLong(flags));
g_free(ret);
return tuple;
}
%%
override gedit_panel_add_item kwargs
static PyObject *
_wrap_gedit_panel_add_item(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist1[] = { "item", "name", "image", NULL };
static char *kwlist2[] = { "item", "name", "stock_id", NULL };
PyGObject *item, *image;
char *name = NULL;
char *stock_id = NULL;
if (PyArg_ParseTupleAndKeywords(args, kwargs, "O!sO!:GeditPanel.add_item", kwlist1, &PyGtkWidget_Type, &item, &name, &PyGtkImage_Type, &image)) {
gedit_panel_add_item(GEDIT_PANEL(self->obj), GTK_WIDGET(item->obj), name, GTK_WIDGET(image->obj));
Py_INCREF(Py_None);
return Py_None;
}
PyErr_Clear();
if (PyArg_ParseTupleAndKeywords(args, kwargs, "O!ss:GeditPanel.add_item", kwlist2, &PyGtkWidget_Type, &item, &name, &stock_id)) {
gedit_panel_add_item_with_stock_icon(GEDIT_PANEL(self->obj), GTK_WIDGET(item->obj), name, stock_id);
Py_INCREF(Py_None);
return Py_None;
}
PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "the last arg should be either a gtk.Image or a stock_id string");
return NULL;
}
%%
override gedit_app_get_default_deprecated
/* deprecated wrappers */
static PyObject *
_wrap_gedit_app_get_default_deprecated(PyObject *self)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.app_get_default instead") < 0)
return NULL;
return _wrap_gedit_app_get_default(self);
}
%%
override gedit_encoding_get_from_charset_deprecated kwargs
static PyObject *
_wrap_gedit_encoding_get_from_charset_deprecated(PyObject *self, PyObject *args, PyObject *kwargs)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.encoding_get_from_charset instead") < 0)
return NULL;
return _wrap_gedit_encoding_get_from_charset(self, args, kwargs);
}
%%
override gedit_encoding_get_from_index_deprecated kwargs
static PyObject *
_wrap_gedit_encoding_get_from_index_deprecated(PyObject *self, PyObject *args, PyObject *kwargs)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.encoding_get_from_index instead") < 0)
return NULL;
return _wrap_gedit_encoding_get_from_index(self, args, kwargs);
}
%%
override gedit_encoding_get_utf8_deprecated
static PyObject *
_wrap_gedit_encoding_get_utf8_deprecated(PyObject *self)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.encoding_get_utf8 instead") < 0)
return NULL;
return _wrap_gedit_encoding_get_utf8(self);
}
%%
override gedit_encoding_get_current_deprecated
static PyObject *
_wrap_gedit_encoding_get_current_deprecated(PyObject *self)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.encoding_get_current instead") < 0)
return NULL;
return _wrap_gedit_encoding_get_current(self);
}
%%
override gedit_tab_get_from_document_deprecated kwargs
static PyObject *
_wrap_gedit_tab_get_from_document_deprecated(PyObject *self, PyObject *args, PyObject *kwargs)
{
if (PyErr_Warn(PyExc_DeprecationWarning, "use gedit.tab_get_from_document instead") < 0)
return NULL;
return _wrap_gedit_tab_get_from_document(self, args, kwargs);
}
%%
override gedit_language_manager_list_languages_sorted kwargs
static PyObject *
_wrap_gedit_language_manager_list_languages_sorted(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "lm", "include_hidden", NULL };
PyGObject *lm;
int include_hidden;
PyObject *py_list;
GSList *list;
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
"O!i:language_manager_list_languages_sorted",
kwlist, &PyGtkSourceLanguageManager_Type, &lm,
&include_hidden))
return NULL;
list = gedit_language_manager_list_languages_sorted (GTK_SOURCE_LANGUAGE_MANAGER (lm->obj),
include_hidden);
py_list = _helper_wrap_gobject_gslist (list);
g_slist_free (list);
return py_list;
}
%%
override gedit_debug kwargs
static PyObject *
_wrap_gedit_debug(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "message", NULL };
PyObject *traceback_module, *mdict, *func, *traceback, *tuple;
PyObject *filename, *lineno, *funcname;
char *message = NULL;
if (g_getenv ("GEDIT_DEBUG_PLUGINS") == NULL)
{
Py_INCREF (Py_None);
return Py_None;
}
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "|s", kwlist, &message))
return NULL;
traceback_module = PyImport_ImportModule ("traceback");
if (traceback_module == NULL)
{
g_warning ("traceback module cannot be imported");
Py_INCREF (Py_None);
return Py_None;
}
mdict = PyModule_GetDict (traceback_module);
func = PyDict_GetItemString (mdict, "extract_stack");
traceback = PyObject_CallFunction (func, "zi", NULL, 1);
tuple = PyList_GetItem (traceback, 0);
if (tuple == NULL || !PyTuple_Check (tuple))
{
g_warning ("traceback tuple is null!");
}
else
{
filename = PyTuple_GetItem (tuple, 0);
lineno = PyTuple_GetItem (tuple, 1);
funcname = PyTuple_GetItem (tuple, 2);
if (message == NULL)
gedit_debug (GEDIT_DEBUG_PLUGINS,
PyString_AsString (filename),
PyInt_AsLong (lineno),
PyString_AsString (funcname));
else
gedit_debug_message (GEDIT_DEBUG_PLUGINS,
PyString_AsString (filename),
PyInt_AsLong (lineno),
PyString_AsString (funcname),
"%s",
message);
}
Py_DECREF (traceback);
Py_DECREF (traceback_module);
Py_INCREF (Py_None);
return Py_None;
}
%%
override gedit_statusbar_flash_message kwargs
static PyObject *
_wrap_gedit_statusbar_flash_message(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "context_id", "message", NULL };
int context_id;
char *message;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,"is:GeditStatusbar.flash_message", kwlist, &context_id, &message))
return NULL;
gedit_statusbar_flash_message(GEDIT_STATUSBAR(self->obj), context_id, "%s", message);
Py_INCREF(Py_None);
return Py_None;
}
%%

View File

@@ -0,0 +1,45 @@
;; -*- scheme -*-
; object definitions ...
;; Enumerations and flags ...
;; From ../../gedit/gedit-commands.h
(define-function load_uri
(c-name "gedit_commands_load_uri")
(return-type "none")
(parameters
'("GeditWindow*" "window")
'("const-gchar*" "uri")
'("const-GeditEncoding*" "encoding")
'("gint" "line_pos")
)
)
(define-function load_uris
(c-name "gedit_commands_load_uris")
(return-type "gint")
(parameters
'("GeditWindow*" "window")
'("const-GSList*" "uris")
'("const-GeditEncoding*" "encoding")
'("gint" "line_pos")
)
)
(define-function save_document
(c-name "gedit_commands_save_document")
(return-type "none")
(parameters
'("GeditWindow*" "window")
'("GeditDocument*" "document")
)
)
(define-function save_all_documents
(c-name "gedit_commands_save_all_documents")
(return-type "none")
(parameters
'("GeditWindow*" "window")
)
)

View File

@@ -0,0 +1,122 @@
%%
headers
#define NO_IMPORT_PYGOBJECT
#define NO_IMPORT_PYGTK
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include "gedit-commands.h"
#include "gedit-window.h"
void pygeditcommands_register_classes (PyObject *d);
void pygeditcommands_add_constants (PyObject *module, const gchar *strip_prefix);
%%
modulename gedit.commands
%%
import gedit.Window as PyGeditWindow_Type
import gedit.Document as PyGeditDocument_Type
%%
ignore-glob
_*
%%
override gedit_commands_load_uri kwargs
static PyObject *
_wrap_gedit_commands_load_uri (PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "window", "uri", "encoding", "line_pos", NULL };
PyGObject *window;
char *uri;
int line_pos = 0;
PyObject *py_encoding = NULL;
GeditEncoding *encoding = NULL;
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "O!s|Oi:load_uri",
kwlist, &PyGeditWindow_Type,
&window, &uri, &py_encoding,
&line_pos))
return NULL;
if (py_encoding != NULL && py_encoding != Py_None)
{
if (pyg_boxed_check (py_encoding, GEDIT_TYPE_ENCODING))
encoding = pyg_boxed_get (py_encoding, GeditEncoding);
else
{
PyErr_SetString (PyExc_TypeError,
"encoding should be a GeditEncoding");
return NULL;
}
}
gedit_commands_load_uri (GEDIT_WINDOW (window->obj), uri, encoding,
line_pos);
Py_INCREF (Py_None);
return Py_None;
}
%%
override gedit_commands_load_uris kwargs
static PyObject *
_wrap_gedit_commands_load_uris (PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "window", "uris", "encoding", "line_pos", NULL };
PyGObject *window;
GSList *uris = NULL;
int line_pos = 0;
PyObject *py_encoding = NULL;
PyObject *list;
PyObject *item;
GeditEncoding *encoding = NULL;
int len;
int i;
if (!PyArg_ParseTupleAndKeywords (args, kwargs, "O!O|Oi:load_uri",
kwlist, &PyGeditWindow_Type,
&window, &list, &py_encoding,
&line_pos))
return NULL;
if (py_encoding != NULL && py_encoding != Py_None)
{
if (pyg_boxed_check (py_encoding, GEDIT_TYPE_ENCODING))
encoding = pyg_boxed_get (py_encoding, GeditEncoding);
else {
PyErr_SetString (PyExc_TypeError,
"encoding should be a GeditEncoding");
return NULL;
}
}
if (!PySequence_Check (list))
{
PyErr_SetString (PyExc_TypeError,
"second argument must be a sequence");
return NULL;
}
len = PySequence_Length (list);
for (i = 0; i < len; i++)
{
item = PySequence_GetItem (list, i);
Py_DECREF (item);
if (!PyString_Check (item))
{
PyErr_SetString (PyExc_TypeError,
"sequence item not a string");
g_slist_free (uris);
return NULL;
}
uris = g_slist_prepend (uris, PyString_AsString (item));
}
uris = g_slist_reverse (uris);
gedit_commands_load_uris (GEDIT_WINDOW (window->obj), uris,
encoding, line_pos);
g_slist_free (uris);
Py_INCREF (Py_None);
return Py_None;
}

View File

@@ -0,0 +1,556 @@
%%
headers
#include <gedit/gedit-message-bus.h>
#include <gedit/gedit-message.h>
static GType
_helper_wrap_get_gtype_from_pytype (PyObject *pytype)
{
PyTypeObject *type = (PyTypeObject *)pytype;
if (type == &PyList_Type || type == &PyTuple_Type)
return G_TYPE_STRV;
return pyg_type_from_object (pytype);
}
static gchar *
_helper_wrap_get_string (PyObject *obj)
{
PyObject *str;
gchar *result;
str = PyObject_Str (obj);
if (!str)
return NULL;
result = g_strdup (PyString_AsString (str));
Py_DECREF (str);
return result;
}
static int
_helper_wrap_list_to_gvalue (GValue *gvalue, PyObject *pyvalue)
{
int num;
gchar **lst;
gint i;
num = PySequence_Size (pyvalue);
lst = g_new0 (gchar *, num + 1);
for (i = 0; i < num; i++)
{
lst[i] = _helper_wrap_get_string (PySequence_GetItem (pyvalue, i));
if (lst[i] == NULL)
{
g_strfreev (lst);
return 1;
}
}
g_value_set_boxed (gvalue, lst);
g_strfreev (lst);
return 0;
}
static int
_helper_wrap_get_gvalue_from_pyobject (GValue *gvalue, PyObject *pyvalue)
{
if (pyvalue->ob_type == &PyList_Type || pyvalue->ob_type == &PyTuple_Type)
return _helper_wrap_list_to_gvalue (gvalue, pyvalue);
return pyg_value_from_pyobject(gvalue, pyvalue);
}
static int
_helper_wrap_message_set_value(GeditMessage *message, PyObject *pykey, PyObject *pyvalue)
{
gchar *key;
GType gtype;
GValue value = {0,};
key = _helper_wrap_get_string(pykey);
if (key == NULL)
return 0;
gtype = gedit_message_get_key_type(message, key);
if (gtype == 0) {
PyErr_SetString(PyExc_TypeError, "invalid key");
g_free (key);
return 0;
}
g_value_init(&value, gtype);
if (_helper_wrap_get_gvalue_from_pyobject (&value, pyvalue)) {
PyErr_SetString(PyExc_TypeError,
"value is of the wrong type for this key");
g_free (key);
return 0;
}
gedit_message_set_value(message, key, &value);
g_value_unset(&value);
g_free (key);
return 1;
}
typedef void (*ParsePairFunc)(PyObject *key, PyObject *value, gpointer user_data);
static void
_helper_parse_pairs_dict (PyObject *dict, ParsePairFunc func, gpointer user_data)
{
if (!dict)
return;
PyObject *key, *value;
Py_ssize_t i = 0;
while (PyDict_Next(dict, &i, &key, &value))
{
func(key, value, user_data);
}
}
static void
_helper_parse_pairs(PyObject *args, PyObject *kwargs, ParsePairFunc func, gpointer user_data)
{
guint len;
guint i;
len = PyTuple_Size(args);
for (i = 0; i < len; ++i)
{
PyObject *d = PyTuple_GetItem(args, i);
if (PyDict_Check(d))
_helper_parse_pairs_dict(d, func, user_data);
}
_helper_parse_pairs_dict(kwargs, func, user_data);
}
static void
_helper_message_set(PyObject *key, PyObject *value, GeditMessage *message)
{
_helper_wrap_message_set_value(message, key, value);
}
static void
_helper_message_set_values(GeditMessage *message, PyObject *args, PyObject *kwargs)
{
_helper_parse_pairs(args, kwargs, (ParsePairFunc)_helper_message_set, message);
}
static GeditMessage *
_helper_wrap_create_message(GeditMessageBus *bus, PyObject *args, PyObject *kwargs)
{
PyObject *pypath, *pymethod, *pydict;
if (!PyArg_ParseTuple(args, "OO|O:GeditMessage.create", &pypath, &pymethod, &pydict))
return NULL;
gchar *object_path = _helper_wrap_get_string(pypath);
gchar *method = _helper_wrap_get_string(pymethod);
GeditMessageType *message_type = gedit_message_bus_lookup (bus, object_path, method);
GeditMessage *message;
if (message_type)
{
message = gedit_message_type_instantiate(message_type, NULL);
_helper_message_set_values(message, args, kwargs);
}
else
{
PyErr_SetString(PyExc_StandardError, "Message type does not exist");
message = NULL;
}
g_free(object_path);
g_free(method);
return message;
}
typedef struct {
PyObject *func;
PyObject *data;
} PyGeditCustomNotify;
static void
pygedit_custom_destroy_notify(gpointer user_data)
{
PyGeditCustomNotify *cunote = user_data;
PyGILState_STATE state;
g_return_if_fail(user_data);
state = pyg_gil_state_ensure();
Py_XDECREF(cunote->func);
Py_XDECREF(cunote->data);
pyg_gil_state_release(state);
g_free(cunote);
}
%%
ignore-glob
*_get_type
gedit_message_type_foreach
gedit_message_type_instantiate_valist
gedit_message_type_new_valist
gedit_message_get_valist
gedit_message_set_valist
gedit_message_set_valuesv
gedit_message_bus_disconnect_by_func
gedit_message_bus_block_by_func
gedit_message_bus_unblock_by_func
%%
override gedit_message_type_new kwargs
typedef struct
{
GeditMessageType *message_type;
PyObject *optional;
} MessageTypeSetInfo;
static void
_message_type_set(PyObject *key, PyObject *value, MessageTypeSetInfo *info)
{
GType gtype;
gchar *k = _helper_wrap_get_string(key);
if (!k)
return;
gtype = _helper_wrap_get_gtype_from_pytype(value);
gboolean optional = info->optional && PySequence_Contains(info->optional, key);
gedit_message_type_set(info->message_type, optional, k, gtype, NULL);
g_free(k);
}
static int
_wrap_gedit_message_type_new(PyGObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *pypath, *pymethod, *optional = NULL, *pydict;
if (!PyArg_ParseTuple(args, "OO|OO:GeditMessageType.new", &pypath, &pymethod, &optional, &pydict))
return -1;
GeditMessageType *message_type = GEDIT_MESSAGE_TYPE(g_object_new(pyg_type_from_object((PyObject *) self), NULL));
MessageTypeSetInfo info = {message_type, optional && PySequence_Check(optional) ? optional : NULL};
_helper_parse_pairs (args, kwargs, (ParsePairFunc)_message_type_set, &info);
self->obj = (GObject *)message_type;
pygobject_register_wrapper((PyObject *) self);
return 0;
}
%%
override gedit_message_type_instantiate kwargs
static PyObject *
_wrap_gedit_message_type_instantiate(PyGObject *self, PyObject *args, PyObject *kwargs)
{
GeditMessageType *message_type = GEDIT_MESSAGE_TYPE (self->obj);
GeditMessage *message = gedit_message_type_instantiate(message_type, NULL);
_helper_message_set_values(message, args, kwargs);
return pygobject_new((GObject *)message);
}
%%
override gedit_message_get args
static PyObject *
_wrap_gedit_message_get(PyGObject *self, PyObject *args)
{
guint len, i;
PyObject *ret;
len = PyTuple_Size(args);
ret = PyTuple_New(len);
for (i = 0; i < len; i++) {
GValue value = { 0, };
PyObject *py_key = PyTuple_GetItem(args, i);
gchar *key = _helper_wrap_get_string(py_key);
if (!key) {
PyErr_SetString(PyExc_TypeError, "keys must be strings");
Py_DECREF(ret);
return NULL;
}
gedit_message_get_value (GEDIT_MESSAGE (self->obj), key, &value);
g_free (key);
PyTuple_SetItem(ret, i, pyg_value_as_pyobject(&value, TRUE));
g_value_unset(&value);
}
return ret;
}
%%
override gedit_message_get_value kwargs
static PyObject *
_wrap_gedit_message_get_value(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "key", NULL };
const gchar *key;
PyObject *ret;
GValue value = { 0, };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:GeditMessage.get_value", kwlist, &key))
return NULL;
gedit_message_get_value(GEDIT_MESSAGE(self->obj), key, &value);
ret = pyg_value_as_pyobject(&value, TRUE);
g_value_unset(&value);
return ret;
}
%%
override gedit_message_set_value kwargs
static PyObject *
_wrap_gedit_message_set_value(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "key", "value", NULL };
PyObject *pykey, *pyvalue;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO:GeditMessage.set_value", kwlist, &pykey, &pyvalue))
return NULL;
if (!_helper_wrap_message_set_value(GEDIT_MESSAGE(self->obj), pykey, pyvalue))
return NULL;
Py_INCREF(Py_None);
return Py_None;
}
%%
override gedit_message_set kwargs
static PyObject *
_wrap_gedit_message_set (PyGObject *self, PyObject *args, PyObject *kwargs) {
_helper_message_set_values(GEDIT_MESSAGE(self->obj), args, kwargs);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gedit_message_bus_new
static int
_wrap_gedit_message_bus_new(PyGObject *self)
{
pygobject_construct (self, NULL);
if (!self->obj) {
PyErr_SetString (PyExc_RuntimeError, "could not create gedit.MessageBus object");
return -1;
}
return 0;
}
%%
new-constructor GEDIT_TYPE_MESSAGE_BUS
%%
override gedit_message_bus_register kwargs
static PyObject *
_wrap_gedit_message_bus_register(PyGObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *pypath, *pymethod, *optional = NULL, *pydict;
GeditMessageBus *bus = GEDIT_MESSAGE_BUS(self->obj);
if (!PyArg_ParseTuple(args, "OO|OO:GeditMessageBus.register", &pypath, &pymethod, &optional, &pydict))
return NULL;
gchar *object_path = _helper_wrap_get_string(pypath);
gchar *method = _helper_wrap_get_string(pymethod);
GeditMessageType *message_type = gedit_message_bus_register(bus, object_path, method, 0, NULL);
g_free(object_path);
g_free(method);
if (!message_type)
{
PyErr_SetString(PyExc_StandardError, "Message type already exists");
return NULL;
}
MessageTypeSetInfo info = {message_type, optional && PySequence_Check(optional) ? optional : NULL};
_helper_parse_pairs (args, kwargs, (ParsePairFunc)_message_type_set, &info);
return pyg_boxed_new(GEDIT_TYPE_MESSAGE_TYPE, message_type, TRUE, TRUE);
}
%%
override gedit_message_bus_connect kwargs
static void
pygedit_message_bus_connect_cb(GeditMessageBus *bus, GeditMessage *message, gpointer data)
{
PyGILState_STATE state;
PyGeditCustomNotify *cunote = data;
PyObject *pybus, *pymessage, *retobj;
g_assert(cunote->func);
state = pyg_gil_state_ensure();
pybus = pygobject_new((GObject *)bus);
pymessage = pygobject_new((GObject *)message);
if (cunote->data) {
retobj = PyEval_CallFunction(cunote->func, "(NNO)", pybus, pymessage, cunote->data);
} else {
retobj = PyEval_CallFunction(cunote->func, "(NN)", pybus, pymessage);
}
if (PyErr_Occurred()) {
PyErr_Print();
}
Py_XDECREF(retobj);
pyg_gil_state_release(state);
}
static PyObject *
_wrap_gedit_message_bus_connect(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "domain", "name", "func", "data", NULL };
PyObject *pyfunc, *pyarg = NULL;
const gchar *domain;
const gchar *name;
PyGeditCustomNotify *cunote;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"ssO|O:GeditMessageBus.connect",
kwlist, &domain, &name, &pyfunc, &pyarg))
return NULL;
if (!PyCallable_Check(pyfunc)) {
PyErr_SetString(PyExc_TypeError, "func must be a callable object");
return NULL;
}
cunote = g_new(PyGeditCustomNotify, 1);
Py_INCREF(pyfunc);
cunote->func = pyfunc;
Py_XINCREF(pyarg);
cunote->data = pyarg;
guint id = gedit_message_bus_connect(GEDIT_MESSAGE_BUS(self->obj),
domain,
name,
pygedit_message_bus_connect_cb,
(gpointer)cunote,
pygedit_custom_destroy_notify);
return PyLong_FromUnsignedLong(id);
}
%%
override gedit_message_bus_send kwargs
static PyObject *
_wrap_gedit_message_bus_send(PyGObject *self, PyObject *args, PyObject *kwargs)
{
/* create a new message object */
GeditMessage *message;
GeditMessageBus *bus = GEDIT_MESSAGE_BUS(self->obj);
message = _helper_wrap_create_message(bus, args, kwargs);
if (!message)
return NULL;
gedit_message_bus_send_message(bus, message);
g_object_unref (message);
Py_INCREF(Py_None);
return Py_None;
}
%%
override gedit_message_bus_send_sync kwargs
static PyObject *
_wrap_gedit_message_bus_send_sync(PyGObject *self, PyObject *args, PyObject *kwargs)
{
/* create a new message object */
GeditMessage *message;
GeditMessageBus *bus = GEDIT_MESSAGE_BUS(self->obj);
message = _helper_wrap_create_message(bus, args, kwargs);
if (!message)
return NULL;
gedit_message_bus_send_message_sync(bus, message);
return pygobject_new((GObject *)message);
}
%%
override-slot GeditMessage.tp_getattro
static PyObject *
_wrap_gedit_message_tp_getattro(PyObject *self, PyObject *attrname)
{
GeditMessage *message = GEDIT_MESSAGE(((PyGObject *)self)->obj);
GeditMessageType *type;
gchar *name = _helper_wrap_get_string (attrname);
gboolean exists;
gboolean intype;
PyObject *ret;
if (name == NULL)
{
PyErr_SetString(PyExc_TypeError, "attr name somehow not a string");
return NULL;
}
g_object_get (message, "type", &type, NULL);
intype = gedit_message_type_lookup (type, name) != G_TYPE_INVALID;
gedit_message_type_unref (type);
exists = gedit_message_has_key (message, name);
if (!intype)
{
ret = PyObject_GenericGetAttr(self, attrname);
}
else if (exists)
{
GValue value = { 0, };
gedit_message_get_value (message, name, &value);
ret = pyg_value_as_pyobject(&value, TRUE);
g_value_unset (&value);
}
else
{
Py_INCREF(Py_None);
ret = Py_None;
}
g_free (name);
return ret;
}
%%
override-slot GeditMessage.tp_setattro
static int
_wrap_gedit_message_tp_setattro(PyObject *self, PyObject *attrname, PyObject *value)
{
GeditMessage *message = GEDIT_MESSAGE(((PyGObject *)self)->obj);
if (!_helper_wrap_message_set_value(message, attrname, value))
{
return PyObject_GenericSetAttr(self, attrname, value);
}
else
{
return 1;
}
}

View File

@@ -0,0 +1,193 @@
%%
headers
#include <gedit/gedit-plugin.h>
#include <gedit/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 *)(((PyObject *)self)->ob_type);
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_PLUGIN_PYTHON_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 *)(((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_PLUGIN_PYTHON_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 *)(((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_PLUGIN_PYTHON_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 *)(((PyObject *)self)->ob_type);
klass = g_type_class_ref (pyg_type_from_object (cls));
if (GEDIT_IS_PLUGIN_PYTHON_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 *)(((PyObject *)self)->ob_type);
klass = g_type_class_ref(pyg_type_from_object (cls));
if (GEDIT_IS_PLUGIN_PYTHON_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);
}

View File

@@ -0,0 +1,67 @@
;; -*- scheme -*-
;; From ../../gedit/gedit-utils.h
(define-function uri_has_writable_scheme
(c-name "gedit_utils_uri_has_writable_scheme")
(return-type "gboolean")
(parameters
'("const-gchar*" "uri")
)
)
(define-function uri_has_file_scheme
(c-name "gedit_utils_uri_has_file_scheme")
(return-type "gboolean")
(parameters
'("const-gchar*" "uri")
)
)
(define-function uri_exists
(c-name "gedit_utils_uri_exists")
(return-type "gboolean")
(parameters
'("const-gchar*" "text_uri")
)
)
(define-function uri_is_valid
(c-name "gedit_utils_is_valid_uri")
(return-type "gboolean")
(parameters
'("const-gchar*" "uri")
)
)
(define-function uri_get_dirname
(c-name "gedit_utils_uri_get_dirname")
(return-type "gchar*")
(parameters
'("const-char*" "uri")
)
)
(define-function menu_position_under_widget
(c-name "gedit_utils_menu_position_under_widget")
(return-type "none")
(parameters
'("GtkMenu*" "menu")
'("gint*" "x")
'("gint*" "y")
'("gboolean*" "push_in")
'("gpointer" "user_data")
)
)
(define-function menu_position_under_tree_view
(c-name "gedit_utils_menu_position_under_tree_view")
(return-type "none")
(parameters
'("GtkMenu*" "menu")
'("gint*" "x")
'("gint*" "y")
'("gboolean*" "push_in")
'("gpointer" "user_data")
)
)

View File

@@ -0,0 +1,85 @@
%%
headers
#define NO_IMPORT_PYGOBJECT
#define NO_IMPORT_PYGTK
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include "gedit-utils.h"
void pygeditutils_register_classes (PyObject *d);
void pygeditutils_add_constants (PyObject *module, const gchar *strip_prefix);
%%
modulename gedit.utils
%%
import gtk.Widget as PyGtkWidget_Type
import gtk.TreeView as PyGtkTreeView_Type
import gtk.Menu as PyGtkMenu_Type
%%
ignore-glob
_*
%%
override gedit_utils_menu_position_under_widget kwargs
static PyObject *
_wrap_gedit_utils_menu_position_under_widget (PyObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "menu", "widget", NULL };
PyObject *py_menu, *py_widget;
GtkMenu *menu;
GtkWidget *widget;
gint x, y;
gboolean push_in;
PyObject *tuple;
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
"O!O!", kwlist,
&PyGtkMenu_Type, &py_menu,
&PyGtkWidget_Type, &py_widget))
return NULL;
menu = GTK_MENU (pygobject_get (py_menu));
widget = GTK_WIDGET (pygobject_get (py_widget));
gedit_utils_menu_position_under_widget (menu, &x, &y, &push_in, widget);
tuple = PyTuple_New (3);
PyTuple_SetItem (tuple, 0, PyInt_FromLong (x));
PyTuple_SetItem (tuple, 1, PyInt_FromLong (y));
PyTuple_SetItem (tuple, 2, PyBool_FromLong (push_in));
return tuple;
}
%%
override gedit_utils_menu_position_under_tree_view kwargs
static PyObject *
_wrap_gedit_utils_menu_position_under_tree_view (PyObject *self,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "menu", "tree_view", NULL };
PyObject *py_menu, *py_view;
GtkMenu *menu;
GtkTreeView *view;
gint x, y;
gboolean push_in;
PyObject *tuple;
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
"O!O!", kwlist,
&PyGtkMenu_Type, &py_menu,
&PyGtkTreeView_Type, &py_view))
return NULL;
menu = GTK_MENU (pygobject_get (py_menu));
view = GTK_TREE_VIEW (pygobject_get (py_view));
gedit_utils_menu_position_under_widget (menu, &x, &y, &push_in, view);
tuple = PyTuple_New (3);
PyTuple_SetItem (tuple, 0, PyInt_FromLong (x));
PyTuple_SetItem (tuple, 1, PyInt_FromLong (y));
PyTuple_SetItem (tuple, 2, PyBool_FromLong (push_in));
return tuple;
}

View File

@@ -0,0 +1,719 @@
/*
* gedit-plugin-loader-python.c
* This file is part of gedit
*
* Copyright (C) 2008 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gedit-plugin-loader-python.h"
#include "gedit-plugin-python.h"
#include <gedit/gedit-object-module.h>
#define NO_IMPORT_PYGOBJECT
#define NO_IMPORT_PYGTK
#include <Python.h>
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include <signal.h>
#include "config.h"
#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif
#define GEDIT_PLUGIN_LOADER_PYTHON_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_PLUGIN_LOADER_PYTHON, GeditPluginLoaderPythonPrivate))
struct _GeditPluginLoaderPythonPrivate
{
GHashTable *loaded_plugins;
guint idle_gc;
gboolean init_failed;
};
typedef struct
{
PyObject *type;
PyObject *instance;
gchar *path;
} PythonInfo;
static void gedit_plugin_loader_iface_init (gpointer g_iface, gpointer iface_data);
/* 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[];
/* We retreive this to check for correct class hierarchy */
static PyTypeObject *PyGeditPlugin_Type;
GEDIT_PLUGIN_LOADER_REGISTER_TYPE (GeditPluginLoaderPython, gedit_plugin_loader_python, G_TYPE_OBJECT, gedit_plugin_loader_iface_init);
static PyObject *
find_python_plugin_type (GeditPluginInfo *info,
PyObject *pymodule)
{
PyObject *locals, *key, *value;
Py_ssize_t pos = 0;
locals = PyModule_GetDict (pymodule);
while (PyDict_Next (locals, &pos, &key, &value))
{
if (!PyType_Check(value))
continue;
if (PyObject_IsSubclass (value, (PyObject*) PyGeditPlugin_Type))
return value;
}
g_warning ("No GeditPlugin derivative found in Python plugin '%s'",
gedit_plugin_info_get_name (info));
return NULL;
}
static GeditPlugin *
new_plugin_from_info (GeditPluginLoaderPython *loader,
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;
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;
}
pygobject = (PyGObject *)pyobject;
if (pygobject->obj != NULL)
{
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;
/* make sure to register the python instance for the GeditPluginPython
object to it can wrap the virtual gedit plugin funcs back to python */
_gedit_plugin_python_set_instance (GEDIT_PLUGIN_PYTHON (instance), (PyObject *)pygobject);
/* we return a reference here because the other is owned by python */
return GEDIT_PLUGIN (g_object_ref (instance));
}
static GeditPlugin *
add_python_info (GeditPluginLoaderPython *loader,
GeditPluginInfo *info,
PyObject *module,
const gchar *path,
PyObject *type)
{
PythonInfo *pyinfo;
pyinfo = g_new (PythonInfo, 1);
pyinfo->path = g_strdup (path);
pyinfo->type = type;
Py_INCREF (pyinfo->type);
g_hash_table_insert (loader->priv->loaded_plugins, info, pyinfo);
return new_plugin_from_info (loader, info);
}
static const gchar *
gedit_plugin_loader_iface_get_id (void)
{
return "Python";
}
static GeditPlugin *
gedit_plugin_loader_iface_load (GeditPluginLoader *loader,
GeditPluginInfo *info,
const gchar *path)
{
GeditPluginLoaderPython *pyloader = GEDIT_PLUGIN_LOADER_PYTHON (loader);
PyObject *main_module, *main_locals, *pytype;
PyObject *pymodule, *fromlist;
gchar *module_name;
GeditPlugin *result;
if (pyloader->priv->init_failed)
{
g_warning ("Cannot load python plugin Python '%s' since gedit was"
"not able to initialize the Python interpreter.",
gedit_plugin_info_get_name (info));
return NULL;
}
/* see if py definition for the plugin is already loaded */
result = new_plugin_from_info (pyloader, info);
if (result != NULL)
return result;
main_module = PyImport_AddModule ("gedit.plugins");
if (main_module == NULL)
{
g_warning ("Could not get gedit.plugins.");
return NULL;
}
/* If we have a special path, we register it */
if (path != NULL)
{
PyObject *sys_path = PySys_GetObject ("path");
PyObject *pypath = PyString_FromString (path);
if (PySequence_Contains (sys_path, pypath) == 0)
PyList_Insert (sys_path, 0, pypath);
Py_DECREF (pypath);
}
main_locals = PyModule_GetDict (main_module);
/* we need a fromlist to be able to import modules with a '.' in the
name. */
fromlist = PyTuple_New(0);
module_name = g_strdup (gedit_plugin_info_get_module_name (info));
pymodule = PyImport_ImportModuleEx (module_name,
main_locals,
main_locals,
fromlist);
Py_DECREF(fromlist);
if (!pymodule)
{
g_free (module_name);
PyErr_Print ();
return NULL;
}
PyDict_SetItemString (main_locals, module_name, pymodule);
g_free (module_name);
pytype = find_python_plugin_type (info, pymodule);
if (pytype)
return add_python_info (pyloader, info, pymodule, path, pytype);
return NULL;
}
static void
gedit_plugin_loader_iface_unload (GeditPluginLoader *loader,
GeditPluginInfo *info)
{
GeditPluginLoaderPython *pyloader = GEDIT_PLUGIN_LOADER_PYTHON (loader);
PythonInfo *pyinfo;
PyGILState_STATE state;
pyinfo = (PythonInfo *)g_hash_table_lookup (pyloader->priv->loaded_plugins, info);
if (!pyinfo)
return;
state = pyg_gil_state_ensure ();
Py_XDECREF (pyinfo->instance);
pyg_gil_state_release (state);
pyinfo->instance = NULL;
}
static gboolean
run_gc (GeditPluginLoaderPython *loader)
{
while (PyGC_Collect ())
;
loader->priv->idle_gc = 0;
return FALSE;
}
static void
gedit_plugin_loader_iface_garbage_collect (GeditPluginLoader *loader)
{
GeditPluginLoaderPython *pyloader;
if (!Py_IsInitialized())
return;
pyloader = GEDIT_PLUGIN_LOADER_PYTHON (loader);
/*
* We both run the GC right now and we schedule
* a further collection in the main loop.
*/
while (PyGC_Collect ())
;
if (pyloader->priv->idle_gc == 0)
pyloader->priv->idle_gc = g_idle_add ((GSourceFunc)run_gc, pyloader);
}
static void
gedit_plugin_loader_iface_init (gpointer g_iface,
gpointer iface_data)
{
GeditPluginLoaderInterface *iface = (GeditPluginLoaderInterface *)g_iface;
iface->get_id = gedit_plugin_loader_iface_get_id;
iface->load = gedit_plugin_loader_iface_load;
iface->unload = gedit_plugin_loader_iface_unload;
iface->garbage_collect = gedit_plugin_loader_iface_garbage_collect;
}
static void
gedit_python_shutdown (GeditPluginLoaderPython *loader)
{
if (!Py_IsInitialized ())
return;
if (loader->priv->idle_gc != 0)
{
g_source_remove (loader->priv->idle_gc);
loader->priv->idle_gc = 0;
}
while (PyGC_Collect ())
;
Py_Finalize ();
}
/* C equivalent of
* import pygtk
* pygtk.require ("2.0")
*/
static gboolean
gedit_check_pygtk2 (void)
{
PyObject *pygtk, *mdict, *require;
/* pygtk.require("2.0") */
pygtk = PyImport_ImportModule ("pygtk");
if (pygtk == NULL)
{
g_warning ("Error initializing Python interpreter: could not import pygtk.");
return FALSE;
}
mdict = PyModule_GetDict (pygtk);
require = PyDict_GetItemString (mdict, "require");
PyObject_CallObject (require,
Py_BuildValue ("(S)", PyString_FromString ("2.0")));
if (PyErr_Occurred())
{
g_warning ("Error initializing Python interpreter: pygtk 2 is required.");
return FALSE;
}
return TRUE;
}
/* Note: the following two functions are needed because
* init_pyobject and init_pygtk which are *macros* which in case
* case of error set the PyErr and then make the calling
* function return behind our back.
* It's up to the caller to check the result with PyErr_Occurred()
*/
static void
gedit_init_pygobject (void)
{
init_pygobject_check (2, 11, 5); /* FIXME: get from config */
}
static void
gedit_init_pygtk (void)
{
PyObject *gtk, *mdict, *version, *required_version;
init_pygtk ();
/* there isn't init_pygtk_check(), do the version
* check ourselves */
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;
}
required_version = Py_BuildValue ("(iii)", 2, 4, 0); /* FIXME */
if (PyObject_Compare (version, required_version) == -1)
{
PyErr_SetString (PyExc_ImportError,
"PyGObject version too old");
Py_DECREF (required_version);
return;
}
Py_DECREF (required_version);
}
static void
old_gtksourceview_init (void)
{
PyErr_SetString(PyExc_ImportError,
"gtksourceview module not allowed, use gtksourceview2");
}
static void
gedit_init_pygtksourceview (void)
{
PyObject *gtksourceview, *mdict, *version, *required_version;
gtksourceview = PyImport_ImportModule("gtksourceview2");
if (gtksourceview == NULL)
{
PyErr_SetString (PyExc_ImportError,
"could not import gtksourceview");
return;
}
mdict = PyModule_GetDict (gtksourceview);
version = PyDict_GetItemString (mdict, "pygtksourceview2_version");
if (!version)
{
PyErr_SetString (PyExc_ImportError,
"PyGtkSourceView version too old");
return;
}
required_version = Py_BuildValue ("(iii)", 0, 8, 0); /* FIXME */
if (PyObject_Compare (version, required_version) == -1)
{
PyErr_SetString (PyExc_ImportError,
"PyGtkSourceView version too old");
Py_DECREF (required_version);
return;
}
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);
}
static gboolean
gedit_python_init (GeditPluginLoaderPython *loader)
{
PyObject *mdict, *tuple;
PyObject *gedit, *geditutils, *geditcommands, *geditplugins;
PyObject *gettext, *install, *gettext_args;
//char *argv[] = { "gedit", NULL };
char *argv[] = { GEDIT_PLUGINS_LIBS_DIR, NULL };
#ifdef HAVE_SIGACTION
gint res;
struct sigaction old_sigint;
#endif
if (loader->priv->init_failed)
{
/* We already failed to initialized Python, don't need to
* retry again */
return FALSE;
}
if (Py_IsInitialized ())
{
/* Python has already been successfully initialized */
return TRUE;
}
/* We are trying to initialize Python for the first time,
set init_failed to FALSE only if the entire initialization process
ends with success */
loader->priv->init_failed = TRUE;
/* Hack to make python not overwrite SIGINT: this is needed to avoid
* the crash reported on bug #326191 */
/* CHECK: can't we use Py_InitializeEx instead of Py_Initialize in order
to avoid to manage signal handlers ? - Paolo (Dec. 31, 2006) */
#ifdef HAVE_SIGACTION
/* Save old handler */
res = sigaction (SIGINT, NULL, &old_sigint);
if (res != 0)
{
g_warning ("Error initializing Python interpreter: cannot get "
"handler to SIGINT signal (%s)",
g_strerror (errno));
return FALSE;
}
#endif
/* Python initialization */
Py_Initialize ();
#ifdef HAVE_SIGACTION
/* Restore old handler */
res = sigaction (SIGINT, &old_sigint, NULL);
if (res != 0)
{
g_warning ("Error initializing Python interpreter: cannot restore "
"handler to SIGINT signal (%s).",
g_strerror (errno));
goto python_init_error;
}
#endif
PySys_SetArgv (1, argv);
if (!gedit_check_pygtk2 ())
{
/* Warning message already printed in check_pygtk2 */
goto python_init_error;
}
/* import gobject */
gedit_init_pygobject ();
if (PyErr_Occurred ())
{
g_warning ("Error initializing Python interpreter: could not import pygobject.");
goto python_init_error;
}
/* import gtk */
gedit_init_pygtk ();
if (PyErr_Occurred ())
{
g_warning ("Error initializing Python interpreter: could not import pygtk.");
goto python_init_error;
}
/* import gtksourceview */
gedit_init_pygtksourceview ();
if (PyErr_Occurred ())
{
PyErr_Print ();
g_warning ("Error initializing Python interpreter: could not import pygtksourceview.");
goto python_init_error;
}
/* import gedit */
gedit = Py_InitModule ("gedit", pygedit_functions);
mdict = PyModule_GetDict (gedit);
pygedit_register_classes (mdict);
pygedit_add_constants (gedit, "GEDIT_");
/* gedit version */
tuple = Py_BuildValue("(iii)",
GEDIT_MAJOR_VERSION,
GEDIT_MINOR_VERSION,
GEDIT_MICRO_VERSION);
PyDict_SetItemString(mdict, "version", tuple);
Py_DECREF(tuple);
/* Retrieve the Python type for gedit.Plugin */
PyGeditPlugin_Type = (PyTypeObject *) PyDict_GetItemString (mdict, "Plugin");
if (PyGeditPlugin_Type == NULL)
{
PyErr_Print ();
goto python_init_error;
}
/* import gedit.utils */
geditutils = Py_InitModule ("gedit.utils", pygeditutils_functions);
PyDict_SetItemString (mdict, "utils", geditutils);
/* import gedit.commands */
geditcommands = Py_InitModule ("gedit.commands", pygeditcommands_functions);
PyDict_SetItemString (mdict, "commands", geditcommands);
/* initialize empty gedit.plugins module */
geditplugins = Py_InitModule ("gedit.plugins", NULL);
PyDict_SetItemString (mdict, "plugins", geditplugins);
mdict = PyModule_GetDict (geditutils);
pygeditutils_register_classes (mdict);
mdict = PyModule_GetDict (geditcommands);
pygeditcommands_register_classes (mdict);
/* i18n support */
gettext = PyImport_ImportModule ("gettext");
if (gettext == NULL)
{
g_warning ("Error initializing Python interpreter: could not import gettext.");
goto python_init_error;
}
mdict = PyModule_GetDict (gettext);
install = PyDict_GetItemString (mdict, "install");
gettext_args = Py_BuildValue ("ss", GETTEXT_PACKAGE, GEDIT_LOCALEDIR);
PyObject_CallObject (install, gettext_args);
Py_DECREF (gettext_args);
/* Python has been successfully initialized */
loader->priv->init_failed = FALSE;
return TRUE;
python_init_error:
g_warning ("Please check the installation of all the Python related packages required "
"by gedit and try again.");
PyErr_Clear ();
gedit_python_shutdown (loader);
return FALSE;
}
static void
gedit_plugin_loader_python_finalize (GObject *object)
{
GeditPluginLoaderPython *pyloader = GEDIT_PLUGIN_LOADER_PYTHON (object);
g_hash_table_destroy (pyloader->priv->loaded_plugins);
gedit_python_shutdown (pyloader);
G_OBJECT_CLASS (gedit_plugin_loader_python_parent_class)->finalize (object);
}
static void
gedit_plugin_loader_python_class_init (GeditPluginLoaderPythonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gedit_plugin_loader_python_finalize;
g_type_class_add_private (object_class, sizeof (GeditPluginLoaderPythonPrivate));
}
static void
gedit_plugin_loader_python_class_finalize (GeditPluginLoaderPythonClass *klass)
{
}
static void
destroy_python_info (PythonInfo *info)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
Py_XDECREF (info->type);
pyg_gil_state_release (state);
g_free (info->path);
g_free (info);
}
static void
gedit_plugin_loader_python_init (GeditPluginLoaderPython *self)
{
self->priv = GEDIT_PLUGIN_LOADER_PYTHON_GET_PRIVATE (self);
/* initialize python interpreter */
gedit_python_init (self);
/* loaded_plugins maps GeditPluginInfo to a PythonInfo */
self->priv->loaded_plugins = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
(GDestroyNotify)destroy_python_info);
}
GeditPluginLoaderPython *
gedit_plugin_loader_python_new ()
{
GObject *loader = g_object_new (GEDIT_TYPE_PLUGIN_LOADER_PYTHON, NULL);
return GEDIT_PLUGIN_LOADER_PYTHON (loader);
}

View File

@@ -0,0 +1,61 @@
/*
* gedit-plugin-loader-python.h
* This file is part of gedit
*
* Copyright (C) 2008 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GEDIT_PLUGIN_LOADER_PYTHON_H__
#define __GEDIT_PLUGIN_LOADER_PYTHON_H__
#include <gedit/gedit-plugin-loader.h>
G_BEGIN_DECLS
#define GEDIT_TYPE_PLUGIN_LOADER_PYTHON (gedit_plugin_loader_python_get_type ())
#define GEDIT_PLUGIN_LOADER_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_PLUGIN_LOADER_PYTHON, GeditPluginLoaderPython))
#define GEDIT_PLUGIN_LOADER_PYTHON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_PLUGIN_LOADER_PYTHON, GeditPluginLoaderPython const))
#define GEDIT_PLUGIN_LOADER_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_PLUGIN_LOADER_PYTHON, GeditPluginLoaderPythonClass))
#define GEDIT_IS_PLUGIN_LOADER_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_PLUGIN_LOADER_PYTHON))
#define GEDIT_IS_PLUGIN_LOADER_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_PLUGIN_LOADER_PYTHON))
#define GEDIT_PLUGIN_LOADER_PYTHON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_PLUGIN_LOADER_PYTHON, GeditPluginLoaderPythonClass))
typedef struct _GeditPluginLoaderPython GeditPluginLoaderPython;
typedef struct _GeditPluginLoaderPythonClass GeditPluginLoaderPythonClass;
typedef struct _GeditPluginLoaderPythonPrivate GeditPluginLoaderPythonPrivate;
struct _GeditPluginLoaderPython {
GObject parent;
GeditPluginLoaderPythonPrivate *priv;
};
struct _GeditPluginLoaderPythonClass {
GObjectClass parent_class;
};
GType gedit_plugin_loader_python_get_type (void) G_GNUC_CONST;
GeditPluginLoaderPython *gedit_plugin_loader_python_new(void);
/* All the loaders must implement this function */
G_MODULE_EXPORT GType register_gedit_plugin_loader (GTypeModule * module);
G_END_DECLS
#endif /* __GEDIT_PLUGIN_LOADER_PYTHON_H__ */

View File

@@ -0,0 +1,281 @@
/*
* gedit-plugin-python.c
* This file is part of gedit
*
* Copyright (C) 2005 Raphael Slinckx
* Copyright (C) 2008 Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include "gedit-plugin-python.h"
#include <gedit/gedit-plugin.h>
#include <gedit/gedit-debug.h>
#include <pygobject.h>
#include <string.h>
#define GEDIT_PLUGIN_PYTHON_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_PLUGIN_PYTHON, GeditPluginPythonPrivate))
static GObjectClass *parent_class;
struct _GeditPluginPythonPrivate
{
PyObject *instance;
};
static void gedit_plugin_python_class_init (GeditPluginPythonClass *klass);
static void gedit_plugin_python_init (GeditPluginPython *plugin);
G_DEFINE_TYPE (GeditPluginPython, gedit_plugin_python, GEDIT_TYPE_PLUGIN)
static PyObject *
call_python_method (GeditPluginPythonPrivate *priv,
GeditWindow *window,
gchar *method)
{
PyObject *py_ret = NULL;
g_return_val_if_fail (PyObject_HasAttrString (priv->instance, method), NULL);
if (window == NULL)
{
py_ret = PyObject_CallMethod (priv->instance,
method,
NULL);
}
else
{
py_ret = PyObject_CallMethod (priv->instance,
method,
"(N)",
pygobject_new (G_OBJECT (window)));
}
if (!py_ret)
PyErr_Print ();
return py_ret;
}
static gboolean
check_py_object_is_gtk_widget (PyObject *py_obj)
{
static PyTypeObject *_PyGtkWidget_Type = NULL;
if (_PyGtkWidget_Type == NULL)
{
PyObject *module;
if ((module = PyImport_ImportModule ("gtk")))
{
PyObject *moddict = PyModule_GetDict (module);
_PyGtkWidget_Type = (PyTypeObject *) PyDict_GetItemString (moddict, "Widget");
}
if (_PyGtkWidget_Type == NULL)
{
PyErr_SetString(PyExc_TypeError, "could not find Python gtk widget type");
PyErr_Print();
return FALSE;
}
}
return PyObject_TypeCheck (py_obj, _PyGtkWidget_Type) ? TRUE : FALSE;
}
static void
impl_update_ui (GeditPlugin *plugin,
GeditWindow *window)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPluginPythonPrivate *priv = GEDIT_PLUGIN_PYTHON(plugin)->priv;
if (PyObject_HasAttrString (priv->instance, "update_ui"))
{
PyObject *py_ret = call_python_method (priv, window, "update_ui");
if (py_ret)
{
Py_XDECREF (py_ret);
}
}
else
GEDIT_PLUGIN_CLASS (parent_class)->update_ui (plugin, window);
pyg_gil_state_release (state);
}
static void
impl_deactivate (GeditPlugin *plugin,
GeditWindow *window)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPluginPythonPrivate *priv = GEDIT_PLUGIN_PYTHON(plugin)->priv;
if (PyObject_HasAttrString (priv->instance, "deactivate"))
{
PyObject *py_ret = call_python_method (priv, window, "deactivate");
if (py_ret)
{
Py_XDECREF (py_ret);
}
}
else
GEDIT_PLUGIN_CLASS (parent_class)->deactivate (plugin, window);
pyg_gil_state_release (state);
}
static void
impl_activate (GeditPlugin *plugin,
GeditWindow *window)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPluginPythonPrivate *priv = GEDIT_PLUGIN_PYTHON(plugin)->priv;
if (PyObject_HasAttrString (priv->instance, "activate"))
{
PyObject *py_ret = call_python_method (priv, window, "activate");
if (py_ret)
{
Py_XDECREF (py_ret);
}
}
else
GEDIT_PLUGIN_CLASS (parent_class)->activate (plugin, window);
pyg_gil_state_release (state);
}
static GtkWidget *
impl_create_configure_dialog (GeditPlugin *plugin)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPluginPythonPrivate *priv = GEDIT_PLUGIN_PYTHON(plugin)->priv;
GtkWidget *ret = NULL;
if (PyObject_HasAttrString (priv->instance, "create_configure_dialog"))
{
PyObject *py_ret = call_python_method (priv, NULL, "create_configure_dialog");
if (py_ret)
{
if (check_py_object_is_gtk_widget (py_ret))
{
ret = GTK_WIDGET (pygobject_get (py_ret));
g_object_ref (ret);
}
else
{
PyErr_SetString(PyExc_TypeError, "return value for create_configure_dialog is not a GtkWidget");
PyErr_Print();
}
Py_DECREF (py_ret);
}
}
else
ret = GEDIT_PLUGIN_CLASS (parent_class)->create_configure_dialog (plugin);
pyg_gil_state_release (state);
return ret;
}
static gboolean
impl_is_configurable (GeditPlugin *plugin)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
GeditPluginPythonPrivate *priv = GEDIT_PLUGIN_PYTHON(plugin)->priv;
PyObject *dict = priv->instance->ob_type->tp_dict;
gboolean result;
if (dict == NULL)
result = FALSE;
else if (!PyDict_Check(dict))
result = FALSE;
else
result = PyDict_GetItemString(dict, "create_configure_dialog") != NULL;
pyg_gil_state_release (state);
return result;
}
void
_gedit_plugin_python_set_instance (GeditPluginPython *plugin,
PyObject *instance)
{
PyGILState_STATE state = pyg_gil_state_ensure ();
/* we don't increment the instance here because we are the instance,
when it dies, we also die */
plugin->priv->instance = instance;
pyg_gil_state_release (state);
}
PyObject *
_gedit_plugin_python_get_instance (GeditPluginPython *plugin)
{
return plugin->priv->instance;
}
static void
gedit_plugin_python_init (GeditPluginPython *plugin)
{
plugin->priv = GEDIT_PLUGIN_PYTHON_GET_PRIVATE(plugin);
gedit_debug_message (DEBUG_PLUGINS, "Creating Python plugin instance");
plugin->priv->instance = 0;
}
static void
gedit_plugin_python_finalize (GObject *object)
{
PyGILState_STATE state;
gedit_debug_message (DEBUG_PLUGINS, "Finalizing Python plugin instance");
state = pyg_gil_state_ensure ();
Py_XDECREF (GEDIT_PLUGIN_PYTHON(object)->priv->instance);
pyg_gil_state_release (state);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gedit_plugin_python_class_init (GeditPluginPythonClass *klass)
{
GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (GeditPluginPythonPrivate));
G_OBJECT_CLASS (klass)->finalize = gedit_plugin_python_finalize;
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;
plugin_class->is_configurable = impl_is_configurable;
}

View File

@@ -0,0 +1,88 @@
/*
* gedit-plugin-python.h
* This file is part of gedit
*
* Copyright (C) 2005 - Raphael Slinckx
* Copyright (C) 2008 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GEDIT_PLUGIN_PYTHON_H__
#define __GEDIT_PLUGIN_PYTHON_H__
#define NO_IMPORT_PYGOBJECT
#include <glib-object.h>
#include <pygobject.h>
#include <gedit/gedit-plugin.h>
G_BEGIN_DECLS
/*
* Type checking and casting macros
*/
#define GEDIT_TYPE_PLUGIN_PYTHON (gedit_plugin_python_get_type())
#define GEDIT_PLUGIN_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GEDIT_TYPE_PLUGIN_PYTHON, GeditPluginPython))
#define GEDIT_PLUGIN_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GEDIT_TYPE_PLUGIN_PYTHON, GeditPluginPythonClass))
#define GEDIT_IS_PLUGIN_PYTHON(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GEDIT_TYPE_PLUGIN_PYTHON))
#define GEDIT_IS_PLUGIN_PYTHON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_PLUGIN_PYTHON))
#define GEDIT_PLUGIN_PYTHON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GEDIT_TYPE_PLUGIN_PYTHON, GeditPluginPythonClass))
/* Private structure type */
typedef struct _GeditPluginPythonPrivate GeditPluginPythonPrivate;
/*
* Main object structure
*/
typedef struct _GeditPluginPython GeditPluginPython;
struct _GeditPluginPython
{
GeditPlugin parent;
/*< private > */
GeditPluginPythonPrivate *priv;
};
/*
* Class definition
*/
typedef struct _GeditPluginPythonClass GeditPluginPythonClass;
struct _GeditPluginPythonClass
{
GeditPluginClass parent_class;
};
/*
* Public methods
*/
GType gedit_plugin_python_get_type (void) G_GNUC_CONST;
/*
* Private methods
*/
void _gedit_plugin_python_set_instance (GeditPluginPython *plugin,
PyObject *instance);
PyObject *_gedit_plugin_python_get_instance (GeditPluginPython *plugin);
G_END_DECLS
#endif /* __GEDIT_PLUGIN_PYTHON_H__ */