mirror of
https://gitlab.gnome.org/GNOME/eog
synced 2024-10-18 22:14:48 +00:00
Added Python support in the plugin system.
2007-07-04 Lucas Rocha <lucasr@gnome.org> Added Python support in the plugin system. * Makefile.am, bindings/Makefile.am, bindings/python/Makefile.am, bindings/python/eog.defs, bindings/python/eog.override: python bindings for plugin API. A lot of improvement needed here. * configure.ac: check for Python libraries in order to activate or deactivate Python support. * src/Makefile.am, data/eog.pc.in: includedir is now @includedir@/eog-API_VERSION to allow future parallel deployments. * src/eog-python-*: * src/eog-window.c (eog_window_transparency_changed_cb, eog_window_trans_color_changed_cb), src/eog-scroll-view.[ch] (paint_rectangle, eog_scroll_view_set_transparency, eog_scroll_view_init): adapt enum names to be more friendly for bindings. svn path=/trunk/; revision=3859
This commit is contained in:
parent
d55cedf800
commit
fc78287604
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2007-07-04 Lucas Rocha <lucasr@gnome.org>
|
||||
|
||||
Added Python support in the plugin system.
|
||||
|
||||
* Makefile.am, bindings/Makefile.am, bindings/python/Makefile.am,
|
||||
bindings/python/eog.defs, bindings/python/eog.override: python
|
||||
bindings for plugin API. A lot of improvement needed here.
|
||||
* configure.ac: check for Python libraries in order to activate or
|
||||
deactivate Python support.
|
||||
* src/Makefile.am, data/eog.pc.in: includedir is now
|
||||
@includedir@/eog-API_VERSION to allow future parallel deployments.
|
||||
* src/eog-python-*:
|
||||
* src/eog-window.c (eog_window_transparency_changed_cb,
|
||||
eog_window_trans_color_changed_cb), src/eog-scroll-view.[ch] (paint_rectangle,
|
||||
eog_scroll_view_set_transparency, eog_scroll_view_init): adapt enum
|
||||
names to be more friendly for bindings.
|
||||
|
||||
2007-07-03 Jaap Haitsma <jaap@haitsma.org>
|
||||
|
||||
* cut-n-paste/toolbar-editor/update-toolbareditor-from-libegg.sh: added
|
||||
|
|
|
@ -2,7 +2,7 @@ if ENABLE_JPEG
|
|||
jpeg_DIRS = jpegutils
|
||||
endif
|
||||
|
||||
SUBDIRS = $(jpeg_DIRS) cut-n-paste src po help data
|
||||
SUBDIRS = $(jpeg_DIRS) cut-n-paste bindings src po help data
|
||||
|
||||
EXTRA_DIST = \
|
||||
HACKING \
|
||||
|
|
5
bindings/Makefile.am
Normal file
5
bindings/Makefile.am
Normal file
|
@ -0,0 +1,5 @@
|
|||
SUBDIRS =
|
||||
|
||||
if ENABLE_PYTHON
|
||||
SUBDIRS += python
|
||||
endif
|
74
bindings/python/Makefile.am
Normal file
74
bindings/python/Makefile.am
Normal file
|
@ -0,0 +1,74 @@
|
|||
noinst_LTLIBRARIES = \
|
||||
eog.la
|
||||
|
||||
nodist_eog_la_SOURCES = \
|
||||
eog.c
|
||||
|
||||
eog_la_LDFLAGS = \
|
||||
-module -avoid-version
|
||||
|
||||
eog_la_LIBADD = \
|
||||
$(PYTHON_LIB_LOC) \
|
||||
$(PYTHON_LIBS) \
|
||||
$(PYTHON_EXTRA_LIBS) \
|
||||
$(PYGTK_LIBS)
|
||||
|
||||
eog_la_CFLAGS = \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_builddir) \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_builddir)/src \
|
||||
-I$(top_srcdir)/cut-n-paste/toolbar-editor \
|
||||
$(EOG_CFLAGS) \
|
||||
$(NO_STRICT_ALIASING_CFLAGS) \
|
||||
$(PYGTK_CFLAGS) \
|
||||
$(PYTHON_CFLAGS) \
|
||||
$(AM_CFLAGS)
|
||||
|
||||
$(top_builddir)/src/eog-enum-types.h:
|
||||
cd $(top_builddir)/src && $(MAKE) eog-enum-types.h
|
||||
|
||||
eog.c: eog.defs eog.override $(top_builddir)/src/eog-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 \
|
||||
--override $*.override \
|
||||
--prefix py$* $(<F) ) > $@
|
||||
|
||||
BINDING_EOG_HEADERS_SRCDIR_IN = \
|
||||
src/eog-application.h \
|
||||
src/eog-window.h \
|
||||
src/eog-dialog.h \
|
||||
src/eog-properties-dialog.h \
|
||||
src/eog-message-area.h \
|
||||
src/eog-statusbar.h \
|
||||
src/eog-thumb-nav.h \
|
||||
src/eog-image.h \
|
||||
src/eog-scroll-view.h \
|
||||
src/eog-thumb-view.h \
|
||||
src/eog-list-store.h \
|
||||
src/eog-job-queue.h \
|
||||
src/eog-jobs.h \
|
||||
src/eog-plugin.h
|
||||
|
||||
BINDING_HEADERS_BUILDDIR_IN =
|
||||
|
||||
BINDING_EOG_HEADERS_SRCDIR := $(addprefix $(top_srcdir)/,$(BINDING_EOG_HEADERS_SRCDIR_IN))
|
||||
|
||||
BINDING_HEADERS_BUILDDIR := $(addprefix $(top_builddir)/,$(BINDING_HEADERS_BUILDDIR_IN))
|
||||
|
||||
regenerate-python-binding:
|
||||
$(PYGTK_H2DEF) $(sort $(BINDING_EOG_HEADERS_SRCDIR) $(BINDING_HEADERS_BUILDDIR)) > eog.defs.new
|
||||
|
||||
BUILT_SOURCES = \
|
||||
eog.c
|
||||
|
||||
EXTRA_DIST = \
|
||||
eog.override \
|
||||
eog.defs
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
dist-hook:
|
||||
cd $(distdir); rm -f $(BUILT_SOURCES)
|
1254
bindings/python/eog.defs
Normal file
1254
bindings/python/eog.defs
Normal file
File diff suppressed because it is too large
Load diff
125
bindings/python/eog.override
Normal file
125
bindings/python/eog.override
Normal file
|
@ -0,0 +1,125 @@
|
|||
%%
|
||||
headers
|
||||
#define NO_IMPORT_PYGOBJECT
|
||||
#include "pygobject.h"
|
||||
#include <pygtk/pygtk.h>
|
||||
|
||||
#include "eog-enum-types.h"
|
||||
#include "eog-application.h"
|
||||
#include "eog-window.h"
|
||||
#include "eog-dialog.h"
|
||||
#include "eog-properties-dialog.h"
|
||||
#include "eog-message-area.h"
|
||||
#include "eog-statusbar.h"
|
||||
#include "eog-thumb-nav.h"
|
||||
#include "eog-image.h"
|
||||
#include "eog-scroll-view.h"
|
||||
#include "eog-thumb-view.h"
|
||||
#include "eog-list-store.h"
|
||||
#include "eog-job-queue.h"
|
||||
#include "eog-jobs.h"
|
||||
#include "eog-plugin.h"
|
||||
|
||||
void pyeog_register_classes (PyObject *d);
|
||||
void pyeog_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;
|
||||
}
|
||||
%%
|
||||
modulename eog
|
||||
%%
|
||||
import gtk.Widget as PyGtkWidget_Type
|
||||
import gobject.GObject as PyGObject_Type
|
||||
import gtk.Window as PyGtkWindow_Type
|
||||
import gtk.Action as PyGtkAction_Type
|
||||
import gtk.Statusbar as PyGtkStatusbar_Type
|
||||
import gtk.Menu as PyGtkMenu_Type
|
||||
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
|
||||
import gtk.FileChooserDialog as PyGtkFileChooserDialog_Type
|
||||
import gtk.ListStore as PyGtkListStore_Type
|
||||
import gtk.HBox as PyGtkHBox_Type
|
||||
import gtk.Table as PyGtkTable_Type
|
||||
import gtk.IconView as PyGtkIconView_Type
|
||||
import gnomevfs.URI as PyGnomeVFSURI_Type
|
||||
%%
|
||||
ignore-glob
|
||||
*_get_type
|
||||
%%
|
||||
override eog_application_get_windows
|
||||
static PyObject *
|
||||
_wrap_eog_application_get_windows(PyGObject *self)
|
||||
{
|
||||
const GList *list;
|
||||
PyObject *py_list;
|
||||
|
||||
list = eog_application_get_windows (EOG_APPLICATION (self->obj));
|
||||
|
||||
py_list = _helper_wrap_gobject_glist (list);
|
||||
|
||||
return py_list;
|
||||
}
|
||||
%%
|
||||
override eog_application_open_uri_list kwargs
|
||||
static PyObject *
|
||||
_wrap_eog_application_open_uri_list (PyGObject *self,
|
||||
PyObject *args,
|
||||
PyObject *kwargs)
|
||||
{
|
||||
static char *kwlist[] = { "uri_list", NULL };
|
||||
PyObject *list, *item;
|
||||
GSList *glist = NULL;
|
||||
int len, i;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
|
||||
"O:EogApplication.open_uri_list", 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 (!PyString_Check (item)) {
|
||||
PyErr_SetString (PyExc_TypeError,
|
||||
"sequence item not a string");
|
||||
g_slist_free (glist);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
glist = g_slist_append (glist, g_strdup (PyString_AsString (item)));
|
||||
}
|
||||
|
||||
eog_application_open_uri_list (EOG_APPLICATION (self->obj), glist, GDK_CURRENT_TIME, 0, NULL);
|
||||
|
||||
g_slist_free (glist);
|
||||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
120
configure.ac
120
configure.ac
|
@ -1,9 +1,23 @@
|
|||
dnl Configure script for the EOG Image Viewer
|
||||
AC_PREREQ(2.59)
|
||||
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT([eog], [2.19.4], [http://bugzilla.gnome.org/enter_bug.cgi?product=eog], [eog])
|
||||
m4_define(eog_major_version, 2)
|
||||
m4_define(eog_minor_version, 19)
|
||||
m4_define(eog_micro_version, 4)
|
||||
m4_define(eog_version, eog_major_version.eog_minor_version.eog_micro_version)
|
||||
|
||||
AC_INIT([eog], eog_version, [http://bugzilla.gnome.org/enter_bug.cgi?product=eog], [eog])
|
||||
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
|
||||
|
||||
AC_DEFINE(EOG_MAJOR_VERSION, eog_major_version, [EOG major version])
|
||||
AC_SUBST(EOG_MAJOR_VERSION, eog_major_version)
|
||||
AC_DEFINE(EOG_MINOR_VERSION, eog_minor_version, [EOG minor version])
|
||||
AC_SUBST(EOG_MINOR_VERSION, eog_minor_version)
|
||||
AC_DEFINE(EOG_MICRO_VERSION, eog_micro_version, [EOG micro version])
|
||||
AC_SUBST(EOG_MICRO_VERSION, eog_micro_version)
|
||||
|
||||
EOG_API_VERSION=2.20
|
||||
AC_SUBST(EOG_API_VERSION)
|
||||
|
||||
AM_CONFIG_HEADER(config.h)
|
||||
|
||||
AM_MAINTAINER_MODE
|
||||
|
@ -206,8 +220,106 @@ fi
|
|||
# ************
|
||||
# Sun Keyboard
|
||||
# ************
|
||||
|
||||
AC_CHECK_HEADERS(X11/Sunkeysym.h, AC_DEFINE(HAVE_SUNKEYSYM_H, 1, [Sun Keyboard Support]))
|
||||
|
||||
# **************
|
||||
# Python Support
|
||||
# **************
|
||||
|
||||
AC_MSG_CHECKING([whether Python support is requested])
|
||||
|
||||
AC_ARG_ENABLE([python],
|
||||
AS_HELP_STRING([--enable-python],[Enable python support]),
|
||||
[enable_python=$enableval have_python=$enableval],
|
||||
[enable_python=autodetect have_python=yes])
|
||||
|
||||
AC_MSG_RESULT([$enable_python])
|
||||
|
||||
if test "x$have_python" != "xno"; then
|
||||
AM_PATH_PYTHON([2.3],[],[no])
|
||||
if test "x$PYTHON" = "x:"; then
|
||||
have_python=no
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x$have_python" != "xno"; then
|
||||
PY_PREFIX=`$PYTHON -c 'import sys ; print sys.prefix'`
|
||||
PY_EXEC_PREFIX=`$PYTHON -c 'import sys ; print sys.exec_prefix'`
|
||||
PYTHON_LIBS="-lpython$PYTHON_VERSION"
|
||||
PYTHON_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python$PYTHON_VERSION/config"
|
||||
PYTHON_CFLAGS="-I$PY_PREFIX/include/python$PYTHON_VERSION"
|
||||
PYTHON_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PYTHON_VERSION/config/Makefile"
|
||||
PYTHON_LOCALMODLIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PYTHON_MAKEFILE`
|
||||
PYTHON_BASEMODLIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PYTHON_MAKEFILE`
|
||||
PYTHON_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PYTHON_MAKEFILE`
|
||||
PYTHON_EXTRA_LIBS="$PYTHON_LOCALMODLIBS $PYTHON_BASEMODLIBS $PYTHON_OTHER_LIBS"
|
||||
AC_SUBST([PYTHON_LIBS])
|
||||
AC_SUBST([PYTHON_LIB_LOC])
|
||||
AC_SUBST([PYTHON_CFLAGS])
|
||||
AC_SUBST([PYTHON_EXTRA_LIBS])
|
||||
fi
|
||||
|
||||
if test "x$have_python" != "xno"; then
|
||||
PYGOBJECT_REQUIRED=2.11.5
|
||||
PYGTK_REQUIRED=2.9.7
|
||||
GNOME_PYTHON_REQUIRED=2.18.2
|
||||
|
||||
PKG_CHECK_MODULES([PYGTK], [
|
||||
pygobject-2.0 >= $PYGOBJECT_REQUIRED
|
||||
gnome-python-2.0 >= $GNOME_PYTHON_REQUIRED
|
||||
pygtk-2.0 >= $PYGTK_REQUIRED],
|
||||
[],[have_python=no])
|
||||
|
||||
AC_SUBST([PYGTK_CFLAGS])
|
||||
AC_SUBST([PYGTK_LIBS])
|
||||
fi
|
||||
|
||||
if test "x$have_python" != "xno"; then
|
||||
AC_MSG_CHECKING([for pygtk defs])
|
||||
PYGTK_DEFSDIR=`$PKG_CONFIG --variable=defsdir pygtk-2.0`
|
||||
AC_MSG_RESULT([$PYGTK_DEFSDIR])
|
||||
|
||||
AC_MSG_CHECKING([for pygtk codegen])
|
||||
PYGTK_CODEGEN="$PYTHON `$PKG_CONFIG --variable=codegendir pygtk-2.0`/codegen.py"
|
||||
AC_MSG_RESULT([$PYGTK_CODEGEN])
|
||||
|
||||
AC_MSG_CHECKING([for pygtk h2def])
|
||||
PYGTK_H2DEF="$PYTHON `$PKG_CONFIG --variable=codegendir pygtk-2.0`/h2def.py"
|
||||
AC_MSG_RESULT([$PYGTK_H2DEF])
|
||||
|
||||
AC_SUBST([PYGTK_DEFSDIR])
|
||||
AC_SUBST([PYGTK_CODEGEN])
|
||||
AC_SUBST([PYGTK_H2DEF])
|
||||
|
||||
dnl Check for -fno-strict-aliasing
|
||||
FLAGS="-fno-strict-aliasing"
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS $FLAGS"
|
||||
AC_MSG_CHECKING([whether [$]CC understands $FLAGS])
|
||||
AC_TRY_COMPILE([], [], [compiler_has_option=yes], [compiler_has_option=no])
|
||||
CFLAGS="$save_CFLAGS"
|
||||
AC_MSG_RESULT($compiler_has_option)
|
||||
if test $compiler_has_option = yes; then
|
||||
NO_STRICT_ALIASING_CFLAGS="$FLAGS"
|
||||
fi
|
||||
AC_SUBST([NO_STRICT_ALIASING_CFLAGS])
|
||||
fi
|
||||
|
||||
if test "x$have_python" != "xyes"; then
|
||||
if test "x$enable_python" = "xyes"; then
|
||||
AC_MSG_ERROR([Python not found])
|
||||
elif test "x$enable_python" = "xautodetect"; then
|
||||
enable_python=no
|
||||
AC_MSG_WARN([Python not found, disabling python support])
|
||||
fi
|
||||
elif test "x$enable_python" != "xno"; then
|
||||
enable_python=yes
|
||||
AC_DEFINE([ENABLE_PYTHON],[1],[Define to compile with python support])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL([ENABLE_PYTHON],[test "x$enable_python" = "xyes"])
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
src/Makefile
|
||||
|
@ -242,6 +354,8 @@ data/icons/48x48/Makefile
|
|||
data/icons/48x48/actions/Makefile
|
||||
data/icons/scalable/Makefile
|
||||
data/icons/scalable/apps/Makefile
|
||||
bindings/Makefile
|
||||
bindings/python/Makefile
|
||||
])
|
||||
|
||||
AC_OUTPUT
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
includedir=@includedir@/eog-@EOG_API_VERSION@
|
||||
pluginsdir=@libdir@/eog/plugins
|
||||
|
||||
Name: Eye of GNOME
|
||||
Description: The GNOME Image Viewer
|
||||
Requires: gtk+-2.0, libgnomeui-2.0 libglade-2.0, gnome-vfs-2.0, gconf-2.0
|
||||
Version: @VERSION@
|
||||
Cflags: -I${includedir}/eog
|
||||
Cflags: -I${includedir}
|
||||
|
|
|
@ -10,7 +10,7 @@ noinst_LTLIBRARIES = libeog.la
|
|||
|
||||
bin_PROGRAMS = eog
|
||||
|
||||
headerdir = $(prefix)/include/eog/eog
|
||||
headerdir = $(prefix)/include/eog-@EOG_API_VERSION@/eog
|
||||
header_DATA = $(INST_H_FILES)
|
||||
|
||||
MARSHAL_OUTPUT = \
|
||||
|
@ -36,6 +36,12 @@ NOINST_H_FILES = \
|
|||
uta.h \
|
||||
zoom.h
|
||||
|
||||
if ENABLE_PYTHON
|
||||
NOINST_H_FILES += \
|
||||
eog-python-module.h \
|
||||
eog-python-plugin.h
|
||||
endif
|
||||
|
||||
INST_H_FILES = \
|
||||
eog-application.h \
|
||||
eog-debug.h \
|
||||
|
@ -94,12 +100,10 @@ libeog_la_SOURCES = \
|
|||
eog-plugin-engine.c \
|
||||
uta.c \
|
||||
zoom.c \
|
||||
$(MARSHAL_OUTPUT) \
|
||||
$(BUILT_SOURCES) \
|
||||
$(NOINST_H_FILES) \
|
||||
$(INST_H_FILES)
|
||||
|
||||
main.c
|
||||
|
||||
if HAVE_EXIF
|
||||
libeog_la_SOURCES += \
|
||||
eog-exif-util.h \
|
||||
|
@ -108,6 +112,14 @@ libeog_la_SOURCES += \
|
|||
eog-exif-details.c
|
||||
endif
|
||||
|
||||
if ENABLE_PYTHON
|
||||
libeog_la_SOURCES += \
|
||||
eog-python-module.c \
|
||||
eog-python-module.h \
|
||||
eog-python-plugin.c \
|
||||
eog-python-plugin.h
|
||||
endif
|
||||
|
||||
libeog_la_CFLAGS = \
|
||||
$(EOG_CFLAGS) \
|
||||
$(WARN_CFLAGS) \
|
||||
|
@ -116,9 +128,26 @@ libeog_la_CFLAGS = \
|
|||
-DG_LOG_DOMAIN=\"EOG\" \
|
||||
-DEOG_PREFIX=\""${prefix}"\" \
|
||||
-DEOG_DATA_DIR=\""$(pkgdatadir)"\" \
|
||||
-DEOG_LOCALE_DIR=\""$(datadir)/locale"\" \
|
||||
-DEOG_PIXMAPS_DIR=\""$(datadir)/pixmaps/eog"\" \
|
||||
-DEOG_PLUGIN_DIR=\""$(libdir)/eog/plugins"\"
|
||||
|
||||
libeog_la_LIBADD = \
|
||||
$(EOG_LIBS)
|
||||
|
||||
if ENABLE_PYTHON
|
||||
libeog_la_CFLAGS += \
|
||||
$(NO_STRICT_ALIASING_CFLAGS) \
|
||||
$(PYGTK_CFLAGS) \
|
||||
$(PYTHON_CFLAGS) \
|
||||
$(AM_CFLAGS)
|
||||
|
||||
libeog_la_LIBADD += \
|
||||
$(top_builddir)/bindings/python/eog.la
|
||||
endif
|
||||
|
||||
libeog_la_LDFLAGS = -export-dynamic -no-undefined -export-symbols-regex "^[[^_]].*"
|
||||
|
||||
eog_SOURCES = main.c
|
||||
|
||||
eog_DEPENDENCIES = \
|
||||
|
@ -130,7 +159,7 @@ eog_CFLAGS = \
|
|||
$(EOG_CFLAGS) \
|
||||
-I$(top_srcdir)/cut-n-paste/toolbar-editor \
|
||||
-DEOG_DATADIR=\""$(pkgdatadir)"\" \
|
||||
-DGNOMELOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
|
||||
-DEOG_LOCALE_DIR=\""$(datadir)/locale"\"
|
||||
|
||||
eog_LDADD = \
|
||||
libeog.la \
|
||||
|
@ -140,16 +169,29 @@ eog_LDADD = \
|
|||
$(toolbar_LIB) \
|
||||
$(jpeg_LIB)
|
||||
|
||||
eog_LDFLAGS = -export-dynamic -no-undefined -export-symbols-regex "^[[^_]].*"
|
||||
|
||||
BUILT_SOURCES = \
|
||||
eog-enum-types.c \
|
||||
eog-enum-types.h \
|
||||
$(MARSHAL_OUTPUT)
|
||||
|
||||
eog-enum-types.h: eog-enum-types.h.template $(INST_H_FILES) $(GLIB_MKENUMS)
|
||||
(cd $(srcdir) && $(GLIB_MKENUMS) --template eog-enum-types.h.template $(INST_H_FILES)) > $@
|
||||
|
||||
eog-enum-types.c: eog-enum-types.c.template $(INST_H_FILES) $(GLIB_MKENUMS)
|
||||
(cd $(srcdir) && $(GLIB_MKENUMS) --template eog-enum-types.c.template $(INST_H_FILES)) > $@
|
||||
|
||||
eog-marshal.h: eog-marshal.list $(GLIB_GENMARSHAL)
|
||||
$(GLIB_GENMARSHAL) $< --header --prefix=eog_marshal > $@
|
||||
|
||||
eog-marshal.c: eog-marshal.list $(GLIB_GENMARSHAL)
|
||||
$(GLIB_GENMARSHAL) $< --body --header --prefix=eog_marshal > $@
|
||||
|
||||
EXTRA_DIST = eog-marshal.list
|
||||
EXTRA_DIST = \
|
||||
eog-enum-types.h.template \
|
||||
eog-enum-types.c.template \
|
||||
eog-marshal.list
|
||||
|
||||
if HAVE_DBUS
|
||||
|
||||
|
|
|
@ -118,12 +118,13 @@ eog_application_init (EogApplication *eog_application)
|
|||
|
||||
eog_application->toolbars_file = g_build_filename
|
||||
(eog_util_dot_dir (), "eog_toolbar.xml", NULL);
|
||||
|
||||
|
||||
egg_toolbars_model_load_names (eog_application->toolbars_model,
|
||||
EOG_DATA_DIR "/eog-toolbar.xml");
|
||||
|
||||
if (!egg_toolbars_model_load_toolbars (eog_application->toolbars_model,
|
||||
eog_application->toolbars_file)) {
|
||||
|
||||
egg_toolbars_model_load_toolbars (eog_application->toolbars_model,
|
||||
EOG_DATA_DIR "/eog-toolbar.xml");
|
||||
}
|
||||
|
|
519
src/eog-python-module.c
Normal file
519
src/eog-python-module.c
Normal file
|
@ -0,0 +1,519 @@
|
|||
/*
|
||||
* eog-python-module.c
|
||||
* This file is part of eog
|
||||
*
|
||||
* Copyright (C) 2005 Raphael Slinckx
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <pygobject.h>
|
||||
#include <pygtk/pygtk.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <gmodule.h>
|
||||
|
||||
#include "eog-python-module.h"
|
||||
#include "eog-python-plugin.h"
|
||||
#include "eog-debug.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 EOG_PYTHON_MODULE_GET_PRIVATE(object) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((object), EOG_TYPE_PYTHON_MODULE, EogPythonModulePrivate))
|
||||
|
||||
struct _EogPythonModulePrivate {
|
||||
gchar *module;
|
||||
gchar *path;
|
||||
GType type;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_PATH,
|
||||
PROP_MODULE
|
||||
};
|
||||
|
||||
void pyeog_register_classes (PyObject *d);
|
||||
void pyeog_add_constants (PyObject *module, const gchar *strip_prefix);
|
||||
extern PyMethodDef pyeog_functions[];
|
||||
|
||||
static PyTypeObject *PyEogPlugin_Type;
|
||||
|
||||
G_DEFINE_TYPE (EogPythonModule, eog_python_module, G_TYPE_TYPE_MODULE)
|
||||
|
||||
static gboolean
|
||||
eog_python_module_load (GTypeModule *gmodule)
|
||||
{
|
||||
EogPythonModulePrivate *priv = EOG_PYTHON_MODULE_GET_PRIVATE (gmodule);
|
||||
PyObject *main_module, *main_locals, *locals, *key, *value;
|
||||
PyObject *module, *fromlist;
|
||||
Py_ssize_t pos = 0;
|
||||
|
||||
g_return_val_if_fail (Py_IsInitialized (), FALSE);
|
||||
|
||||
main_module = PyImport_AddModule ("__main__");
|
||||
|
||||
if (main_module == NULL) {
|
||||
g_warning ("Could not get __main__.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If we have a special path, we register it */
|
||||
if (priv->path != NULL) {
|
||||
PyObject *sys_path = PySys_GetObject ("path");
|
||||
PyObject *path = PyString_FromString (priv->path);
|
||||
|
||||
if (PySequence_Contains(sys_path, path) == 0)
|
||||
PyList_Insert (sys_path, 0, path);
|
||||
|
||||
Py_DECREF(path);
|
||||
}
|
||||
|
||||
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 = PyImport_ImportModuleEx (priv->module, main_locals, main_locals, fromlist);
|
||||
|
||||
Py_DECREF(fromlist);
|
||||
|
||||
if (!module) {
|
||||
PyErr_Print ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
locals = PyModule_GetDict (module);
|
||||
|
||||
while (PyDict_Next (locals, &pos, &key, &value)) {
|
||||
if (!PyType_Check(value))
|
||||
continue;
|
||||
|
||||
if (PyObject_IsSubclass (value, (PyObject*) PyEogPlugin_Type)) {
|
||||
priv->type = eog_python_plugin_get_type (gmodule, value);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_module_unload (GTypeModule *module)
|
||||
{
|
||||
EogPythonModulePrivate *priv = EOG_PYTHON_MODULE_GET_PRIVATE (module);
|
||||
|
||||
eog_debug_message (DEBUG_PLUGINS, "Unloading Python module");
|
||||
|
||||
priv->type = 0;
|
||||
}
|
||||
|
||||
GObject *
|
||||
eog_python_module_new_object (EogPythonModule *module)
|
||||
{
|
||||
EogPythonModulePrivate *priv = EOG_PYTHON_MODULE_GET_PRIVATE (module);
|
||||
|
||||
eog_debug_message (DEBUG_PLUGINS, "Creating object of type %s", g_type_name (priv->type));
|
||||
|
||||
if (priv->type == 0)
|
||||
return NULL;
|
||||
|
||||
return g_object_new (priv->type, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_module_init (EogPythonModule *module)
|
||||
{
|
||||
eog_debug_message (DEBUG_PLUGINS, "Init of Python module");
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_module_finalize (GObject *object)
|
||||
{
|
||||
EogPythonModulePrivate *priv = EOG_PYTHON_MODULE_GET_PRIVATE (object);
|
||||
|
||||
eog_debug_message (DEBUG_PLUGINS, "Finalizing Python module %s", g_type_name (priv->type));
|
||||
|
||||
g_free (priv->module);
|
||||
g_free (priv->path);
|
||||
|
||||
G_OBJECT_CLASS (eog_python_module_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_module_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
g_return_if_reached ();
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_module_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EogPythonModule *mod = EOG_PYTHON_MODULE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_MODULE:
|
||||
EOG_PYTHON_MODULE_GET_PRIVATE (mod)->module = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_PATH:
|
||||
EOG_PYTHON_MODULE_GET_PRIVATE (mod)->path = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_return_if_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_module_class_init (EogPythonModuleClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (class);
|
||||
|
||||
object_class->finalize = eog_python_module_finalize;
|
||||
object_class->get_property = eog_python_module_get_property;
|
||||
object_class->set_property = eog_python_module_set_property;
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class,
|
||||
PROP_MODULE,
|
||||
g_param_spec_string ("module",
|
||||
"Module Name",
|
||||
"The Python module to load for this plugin",
|
||||
NULL,
|
||||
G_PARAM_WRITABLE | G_PARAM_READABLE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class,
|
||||
PROP_PATH,
|
||||
g_param_spec_string ("path",
|
||||
"Path",
|
||||
"The Python path to use when loading this module",
|
||||
NULL,
|
||||
G_PARAM_WRITABLE | G_PARAM_READABLE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (EogPythonModulePrivate));
|
||||
|
||||
module_class->load = eog_python_module_load;
|
||||
module_class->unload = eog_python_module_unload;
|
||||
}
|
||||
|
||||
EogPythonModule *
|
||||
eog_python_module_new (const gchar *path,
|
||||
const gchar *module)
|
||||
{
|
||||
EogPythonModule *result;
|
||||
|
||||
if (module == NULL || module[0] == '\0')
|
||||
return NULL;
|
||||
|
||||
result = g_object_new (EOG_TYPE_PYTHON_MODULE,
|
||||
"module", module,
|
||||
"path", path,
|
||||
NULL);
|
||||
|
||||
g_type_module_set_name (G_TYPE_MODULE (result), module);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static gint idle_garbage_collect_id = 0;
|
||||
|
||||
/* C equivalent of
|
||||
* import pygtk
|
||||
* pygtk.require ("2.0")
|
||||
*/
|
||||
static gboolean
|
||||
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
|
||||
eog_init_pygobject (void)
|
||||
{
|
||||
init_pygobject_check (2, 11, 5); /* FIXME: get from config */
|
||||
}
|
||||
|
||||
static void
|
||||
eog_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);
|
||||
}
|
||||
|
||||
gboolean
|
||||
eog_python_init (void)
|
||||
{
|
||||
PyObject *mdict, *path, *tuple;
|
||||
PyObject *sys_path, *eog;
|
||||
PyObject *gettext, *install, *gettext_args;
|
||||
struct sigaction old_sigint;
|
||||
gint res;
|
||||
char *argv[] = { "eog", NULL };
|
||||
|
||||
static gboolean init_failed = FALSE;
|
||||
|
||||
if (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 */
|
||||
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) */
|
||||
|
||||
/* 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)", strerror (errno));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Python initialization */
|
||||
Py_Initialize ();
|
||||
|
||||
/* 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).", strerror (errno));
|
||||
|
||||
goto python_init_error;
|
||||
}
|
||||
|
||||
PySys_SetArgv (1, argv);
|
||||
|
||||
if (!check_pygtk2 ()) {
|
||||
/* Warning message already printed in check_pygtk2 */
|
||||
goto python_init_error;
|
||||
}
|
||||
|
||||
/* import gobject */
|
||||
eog_init_pygobject ();
|
||||
|
||||
if (PyErr_Occurred ()) {
|
||||
g_warning ("Error initializing Python interpreter: could not import pygobject.");
|
||||
|
||||
goto python_init_error;
|
||||
}
|
||||
|
||||
/* import gtk */
|
||||
eog_init_pygtk ();
|
||||
|
||||
if (PyErr_Occurred ()) {
|
||||
g_warning ("Error initializing Python interpreter: could not import pygtk.");
|
||||
|
||||
goto python_init_error;
|
||||
}
|
||||
|
||||
/* sys.path.insert(0, ...) for system-wide plugins */
|
||||
sys_path = PySys_GetObject ("path");
|
||||
path = PyString_FromString (EOG_PLUGIN_DIR "/");
|
||||
PyList_Insert (sys_path, 0, path);
|
||||
Py_DECREF(path);
|
||||
|
||||
/* import eog */
|
||||
eog = Py_InitModule ("eog", pyeog_functions);
|
||||
mdict = PyModule_GetDict (eog);
|
||||
|
||||
pyeog_register_classes (mdict);
|
||||
pyeog_add_constants (eog, "EOG_");
|
||||
|
||||
/* eog version */
|
||||
tuple = Py_BuildValue("(iii)",
|
||||
EOG_MAJOR_VERSION,
|
||||
EOG_MINOR_VERSION,
|
||||
EOG_MICRO_VERSION);
|
||||
PyDict_SetItemString(mdict, "version", tuple);
|
||||
Py_DECREF(tuple);
|
||||
|
||||
/* Retrieve the Python type for eog.Plugin */
|
||||
PyEogPlugin_Type = (PyTypeObject *) PyDict_GetItemString (mdict, "Plugin");
|
||||
|
||||
if (PyEogPlugin_Type == NULL) {
|
||||
PyErr_Print ();
|
||||
|
||||
goto python_init_error;
|
||||
}
|
||||
|
||||
/* 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, EOG_LOCALE_DIR);
|
||||
PyObject_CallObject (install, gettext_args);
|
||||
Py_DECREF (gettext_args);
|
||||
|
||||
/* Python has been successfully initialized */
|
||||
init_failed = FALSE;
|
||||
|
||||
return TRUE;
|
||||
|
||||
python_init_error:
|
||||
|
||||
g_warning ("Please check the installation of all the Python related packages required "
|
||||
"by eog and try again.");
|
||||
|
||||
PyErr_Clear ();
|
||||
|
||||
eog_python_shutdown ();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
eog_python_shutdown (void)
|
||||
{
|
||||
if (Py_IsInitialized ()) {
|
||||
if (idle_garbage_collect_id != 0) {
|
||||
g_source_remove (idle_garbage_collect_id);
|
||||
idle_garbage_collect_id = 0;
|
||||
}
|
||||
|
||||
while (PyGC_Collect ())
|
||||
;
|
||||
|
||||
Py_Finalize ();
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
run_gc (gpointer data)
|
||||
{
|
||||
while (PyGC_Collect ())
|
||||
;
|
||||
|
||||
idle_garbage_collect_id = 0;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
eog_python_garbage_collect (void)
|
||||
{
|
||||
if (Py_IsInitialized()) {
|
||||
/*
|
||||
* We both run the GC right now and we schedule
|
||||
* a further collection in the main loop.
|
||||
*/
|
||||
|
||||
while (PyGC_Collect ())
|
||||
;
|
||||
|
||||
if (idle_garbage_collect_id == 0)
|
||||
idle_garbage_collect_id = g_idle_add (run_gc, NULL);
|
||||
}
|
||||
}
|
||||
|
68
src/eog-python-module.h
Normal file
68
src/eog-python-module.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/* Eye Of Gnome - Python Module
|
||||
*
|
||||
* Copyright (C) 2007 The Free Software Foundation
|
||||
*
|
||||
* Author: Lucas Rocha <lucasr@gnome.org>
|
||||
*
|
||||
* Based on gedit code (gedit/gedit-python-module.h) by:
|
||||
* - Raphael Slinckx <raphael@slinckx.net>
|
||||
*
|
||||
* 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 __EOG_PYTHON_MODULE_H__
|
||||
#define __EOG_PYTHON_MODULE_H__
|
||||
|
||||
#include <Python.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EOG_TYPE_PYTHON_MODULE (eog_python_module_get_type ())
|
||||
#define EOG_PYTHON_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EOG_TYPE_PYTHON_MODULE, EogPythonModule))
|
||||
#define EOG_PYTHON_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EOG_TYPE_PYTHON_MODULE, EogPythonModuleClass))
|
||||
#define EOG_IS_PYTHON_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EOG_TYPE_PYTHON_MODULE))
|
||||
#define EOG_IS_PYTHON_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EOG_TYPE_PYTHON_MODULE))
|
||||
#define EOG_PYTHON_MODULE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EOG_TYPE_PYTHON_MODULE, EogPythonModuleClass))
|
||||
|
||||
typedef struct _EogPythonModule EogPythonModule;
|
||||
typedef struct _EogPythonModuleClass EogPythonModuleClass;
|
||||
typedef struct _EogPythonModulePrivate EogPythonModulePrivate;
|
||||
|
||||
struct _EogPythonModuleClass {
|
||||
GTypeModuleClass parent_class;
|
||||
};
|
||||
|
||||
struct _EogPythonModule {
|
||||
GTypeModule parent_instance;
|
||||
};
|
||||
|
||||
GType eog_python_module_get_type (void) G_GNUC_CONST;
|
||||
|
||||
EogPythonModule *eog_python_module_new (const gchar* path,
|
||||
const gchar *module);
|
||||
|
||||
GObject *eog_python_module_new_object (EogPythonModule *module);
|
||||
|
||||
|
||||
gboolean eog_python_init (void);
|
||||
|
||||
void eog_python_shutdown (void);
|
||||
|
||||
void eog_python_garbage_collect (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __EOG_PYTHON_MODULE_H__ */
|
281
src/eog-python-plugin.c
Normal file
281
src/eog-python-plugin.c
Normal file
|
@ -0,0 +1,281 @@
|
|||
/* Eye Of Gnome - Python Plugin
|
||||
*
|
||||
* Copyright (C) 2007 The Free Software Foundation
|
||||
*
|
||||
* Author: Lucas Rocha <lucasr@gnome.org>
|
||||
*
|
||||
* Based on gedit code (gedit/gedit-python-module.h) by:
|
||||
* - Raphael Slinckx <raphael@slinckx.net>
|
||||
*
|
||||
* 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 "eog-python-plugin.h"
|
||||
#include "eog-plugin.h"
|
||||
#include "eog-debug.h"
|
||||
|
||||
#include <pygobject.h>
|
||||
#include <string.h>
|
||||
|
||||
static GObjectClass *parent_class;
|
||||
|
||||
static PyObject *
|
||||
call_python_method (EogPythonPlugin *plugin,
|
||||
EogWindow *window,
|
||||
gchar *method)
|
||||
{
|
||||
PyObject *py_ret = NULL;
|
||||
|
||||
g_return_val_if_fail (PyObject_HasAttrString (plugin->instance, method), NULL);
|
||||
|
||||
if (window == NULL) {
|
||||
py_ret = PyObject_CallMethod (plugin->instance,
|
||||
method,
|
||||
NULL);
|
||||
} else {
|
||||
py_ret = PyObject_CallMethod (plugin->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 (EogPlugin *plugin,
|
||||
EogWindow *window)
|
||||
{
|
||||
PyGILState_STATE state = pyg_gil_state_ensure ();
|
||||
|
||||
EogPythonPlugin *pyplugin = (EogPythonPlugin *) plugin;
|
||||
|
||||
if (PyObject_HasAttrString (pyplugin->instance, "update_ui")) {
|
||||
PyObject *py_ret = call_python_method (pyplugin, window, "update_ui");
|
||||
|
||||
if (py_ret)
|
||||
{
|
||||
Py_XDECREF (py_ret);
|
||||
}
|
||||
} else {
|
||||
EOG_PLUGIN_CLASS (parent_class)->update_ui (plugin, window);
|
||||
}
|
||||
|
||||
pyg_gil_state_release (state);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_deactivate (EogPlugin *plugin,
|
||||
EogWindow *window)
|
||||
{
|
||||
PyGILState_STATE state = pyg_gil_state_ensure ();
|
||||
|
||||
EogPythonPlugin *pyplugin = (EogPythonPlugin *) plugin;
|
||||
|
||||
if (PyObject_HasAttrString (pyplugin->instance, "deactivate")) {
|
||||
PyObject *py_ret = call_python_method (pyplugin, window, "deactivate");
|
||||
|
||||
if (py_ret) {
|
||||
Py_XDECREF (py_ret);
|
||||
}
|
||||
} else {
|
||||
EOG_PLUGIN_CLASS (parent_class)->deactivate (plugin, window);
|
||||
}
|
||||
|
||||
pyg_gil_state_release (state);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_activate (EogPlugin *plugin,
|
||||
EogWindow *window)
|
||||
{
|
||||
PyGILState_STATE state = pyg_gil_state_ensure ();
|
||||
|
||||
EogPythonPlugin *pyplugin = (EogPythonPlugin *) plugin;
|
||||
|
||||
if (PyObject_HasAttrString (pyplugin->instance, "activate")) {
|
||||
PyObject *py_ret = call_python_method (pyplugin, window, "activate");
|
||||
|
||||
if (py_ret) {
|
||||
Py_XDECREF (py_ret);
|
||||
}
|
||||
} else {
|
||||
EOG_PLUGIN_CLASS (parent_class)->activate (plugin, window);
|
||||
}
|
||||
|
||||
pyg_gil_state_release (state);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
impl_create_configure_dialog (EogPlugin *plugin)
|
||||
{
|
||||
PyGILState_STATE state = pyg_gil_state_ensure ();
|
||||
EogPythonPlugin *pyplugin = (EogPythonPlugin *) plugin;
|
||||
GtkWidget *ret = NULL;
|
||||
|
||||
if (PyObject_HasAttrString (pyplugin->instance, "create_configure_dialog")) {
|
||||
PyObject *py_ret = call_python_method (pyplugin, 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 = EOG_PLUGIN_CLASS (parent_class)->create_configure_dialog (plugin);
|
||||
}
|
||||
|
||||
pyg_gil_state_release (state);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
impl_is_configurable (EogPlugin *plugin)
|
||||
{
|
||||
PyGILState_STATE state = pyg_gil_state_ensure ();
|
||||
|
||||
EogPythonPlugin *pyplugin = (EogPythonPlugin *) plugin;
|
||||
|
||||
PyObject *dict = pyplugin->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;
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_plugin_init (EogPythonPlugin *plugin)
|
||||
{
|
||||
EogPythonPluginClass *class;
|
||||
|
||||
eog_debug_message (DEBUG_PLUGINS, "Creating Python plugin instance");
|
||||
|
||||
class = (EogPythonPluginClass*) (((GTypeInstance*) plugin)->g_class);
|
||||
|
||||
plugin->instance = PyObject_CallObject (class->type, NULL);
|
||||
|
||||
if (plugin->instance == NULL)
|
||||
PyErr_Print();
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_plugin_finalize (GObject *plugin)
|
||||
{
|
||||
eog_debug_message (DEBUG_PLUGINS, "Finalizing Python plugin instance");
|
||||
|
||||
Py_DECREF (((EogPythonPlugin *) plugin)->instance);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (plugin);
|
||||
}
|
||||
|
||||
static void
|
||||
eog_python_plugin_class_init (EogPythonPluginClass *klass,
|
||||
gpointer class_data)
|
||||
{
|
||||
EogPluginClass *plugin_class = EOG_PLUGIN_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
klass->type = (PyObject*) class_data;
|
||||
|
||||
G_OBJECT_CLASS (klass)->finalize = eog_python_plugin_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;
|
||||
}
|
||||
|
||||
GType
|
||||
eog_python_plugin_get_type (GTypeModule *module,
|
||||
PyObject *type)
|
||||
{
|
||||
GType gtype;
|
||||
gchar *type_name;
|
||||
|
||||
GTypeInfo info = {
|
||||
sizeof (EogPythonPluginClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) eog_python_plugin_class_init,
|
||||
NULL, /* class_finalize */
|
||||
type, /* class_data */
|
||||
sizeof (EogPythonPlugin),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) eog_python_plugin_init,
|
||||
};
|
||||
|
||||
Py_INCREF (type);
|
||||
|
||||
type_name = g_strdup_printf ("%s+EogPythonPlugin",
|
||||
PyString_AsString (PyObject_GetAttrString (type, "__name__")));
|
||||
|
||||
eog_debug_message (DEBUG_PLUGINS, "Registering Python plugin instance: %s", type_name);
|
||||
|
||||
gtype = g_type_module_register_type (module,
|
||||
EOG_TYPE_PLUGIN,
|
||||
type_name,
|
||||
&info, 0);
|
||||
|
||||
g_free (type_name);
|
||||
|
||||
return gtype;
|
||||
}
|
54
src/eog-python-plugin.h
Normal file
54
src/eog-python-plugin.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* Eye Of Gnome - Python Plugin
|
||||
*
|
||||
* Copyright (C) 2007 The Free Software Foundation
|
||||
*
|
||||
* Author: Lucas Rocha <lucasr@gnome.org>
|
||||
*
|
||||
* Based on gedit code (gedit/gedit-python-module.h) by:
|
||||
* - Raphael Slinckx <raphael@slinckx.net>
|
||||
*
|
||||
* 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 __EOG_PYTHON_PLUGIN_H__
|
||||
#define __EOG_PYTHON_PLUGIN_H__
|
||||
|
||||
#include <Python.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "eog-plugin.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _EogPythonPlugin EogPythonPlugin;
|
||||
typedef struct _EogPythonPluginClass EogPythonPluginClass;
|
||||
|
||||
struct _EogPythonPlugin {
|
||||
EogPlugin plugin;
|
||||
|
||||
PyObject *instance;
|
||||
};
|
||||
|
||||
struct _EogPythonPluginClass {
|
||||
EogPluginClass parent_class;
|
||||
|
||||
PyObject *type;
|
||||
};
|
||||
|
||||
GType eog_python_plugin_get_type (GTypeModule *module, PyObject *type);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
|
@ -119,7 +119,7 @@ struct _EogScrollViewPrivate {
|
|||
ProgressiveState progressive_state;
|
||||
|
||||
/* how to indicate transparency in images */
|
||||
TransparencyStyle transp_style;
|
||||
EogTransparencyStyle transp_style;
|
||||
guint32 transp_color;
|
||||
|
||||
/* the type of the cursor we are currently showing */
|
||||
|
@ -657,7 +657,7 @@ paint_rectangle (EogScrollView *view, ArtIRect *rect, GdkInterpType interp_type)
|
|||
|
||||
/* Compute transparency parameters */
|
||||
switch (priv->transp_style) {
|
||||
case TRANSP_BACKGROUND: {
|
||||
case EOG_TRANSP_BACKGROUND: {
|
||||
GdkColor color = GTK_WIDGET (priv->display)->style->bg[GTK_STATE_NORMAL];
|
||||
|
||||
check_1 = check_2 = (((color.red & 0xff00) << 8)
|
||||
|
@ -665,12 +665,12 @@ paint_rectangle (EogScrollView *view, ArtIRect *rect, GdkInterpType interp_type)
|
|||
| ((color.blue & 0xff00) >> 8));
|
||||
break; }
|
||||
|
||||
case TRANSP_CHECKED:
|
||||
case EOG_TRANSP_CHECKED:
|
||||
check_1 = CHECK_GRAY;
|
||||
check_2 = CHECK_LIGHT;
|
||||
break;
|
||||
|
||||
case TRANSP_COLOR:
|
||||
case EOG_TRANSP_COLOR:
|
||||
check_1 = check_2 = priv->transp_color;
|
||||
break;
|
||||
|
||||
|
@ -1676,7 +1676,7 @@ eog_scroll_view_set_antialiasing (EogScrollView *view, gboolean state)
|
|||
}
|
||||
|
||||
void
|
||||
eog_scroll_view_set_transparency (EogScrollView *view, TransparencyStyle style, GdkColor *color)
|
||||
eog_scroll_view_set_transparency (EogScrollView *view, EogTransparencyStyle style, GdkColor *color)
|
||||
{
|
||||
EogScrollViewPrivate *priv;
|
||||
guint32 col = 0;
|
||||
|
@ -1699,7 +1699,7 @@ eog_scroll_view_set_transparency (EogScrollView *view, TransparencyStyle style,
|
|||
changed = TRUE;
|
||||
}
|
||||
|
||||
if (priv->transp_style == TRANSP_COLOR && priv->transp_color != col) {
|
||||
if (priv->transp_style == EOG_TRANSP_COLOR && priv->transp_color != col) {
|
||||
priv->transp_color = col;
|
||||
changed = TRUE;
|
||||
}
|
||||
|
@ -1883,24 +1883,6 @@ eog_scroll_view_set_image (EogScrollView *view, EogImage *image)
|
|||
priv->image = image;
|
||||
}
|
||||
|
||||
void
|
||||
eog_scroll_view_get_image_size (EogScrollView *view, int *width, int *height, gboolean scaled)
|
||||
{
|
||||
EogScrollViewPrivate *priv;
|
||||
|
||||
*width = *height = 0;
|
||||
|
||||
g_return_if_fail (EOG_IS_SCROLL_VIEW (view));
|
||||
|
||||
priv = view->priv;
|
||||
|
||||
if (!priv->pixbuf)
|
||||
return;
|
||||
|
||||
*width = gdk_pixbuf_get_width (priv->pixbuf);
|
||||
*height = gdk_pixbuf_get_height (priv->pixbuf);
|
||||
}
|
||||
|
||||
gboolean
|
||||
eog_scroll_view_scrollbars_visible (EogScrollView *view)
|
||||
{
|
||||
|
@ -1935,7 +1917,7 @@ eog_scroll_view_init (EogScrollView *view)
|
|||
priv->image = NULL;
|
||||
priv->pixbuf = NULL;
|
||||
priv->progressive_state = PROGRESSIVE_NONE;
|
||||
priv->transp_style = TRANSP_BACKGROUND;
|
||||
priv->transp_style = EOG_TRANSP_BACKGROUND;
|
||||
priv->transp_color = 0;
|
||||
priv->cursor = EOG_SCROLL_VIEW_CURSOR_NORMAL;
|
||||
}
|
||||
|
|
|
@ -30,10 +30,10 @@ struct _EogScrollViewClass {
|
|||
};
|
||||
|
||||
typedef enum {
|
||||
TRANSP_BACKGROUND,
|
||||
TRANSP_CHECKED,
|
||||
TRANSP_COLOR
|
||||
} TransparencyStyle;
|
||||
EOG_TRANSP_BACKGROUND,
|
||||
EOG_TRANSP_CHECKED,
|
||||
EOG_TRANSP_COLOR
|
||||
} EogTransparencyStyle;
|
||||
|
||||
GType eog_scroll_view_get_type (void) G_GNUC_CONST;
|
||||
GtkWidget* eog_scroll_view_new (void);
|
||||
|
@ -46,8 +46,7 @@ void eog_scroll_view_set_scroll_wheel_zoom (EogScrollView *view, gboolean sc
|
|||
void eog_scroll_view_set_zoom_upscale (EogScrollView *view, gboolean upscale);
|
||||
void eog_scroll_view_set_zoom_multiplier (EogScrollView *view, gdouble multiplier);
|
||||
void eog_scroll_view_set_antialiasing (EogScrollView *view, gboolean state);
|
||||
void eog_scroll_view_set_transparency (EogScrollView *view, TransparencyStyle style, GdkColor *color);
|
||||
void eog_scroll_view_get_image_size (EogScrollView *view, int *width, int *height, gboolean scaled);
|
||||
void eog_scroll_view_set_transparency (EogScrollView *view, EogTransparencyStyle style, GdkColor *color);
|
||||
gboolean eog_scroll_view_scrollbars_visible (EogScrollView *view);
|
||||
|
||||
/* zoom api */
|
||||
|
|
|
@ -312,15 +312,15 @@ eog_window_transparency_changed_cb (GConfClient *client,
|
|||
EOG_CONF_VIEW_TRANS_COLOR, NULL);
|
||||
if (gdk_color_parse (color_str, &color)) {
|
||||
eog_scroll_view_set_transparency (EOG_SCROLL_VIEW (priv->view),
|
||||
TRANSP_COLOR, &color);
|
||||
EOG_TRANSP_COLOR, &color);
|
||||
}
|
||||
g_free (color_str);
|
||||
} else if (g_ascii_strcasecmp (value, "CHECK_PATTERN") == 0) {
|
||||
eog_scroll_view_set_transparency (EOG_SCROLL_VIEW (priv->view),
|
||||
TRANSP_CHECKED, 0);
|
||||
EOG_TRANSP_CHECKED, 0);
|
||||
} else {
|
||||
eog_scroll_view_set_transparency (EOG_SCROLL_VIEW (priv->view),
|
||||
TRANSP_BACKGROUND, 0);
|
||||
EOG_TRANSP_BACKGROUND, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ eog_window_trans_color_changed_cb (GConfClient *client,
|
|||
|
||||
if (gdk_color_parse (color_str, &color)) {
|
||||
eog_scroll_view_set_transparency (EOG_SCROLL_VIEW (priv->view),
|
||||
TRANSP_COLOR, &color);
|
||||
EOG_TRANSP_COLOR, &color);
|
||||
}
|
||||
}
|
||||
g_free (value);
|
||||
|
|
|
@ -167,7 +167,7 @@ main (int argc, char **argv)
|
|||
GnomeProgram *program;
|
||||
GOptionContext *ctx;
|
||||
|
||||
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
|
||||
bindtextdomain (PACKAGE, EOG_LOCALE_DIR);
|
||||
bind_textdomain_codeset (PACKAGE, "UTF-8");
|
||||
textdomain (PACKAGE);
|
||||
|
||||
|
|
Loading…
Reference in a new issue