Index: configure.in
===================================================================
RCS file: /cvs/gnome/glade3/configure.in,v
retrieving revision 1.73
diff -u -u -p -r1.73 configure.in
--- configure.in	29 Sep 2006 18:01:59 -0000	1.73
+++ configure.in	9 Oct 2006 20:57:11 -0000
@@ -57,6 +57,30 @@ AC_SUBST(GTK_LIBS)
 AC_SUBST(GTK_CFLAGS)
 
 dnl ================================================================
+dnl Check for Python
+dnl ================================================================
+AC_ARG_ENABLE(python,
+[  --disable-python         disable python scripting module],
+	check_python=$enableval, check_python=yes)
+
+if test x"$check_python" = x"yes"; then
+	PYTHON="nop"
+	AC_PATH_PROGS([PYTHON], [python-config python2.5-config python2.4-config])
+
+	if test "$PYTHON" != "nop"; then
+		PYTHON_CFLAGS=`$PYTHON --cflags`
+		PYTHON_LIBS=`$PYTHON --libs`
+		AC_SUBST(PYTHON_CFLAGS)
+		AC_SUBST(PYTHON_LIBS)
+		have_python=yes
+	fi
+else
+	have_python=no
+fi
+
+AM_CONDITIONAL(BUILD_PYTHON, test x"$have_python" = "xyes")
+
+dnl ================================================================
 dnl Check for optional gnome libs
 dnl ================================================================
 AC_ARG_ENABLE(gnome,
@@ -129,5 +153,6 @@ Configuration:
 	Source code location:	${srcdir}
 	Compiler:		${CC} 
 	GnomeUI Catalog:	${have_gnome}
+	Python Scripting:	${have_python}
 
 "
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/glade3/src/Makefile.am,v
retrieving revision 1.59
diff -u -u -p -r1.59 Makefile.am
--- src/Makefile.am	13 Jul 2006 21:38:19 -0000	1.59
+++ src/Makefile.am	9 Oct 2006 20:57:12 -0000
@@ -141,6 +141,15 @@ libgladeuiinclude_HEADERS = \
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libgladeui-1.0.pc glade-3.pc
 
+if BUILD_PYTHON
+gladepython_LTLIBRARIES = libgladepython.la
+gladepythondir = $(glade_modulesdir)
+libgladepython_la_SOURCES = glade-python.c
+libgladepython_la_CFLAGS = -g -Wall $(PYTHON_CFLAGS) $(GTK_CFLAGS)
+libgladepython_la_LDFLAGS = -module -avoid-version $(PYTHON_LIBS)
+libgladepython_la_LIBADD = libgladeui-1.la $(PYTHON_LIBS)
+endif
+
 if BUILD_GNOME
 gladegnome_LTLIBRARIES = libgladegnome.la
 gladegnomedir = $(glade_modulesdir)
@@ -156,6 +165,10 @@ if WITH_WIN32
 
 if BUILD_GNOME
   libgladegnome_la_LDFLAGS += -no-undefined
+endif
+
+if BUILD_PYTHON
+  libgladepython_la_LDFLAGS += -no-undefined
 endif
 
 endif
Index: src/glade-app.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-app.c,v
retrieving revision 1.46
diff -u -u -p -r1.46 glade-app.c
--- src/glade-app.c	12 Aug 2006 01:34:00 -0000	1.46
+++ src/glade-app.c	9 Oct 2006 20:57:13 -0000
@@ -104,6 +104,17 @@ gboolean glade_verbose = FALSE;
 static GObjectClass   * parent_class = NULL;
 static GladeApp       * the_app = NULL;
 
+typedef struct _GladePython GladePython ;
+struct _GladePython {
+	GModule  *module;
+	
+	/* Glade Module symbols */
+	void       (*python_init)(void);
+	gboolean   (*run_string) (gchar *str);
+	GtkWidget *(*console_new)(void);
+};
+
+static GladePython *python = NULL;
 
 /*****************************************************************
  *                    GObjectClass                               *
@@ -1494,4 +1505,51 @@ glade_app_selection_changed (void)
 		project = list->data;
 		glade_project_selection_changed (project);
 	}
+}
+
+
+/* Python Module */
+gboolean
+glade_app_python_init ()
+{
+	GModule *module;
+	
+	if (python) return TRUE;
+	
+	if ((module = glade_util_load_library ("gladepython")) == NULL)
+		return FALSE;
+	
+	python = g_new0 (GladePython, 1);
+	python->module = module;
+	
+	g_module_symbol (module, "glade_python_init", (gpointer)&python->python_init);
+	g_module_symbol (module, "glade_python_run_string", (gpointer)&python->run_string);
+	g_module_symbol (module, "glade_python_console_new", (gpointer)&python->console_new);
+	
+	if (python->python_init && python->run_string && python->console_new) 
+	{
+		python->python_init ();
+		return TRUE;
+	}
+	else
+	{
+		g_module_close (module);
+		g_free (python);
+		python = NULL;
+		return FALSE;
+	}
+}
+
+gboolean
+glade_app_python_run_string (gchar *str)
+{
+	if (python == NULL) return FALSE;
+	return python->run_string (str);
+}
+
+GtkWidget *
+glade_app_python_console_new ()
+{
+	if (python == NULL) return NULL;
+	return python->console_new ();
 }
Index: src/glade-app.h
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-app.h,v
retrieving revision 1.20
diff -u -u -p -r1.20 glade-app.h
--- src/glade-app.h	12 Aug 2006 01:34:01 -0000	1.20
+++ src/glade-app.h	9 Oct 2006 20:57:14 -0000
@@ -161,6 +161,15 @@ void               glade_app_selection_c
 LIBGLADEUI_API 
 void               glade_app_selection_changed(void);
 
+/* Python Plugin, for now... */
+LIBGLADEUI_API
+gboolean           glade_app_python_init (void);
+
+LIBGLADEUI_API
+gboolean           glade_app_python_run_string (gchar *str);
+
+LIBGLADEUI_API
+GtkWidget         *glade_app_python_console_new (void);
 
 G_END_DECLS
 
Index: src/glade-project-window.c
===================================================================
RCS file: /cvs/gnome/glade3/src/glade-project-window.c,v
retrieving revision 1.167
diff -u -u -p -r1.167 glade-project-window.c
--- src/glade-project-window.c	1 Oct 2006 02:31:40 -0000	1.167
+++ src/glade-project-window.c	9 Oct 2006 20:57:17 -0000
@@ -1190,6 +1190,28 @@ gpw_show_clipboard_cb (GtkAction *action
 		gpw_show_clipboard_view (gpw);
 }
 
+static void
+gpw_show_python_console_cb (GtkAction *action, GladeProjectWindow *gpw)
+{
+	static gboolean init = TRUE, initialized;
+	
+	if (init)
+	{
+		initialized = glade_app_python_init ();
+		init = FALSE;
+	}
+	
+	if (initialized)
+	{
+		GtkWidget *console = glade_app_python_console_new ();
+		if (console)
+		{
+			gtk_widget_show_all (console);
+			gtk_widget_set_size_request (console, 640, 480);
+		}
+	}
+}
+
 void
 glade_project_window_prev_project_cb (GtkAction *action, GladeProjectWindow *window)
 {
@@ -1361,6 +1383,7 @@ static const gchar *ui_info =
 "      <menuitem action='PropertyEditor'/>\n"
 "      <menuitem action='Clipboard'/>\n"
 "      <menuitem action='Palette'/>\n"
+"      <menuitem action='Python'/>\n"
 "      <separator/>\n"
 "      <menu action='PaletteAppearance'>\n"
 "        <menuitem action='IconsAndLabels'/>\n"
@@ -1470,7 +1493,10 @@ static GtkActionEntry project_entries[] 
 	{ "Clipboard", NULL, N_("_Clipboard"), NULL,
 	  N_("Show the clipboard"),
 	  G_CALLBACK (gpw_show_clipboard_cb) },
-
+	  
+	{ "Python", NULL, "Monty's Console", NULL,
+	  NULL, G_CALLBACK (gpw_show_python_console_cb) },
+	  
 	/* ProjectsMenu */
 	{ "PreviousProject", NULL, N_("_Previous Project"), "<control>Page_Up",
 	  N_("Activate previous project"), G_CALLBACK (glade_project_window_prev_project_cb) },
Index: src/glade-python.c
===================================================================
RCS file: src/glade-python.c
diff -N src/glade-python.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/glade-python.c	9 Oct 2006 20:57:17 -0000
@@ -0,0 +1,266 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006 Juan Pablo Ugarte.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Authors:
+ *   Juan Pablo Ugarte <juanpablougarte@gmail.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Python.h>
+#include <glade.h>
+
+GtkTextBuffer *buffer = NULL;
+static PyObject *GladeError, *GladeStdout, *GladeStderr;
+
+static PyObject *
+glade_python_undo (PyObject *self, PyObject *args)
+{
+	glade_app_command_undo ();
+	
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyObject *
+glade_python_redo (PyObject *self, PyObject *args)
+{
+	glade_app_command_redo ();
+	
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyObject *
+glade_python_project_new (PyObject *self, PyObject *args)
+{	
+	glade_app_add_project (glade_project_new (TRUE));
+
+	glade_app_update_ui ();
+	
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyObject *
+glade_python_project_open (PyObject *self, PyObject *args)
+{
+	gchar *path;
+	
+	Py_INCREF(Py_None);
+	
+	if (PyArg_ParseTuple(args, "s", &path))
+	{
+		GladeProject *project;
+		
+		if ((project = glade_app_get_project_by_path (path)))
+			glade_app_set_project (project);
+		else if ((project = glade_project_open (path)))
+			glade_app_add_project (project);
+		else
+			return Py_None;
+
+		glade_app_update_ui ();
+	}
+	
+	return Py_None;
+}
+
+static PyObject *
+glade_python_project_save (PyObject *self, PyObject *args)
+{
+	gchar *path;
+	
+	if (PyArg_ParseTuple(args, "s", &path))
+		glade_project_save (glade_app_get_project (), path, NULL);
+	
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+static PyMethodDef GladeMethods[] = {
+    {"undo",  glade_python_undo, METH_VARARGS, "Execute undo command."},
+    {"redo",  glade_python_redo, METH_VARARGS, "Execute redo command."},
+    {"project_new",  glade_python_project_new, METH_VARARGS, "Execute redo command."},
+    {"project_open",  glade_python_project_open, METH_VARARGS, "Execute redo command."},
+    {"project_save",  glade_python_project_save, METH_VARARGS, "Execute redo command."},
+    {NULL, NULL, 0, NULL}
+};
+
+/* GladeStdout GladeStderr write method */
+static PyObject *
+glade_python_std_write (PyObject *self, PyObject *args, gboolean stdout)
+{
+	gchar *string;
+	
+	if (PyArg_ParseTuple(args, "s", &string))
+	{
+		GtkTextIter iter;
+		gtk_text_buffer_get_end_iter (buffer, &iter);
+		if (stdout)
+			gtk_text_buffer_insert (buffer, &iter, string, -1);
+		else
+			gtk_text_buffer_insert_with_tags_by_name (buffer, 
+				&iter, string, -1, "red_foreground", NULL);
+	}
+	
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
+/* GladeStdout methods */
+static PyObject *
+glade_python_stdout_write (PyObject *self, PyObject *args)
+{
+	return glade_python_std_write (self, args, TRUE);
+}
+
+static PyObject *
+glade_python_get_stdout (PyObject *self, PyObject *args)
+{
+	return GladeStdout;
+}
+
+static PyMethodDef GladeStdoutMethods[] = {
+    {"write",  glade_python_stdout_write, METH_VARARGS, NULL},
+    {"get_object",  glade_python_get_stdout, METH_VARARGS, NULL},
+    {NULL, NULL, 0, NULL}
+};
+
+/* GladeStderr methods */
+static PyObject *
+glade_python_stderr_write (PyObject *self, PyObject *args)
+{
+	return glade_python_std_write (self, args, FALSE);
+}
+
+static PyObject *
+glade_python_get_stderr (PyObject *self, PyObject *args)
+{
+	return GladeStderr;
+}
+
+static PyMethodDef GladeStderrMethods[] = {
+    {"write",  glade_python_stderr_write, METH_VARARGS, NULL},
+    {"get_object",  glade_python_get_stderr, METH_VARARGS, NULL},
+    {NULL, NULL, 0, NULL}
+};
+
+/* Console */
+static void
+glage_guile_console_entry_activate (GtkEntry *entry, GtkTextView *textview)
+{
+	const gchar *command = gtk_entry_get_text (entry);
+	GtkTextIter iter;
+	
+	gtk_text_buffer_get_end_iter (buffer, &iter);
+	gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, ">>> ", -1,
+						  "blue_foreground", NULL);
+	gtk_text_buffer_get_end_iter (buffer, &iter);
+	gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, command, -1,
+						  "blue_foreground", NULL);
+	gtk_text_buffer_get_end_iter (buffer, &iter);
+	gtk_text_buffer_insert (buffer, &iter, "\n", -1);
+	
+	if (PyRun_SimpleString (command) == 0) gtk_entry_set_text (entry, "");
+
+	/* agregar esto en una funcion idle!!! */
+	gtk_text_buffer_get_end_iter (buffer, &iter);
+	gtk_text_view_scroll_to_iter (textview, &iter, 0.0, TRUE, 0.0, 1.0);
+}
+
+void
+glade_python_init (void)
+{
+	PyObject *glade;
+	GtkTextIter iter;
+	
+	if (buffer == NULL)
+	{	
+		buffer = gtk_text_buffer_new (NULL);
+		gtk_text_buffer_create_tag (buffer, "blue_foreground",
+					    "foreground", "blue", NULL);  
+		gtk_text_buffer_create_tag (buffer, "red_foreground",
+					    "foreground", "red", NULL);  
+	}
+	else return;
+	
+    	Py_SetProgramName (PACKAGE_NAME);
+	
+    	/* Initialize the Python interpreter if it is not */
+    	if (Py_IsInitialized() == FALSE) Py_Initialize ();
+
+	glade = Py_InitModule ("glade", GladeMethods);
+	GladeError = PyErr_NewException ("glade.error", NULL, NULL);
+	Py_INCREF (GladeError);
+	PyModule_AddObject (glade, "error", GladeError);
+	
+	GladeStdout = Py_InitModule ("glade_stdout", GladeStdoutMethods);
+	GladeStderr = Py_InitModule ("glade_stderr", GladeStderrMethods);
+	
+	PyRun_SimpleString ("import sys; import glade; import glade_stdout; import glade_stderr; sys.stdout=glade_stdout.get_object(); sys.stderr=glade_stderr.get_object();");
+
+	gtk_text_buffer_get_end_iter (buffer, &iter);
+	gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, ">>> import sys;\n>>> import glade;\n", -1,
+						  "blue_foreground", NULL);
+}
+
+gboolean
+glade_python_run_string (gchar *str)
+{
+	return !PyRun_SimpleString (str);
+}
+
+GtkWidget *
+glade_python_console_new (void)
+{
+	GtkWidget *dialog, *hbox, *textview, *entry, *sw;
+   
+	dialog = gtk_dialog_new_with_buttons ("Ptyhon Console", NULL, 0,
+					      GTK_STOCK_CLOSE, GTK_RESPONSE_NONE,
+					      NULL);
+	g_signal_connect_swapped (dialog, "response", 
+				  G_CALLBACK (gtk_widget_destroy), dialog);
+
+	textview = gtk_text_view_new_with_buffer (buffer);
+	gtk_text_view_set_editable (GTK_TEXT_VIEW (textview), FALSE);
+	gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textview), FALSE);
+
+	sw = gtk_scrolled_window_new (NULL, NULL);
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+					GTK_POLICY_AUTOMATIC,
+					GTK_POLICY_AUTOMATIC);
+	gtk_container_add (GTK_CONTAINER (sw), textview);
+	
+	gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox), sw, TRUE, TRUE, 0);
+	
+	hbox = gtk_hbox_new (FALSE, 4);
+	gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (">>>"), FALSE, FALSE, 0);
+	
+	entry = gtk_entry_new ();
+	g_signal_connect (entry, "activate", 
+			  G_CALLBACK (glage_guile_console_entry_activate),
+			  GTK_TEXT_VIEW (textview));
+	gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+	
+	gtk_box_pack_start (GTK_BOX (GTK_DIALOG(dialog)->vbox), hbox, FALSE, TRUE, 0);
+	
+	return dialog;
+}
Index: src/main.c
===================================================================
RCS file: /cvs/gnome/glade3/src/main.c,v
retrieving revision 1.55
diff -u -u -p -r1.55 main.c
--- src/main.c	19 Aug 2006 18:48:55 -0000	1.55
+++ src/main.c	9 Oct 2006 20:57:18 -0000
@@ -174,7 +174,7 @@ main (int argc, char *argv[])
 
 	if (glade_app_get_project () == NULL)
 		glade_project_window_new_project (project_window);
-
+	
 	glade_project_window_show_all (project_window);
 
 	gtk_main ();
