im.pidgin.pidgin: b89651a1e1469c30b3fa9689b5df87c381ac829b
sadrul at pidgin.im
sadrul at pidgin.im
Sat Dec 8 20:05:37 EST 2007
-----------------------------------------------------------------
Revision: b89651a1e1469c30b3fa9689b5df87c381ac829b
Ancestor: a8000dfd2711e51194f8f0068d4ae9787cac5179
Author: sadrul at pidgin.im
Date: 2007-12-09T00:56:29
Branch: im.pidgin.pidgin
Modified files:
configure.ac finch/libgnt/Makefile.am
finch/libgnt/configure.ac finch/libgnt/gntwm.c
ChangeLog:
Allow loading python scripts at runtime.
Things can go wrong if a script starts its own mainloop, or blocks on something.
For now, a script can check for a positive return value from 'gobject.main_depth()'
to determine that it's being loaded at runtime, and not start its own mainloop.
-------------- next part --------------
============================================================
--- configure.ac 44e4e7d9eba4c3a8c9b38c65602423418d03cca2
+++ configure.ac 617f95f36ac89823b33c1849acfb11bbdd3a7c52
@@ -1336,6 +1336,34 @@ AM_CONDITIONAL(ENABLE_DBUS, test "x$enab
AM_CONDITIONAL(ENABLE_DBUS, test "x$enable_dbus" = "xyes")
+dnl Check for Python headers (currently useful only for libgnt)
+dnl (Thanks to XChat)
+AC_PATH_PROG(pythonpath, python)
+if test "_$pythonpath" != _ ; then
+ AC_MSG_CHECKING(for Python compile flags)
+ PY_PREFIX=`$pythonpath -c 'import sys ; print sys.prefix'`
+ PY_EXEC_PREFIX=`$pythonpath -c 'import sys ; print sys.exec_prefix'`
+ changequote(<<, >>)dnl
+ PY_VERSION=`$pythonpath -c 'import sys ; print sys.version[0:3]'`
+ PY_MAJOR=`$pythonpath -c 'import sys ; print sys.version[0:2]'`
+ changequote([, ])dnl
+ if test -f $PY_PREFIX/include/python$PY_VERSION/Python.h -a "$PY_MAJOR" = "2."; then
+ AC_CHECK_LIB(pthread, pthread_create, )
+ AC_CHECK_LIB(util, openpty, )
+ AC_CHECK_LIB(db, dbopen, )
+ PY_LIBS="-lpython$PY_VERSION -L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
+ PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION"
+ AC_DEFINE(USE_PYTHON, [1], [Define if python headers are available.])
+ AC_MSG_RESULT(ok)
+ else
+ AC_MSG_RESULT([Can't find Python.h])
+ PY_LIBS=""
+ PY_CFLAGS=""
+ fi
+fi
+AC_SUBST(PY_CFLAGS)
+AC_SUBST(PY_LIBS)
+
dnl #######################################################################
dnl # Check for Mono support
dnl #######################################################################
============================================================
--- finch/libgnt/Makefile.am 0c5735991777bb38a50f3d0ed48d1b472b737928
+++ finch/libgnt/Makefile.am f42eb9e2e7aa2eb176b67746b3fca34aafee2f80
@@ -84,10 +84,12 @@ libgnt_la_LIBADD = \
libgnt_la_LIBADD = \
$(GLIB_LIBS) \
$(GNT_LIBS) \
- $(LIBXML_LIBS)
+ $(LIBXML_LIBS) \
+ $(PY_LIBS)
AM_CPPFLAGS = \
$(GLIB_CFLAGS) \
$(GNT_CFLAGS) \
$(DEBUG_CFLAGS) \
+ $(LIBXML_CFLAGS) \
+ $(PY_CFLAGS)
- $(LIBXML_CFLAGS)
============================================================
--- finch/libgnt/configure.ac 0a85567522bddaabacab6a60af4cf7e94496d913
+++ finch/libgnt/configure.ac 23f21db721035fabaa836df7c8e814de6f9b56de
@@ -302,6 +302,34 @@ fi
*** You need ncursesw or ncurses and its header files.])
fi
+dnl Check for Python headers (currently useful only for libgnt)
+dnl (Thanks to XChat)
+AC_PATH_PROG(pythonpath, python)
+if test "_$pythonpath" != _ ; then
+ AC_MSG_CHECKING(for Python compile flags)
+ PY_PREFIX=`$pythonpath -c 'import sys ; print sys.prefix'`
+ PY_EXEC_PREFIX=`$pythonpath -c 'import sys ; print sys.exec_prefix'`
+ changequote(<<, >>)dnl
+ PY_VERSION=`$pythonpath -c 'import sys ; print sys.version[0:3]'`
+ PY_MAJOR=`$pythonpath -c 'import sys ; print sys.version[0:2]'`
+ changequote([, ])dnl
+ if test -f $PY_PREFIX/include/python$PY_VERSION/Python.h -a "$PY_MAJOR" = "2."; then
+ AC_CHECK_LIB(pthread, pthread_create, )
+ AC_CHECK_LIB(util, openpty, )
+ AC_CHECK_LIB(db, dbopen, )
+ PY_LIBS="-lpython$PY_VERSION -L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
+ PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION"
+ AC_DEFINE(USE_PYTHON, [1], [Define if python headers are available.])
+ AC_MSG_RESULT(ok)
+ else
+ AC_MSG_RESULT([Can't find Python.h])
+ PY_LIBS=""
+ PY_CFLAGS=""
+ fi
+fi
+AC_SUBST(PY_CFLAGS)
+AC_SUBST(PY_LIBS)
+
dnl Check for libxml
have_libxml=yes
PKG_CHECK_MODULES(LIBXML, [libxml-2.0], , [
============================================================
--- finch/libgnt/gntwm.c 3958a66a0e6119515eb060ffc29f778e27219173
+++ finch/libgnt/gntwm.c ce13ad41615e73bc546144f8bbaf715d19e055b1
@@ -20,13 +20,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
+#include "config.h"
+
+#ifdef USE_PYTHON
+#include <Python.h>
+#else
#define _GNU_SOURCE
#if (defined(__APPLE__) || defined(__unix__)) && !defined(__FreeBSD__)
#define _XOPEN_SOURCE_EXTENDED
#endif
+#endif
-#include "config.h"
-
#include <glib.h>
#include <glib/gstdio.h>
#include <ctype.h>
@@ -1198,12 +1202,50 @@ ignore_keys_end(GntBindable *bindable, G
return ignore_keys ? !(ignore_keys = FALSE) : FALSE;
}
+#ifdef USE_PYTHON
+static void
+python_script_selected(GntFileSel *fs, const char *path, const char *f, gpointer n)
+{
+ char *dir = g_path_get_dirname(path);
+ FILE *file = fopen(path, "r");
+ PyObject *pp = PySys_GetObject("path"), *dirobj = PyString_FromString(dir);
+
+ PyList_Insert(pp, 0, dirobj);
+ Py_DECREF(dirobj);
+ PyRun_SimpleFile(file, path);
+ fclose(file);
+
+ if (PyErr_Occurred()) {
+ PyErr_Print();
+ }
+ g_free(dir);
+
+ gnt_widget_destroy(GNT_WIDGET(fs));
+}
+
static gboolean
+run_python(GntBindable *bindable, GList *n)
+{
+ GntWidget *window = gnt_file_sel_new();
+ GntFileSel *sel = GNT_FILE_SEL(window);
+
+ g_object_set(G_OBJECT(window), "vertical", TRUE, NULL);
+ gnt_box_add_widget(GNT_BOX(window), gnt_label_new("Please select the python script you want to run."));
+ gnt_box_set_title(GNT_BOX(window), "Select Python Script...");
+
+ g_signal_connect(G_OBJECT(sel), "file_selected", G_CALLBACK(python_script_selected), NULL);
+ g_signal_connect_swapped(G_OBJECT(sel->cancel), "activate", G_CALLBACK(gnt_widget_destroy), sel);
+ gnt_widget_show(window);
+ return TRUE;
+}
+#endif /* USE_PYTHON */
+
+static gboolean
help_for_bindable(GntWM *wm, GntBindable *bindable)
{
gboolean ret = TRUE;
GntBindableClass *klass = GNT_BINDABLE_GET_CLASS(bindable);
-
+
if (klass->help_window) {
gnt_wm_raise_window(wm, GNT_WIDGET(klass->help_window));
} else {
@@ -1271,6 +1313,9 @@ gnt_wm_destroy(GObject *obj)
g_object_unref(wm->workspaces->data);
wm->workspaces = g_list_delete_link(wm->workspaces, wm->workspaces);
}
+#ifdef USE_PYTHON
+ Py_Finalize();
+#endif
}
static void
@@ -1441,6 +1486,12 @@ gnt_wm_class_init(GntWMClass *klass)
GNT_KEY_CTRL_G, NULL);
gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-end", ignore_keys_end,
"\033" GNT_KEY_CTRL_G, NULL);
+#ifdef USE_PYTHON
+ gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "run-python", run_python,
+ GNT_KEY_F3, NULL);
+ Py_SetProgramName("gnt");
+ Py_Initialize();
+#endif
gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
More information about the Commits
mailing list