changeset 18556:5e1412f4e67a

Do some work to make pygnt more useful. The dbus-gnt script works fairly well now.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 17 Jul 2007 11:09:03 +0000
parents ab58b55f38b0
children 212c2bec5c97
files finch/libgnt/gnt-skel.h finch/libgnt/gntfilesel.c finch/libgnt/gnttree.c finch/libgnt/gntwm.h finch/libgnt/gntws.h finch/libgnt/pygnt/Makefile.make finch/libgnt/pygnt/common.c finch/libgnt/pygnt/common.h finch/libgnt/pygnt/dbus-gnt finch/libgnt/pygnt/file.py finch/libgnt/pygnt/gendef.sh finch/libgnt/pygnt/gnt.override finch/libgnt/pygnt/gntfilesel.override finch/libgnt/pygnt/gnttree.override finch/libgnt/pygnt/test.py finch/libgnt/test/multiwin.c
diffstat 16 files changed, 285 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gnt-skel.h	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/gnt-skel.h	Tue Jul 17 11:09:03 2007 +0000
@@ -39,10 +39,6 @@
 #define GNT_IS_SKEL_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_SKEL))
 #define GNT_SKEL_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_SKEL, GntSkelClass))
 
-#define GNT_SKEL_FLAGS(obj)				(GNT_SKEL(obj)->priv.flags)
-#define GNT_SKEL_SET_FLAGS(obj, flags)		(GNT_SKEL_FLAGS(obj) |= flags)
-#define GNT_SKEL_UNSET_FLAGS(obj, flags)	(GNT_SKEL_FLAGS(obj) &= ~(flags))
-
 typedef struct _GntSkel			GntSkel;
 typedef struct _GntSkelPriv		GntSkelPriv;
 typedef struct _GntSkelClass		GntSkelClass;
--- a/finch/libgnt/gntfilesel.c	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/gntfilesel.c	Tue Jul 17 11:09:03 2007 +0000
@@ -48,6 +48,8 @@
 static void (*orig_map)(GntWidget *widget);
 static void (*orig_size_request)(GntWidget *widget);
 
+static void select_activated_cb(GntWidget *button, GntFileSel *sel);
+
 static void
 gnt_file_sel_destroy(GntWidget *widget)
 {
@@ -600,7 +602,33 @@
 static void
 gnt_file_sel_init(GTypeInstance *instance, gpointer class)
 {
-	GNTDEBUG;
+	GntFileSel *sel = GNT_FILE_SEL(instance);
+
+	sel->dirs = gnt_tree_new();
+	gnt_tree_set_compare_func(GNT_TREE(sel->dirs), (GCompareFunc)g_utf8_collate);
+	gnt_tree_set_hash_fns(GNT_TREE(sel->dirs), g_str_hash, g_str_equal, g_free);
+	gnt_tree_set_column_titles(GNT_TREE(sel->dirs), "Directories");
+	gnt_tree_set_show_title(GNT_TREE(sel->dirs), TRUE);
+	gnt_tree_set_col_width(GNT_TREE(sel->dirs), 0, 20);
+	g_signal_connect(G_OBJECT(sel->dirs), "key_pressed", G_CALLBACK(dir_key_pressed), sel);
+
+	sel->files = gnt_tree_new_with_columns(2);  /* Name, Size */
+	gnt_tree_set_compare_func(GNT_TREE(sel->files), (GCompareFunc)g_utf8_collate);
+	gnt_tree_set_column_titles(GNT_TREE(sel->files), "Filename", "Size");
+	gnt_tree_set_show_title(GNT_TREE(sel->files), TRUE);
+	gnt_tree_set_col_width(GNT_TREE(sel->files), 0, 25);
+	gnt_tree_set_col_width(GNT_TREE(sel->files), 1, 10);
+	gnt_tree_set_column_is_right_aligned(GNT_TREE(sel->files), 1, TRUE);
+	g_signal_connect(G_OBJECT(sel->files), "selection_changed", G_CALLBACK(file_sel_changed), sel);
+
+	/* The location entry */
+	sel->location = gnt_entry_new(NULL);
+	g_signal_connect(G_OBJECT(sel->location), "key_pressed", G_CALLBACK(location_key_pressed), sel);
+
+	sel->cancel = gnt_button_new("Cancel");
+	sel->select = gnt_button_new("Select");
+
+	g_signal_connect(G_OBJECT(sel->select), "activate", G_CALLBACK(select_activated_cb), sel);
 }
 
 /******************************************************************************
@@ -647,34 +675,6 @@
 GntWidget *gnt_file_sel_new(void)
 {
 	GntWidget *widget = g_object_new(GNT_TYPE_FILE_SEL, NULL);
-	GntFileSel *sel = GNT_FILE_SEL(widget);
-
-	sel->dirs = gnt_tree_new();
-	gnt_tree_set_compare_func(GNT_TREE(sel->dirs), (GCompareFunc)g_utf8_collate);
-	gnt_tree_set_hash_fns(GNT_TREE(sel->dirs), g_str_hash, g_str_equal, g_free);
-	gnt_tree_set_column_titles(GNT_TREE(sel->dirs), "Directories");
-	gnt_tree_set_show_title(GNT_TREE(sel->dirs), TRUE);
-	gnt_tree_set_col_width(GNT_TREE(sel->dirs), 0, 20);
-	g_signal_connect(G_OBJECT(sel->dirs), "key_pressed", G_CALLBACK(dir_key_pressed), sel);
-
-	sel->files = gnt_tree_new_with_columns(2);  /* Name, Size */
-	gnt_tree_set_compare_func(GNT_TREE(sel->files), (GCompareFunc)g_utf8_collate);
-	gnt_tree_set_column_titles(GNT_TREE(sel->files), "Filename", "Size");
-	gnt_tree_set_show_title(GNT_TREE(sel->files), TRUE);
-	gnt_tree_set_col_width(GNT_TREE(sel->files), 0, 25);
-	gnt_tree_set_col_width(GNT_TREE(sel->files), 1, 10);
-	gnt_tree_set_column_is_right_aligned(GNT_TREE(sel->files), 1, TRUE);
-	g_signal_connect(G_OBJECT(sel->files), "selection_changed", G_CALLBACK(file_sel_changed), sel);
-
-	/* The location entry */
-	sel->location = gnt_entry_new(NULL);
-	g_signal_connect(G_OBJECT(sel->location), "key_pressed", G_CALLBACK(location_key_pressed), sel);
-
-	sel->cancel = gnt_button_new("Cancel");
-	sel->select = gnt_button_new("Select");
-
-	g_signal_connect(G_OBJECT(sel->select), "activate", G_CALLBACK(select_activated_cb), sel);
-
 	return widget;
 }
 
--- a/finch/libgnt/gnttree.c	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/gnttree.c	Tue Jul 17 11:09:03 2007 +0000
@@ -1041,7 +1041,7 @@
 	GntTree *tree = GNT_TREE(widget);
 	tree->show_separator = TRUE;
 	tree->priv = g_new0(GntTreePriv, 1);
-	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y);
+	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_GROW_X | GNT_WIDGET_GROW_Y | GNT_WIDGET_CAN_TAKE_FOCUS);
 	widget->priv.minw = 4;
 	widget->priv.minh = 1;
 	GNTDEBUG;
--- a/finch/libgnt/gntwm.h	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/gntwm.h	Tue Jul 17 11:09:03 2007 +0000
@@ -41,7 +41,7 @@
 #define GNT_IS_WM_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_WM))
 #define GNT_WM_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_WM, GntWMClass))
 
-typedef enum
+typedef enum _GntKeyPressMode
 {
 	GNT_KP_MODE_NORMAL,
 	GNT_KP_MODE_RESIZE,
@@ -49,7 +49,7 @@
 	GNT_KP_MODE_WAIT_ON_CHILD
 } GntKeyPressMode;
 
-typedef struct
+typedef struct _GntNode
 {
 	GntWidget *me;
 
--- a/finch/libgnt/gntws.h	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/gntws.h	Tue Jul 17 11:09:03 2007 +0000
@@ -72,14 +72,14 @@
 GType gnt_ws_get_gtype(void);
 
 GntWS *gnt_ws_new(const char *name);
-void gnt_ws_set_name(GntWS *, const gchar *);
-void gnt_ws_add_widget(GntWS *, GntWidget *);
-void gnt_ws_remove_widget(GntWS *, GntWidget *);
-void gnt_ws_widget_hide(GntWidget *, GHashTable *nodes);
-void gnt_ws_widget_show(GntWidget *, GHashTable *nodes);
-void gnt_ws_draw_taskbar(GntWS *, gboolean reposition);
-void gnt_ws_hide(GntWS *, GHashTable *);
-void gnt_ws_show(GntWS *, GHashTable *);
+void gnt_ws_set_name(GntWS *ws, const gchar *name);
+void gnt_ws_add_widget(GntWS *ws, GntWidget *widget);
+void gnt_ws_remove_widget(GntWS *ws, GntWidget *widget);
+void gnt_ws_widget_hide(GntWidget *widget, GHashTable *nodes);
+void gnt_ws_widget_show(GntWidget *widget, GHashTable *nodes);
+void gnt_ws_draw_taskbar(GntWS *ws, gboolean reposition);
+void gnt_ws_hide(GntWS *ws, GHashTable *table);
+void gnt_ws_show(GntWS *ws, GHashTable *table);
 
 const char * gnt_ws_get_name(GntWS *ws);
 
--- a/finch/libgnt/pygnt/Makefile.make	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/pygnt/Makefile.make	Tue Jul 17 11:09:03 2007 +0000
@@ -2,10 +2,10 @@
 CFLAGS = `pkg-config --cflags gtk+-2.0 pygtk-2.0` -I/usr/include/python2.4/ -I.. -g -O0
 LDFLAGS = `pkg-config --libs gtk+-2.0 pygtk-2.0 gnt`
  
-gnt.so: gnt.o gntmodule.o
+gnt.so: gnt.o gntmodule.o common.o
 	$(CC) $(LDFLAGS) -shared $^ -o $@
 
-gnt.c: gnt.def gnt.override
+gnt.c: gnt.def *.override common.c common.h
 	pygtk-codegen-2.0 --prefix gnt \
 	--override gnt.override \
 	gnt.def > $@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/common.c	Tue Jul 17 11:09:03 2007 +0000
@@ -0,0 +1,24 @@
+#include "common.h"
+
+PyObject *
+create_pyobject_from_string_list(GList *list)
+{
+	PyObject *py_list;
+	if (list == NULL) {
+		Py_INCREF(Py_None);
+		return Py_None;
+	}
+	if ((py_list = PyList_New(0)) == NULL) {
+		g_list_foreach(list, (GFunc)g_free, NULL);
+		g_list_free(list);
+		return NULL;
+	}
+	while (list) {
+		PyObject *obj = PyString_FromString(list->data);
+		PyList_Append(py_list, obj);
+		Py_DECREF(obj);
+		g_free(list->data);
+		list = g_list_delete_link(list, list);
+	}
+	return py_list;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/common.h	Tue Jul 17 11:09:03 2007 +0000
@@ -0,0 +1,5 @@
+#include "Python.h"
+#include "gnt.h"
+
+PyObject *create_pyobject_from_string_list(GList *list);
+
--- a/finch/libgnt/pygnt/dbus-gnt	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/pygnt/dbus-gnt	Tue Jul 17 11:09:03 2007 +0000
@@ -11,6 +11,7 @@
 import gobject
 import os
 import gnt
+import sys
 
 from time import strftime
 
@@ -33,8 +34,7 @@
     tv.append_text_with_flags(who + ": ", 1)
     tv.append_text_with_flags(msg, 0)
     tv.scroll(0)
-
-gnt.gnt_init()
+    stuff[0].set_urgent()
 
 bus = dbus.SessionBus()
 obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
@@ -93,6 +93,30 @@
     convwins[key] = [win, tv, entry]
     return convwins[key]
 
+def show_buddylist():
+	win = gnt.Window()
+	tree = gnt.Tree()
+	tree.set_property("columns", 1)
+	win.add_widget(tree)
+	node = purple.PurpleBlistGetRoot()
+	while node:
+		if purple.PurpleBlistNodeIsGroup(node):
+			sys.stderr.write(str(node) + "\n")
+			tree.add_row_after(str(node), ["asd", ""], None, None)
+			#tree.add_row_after(node, [str(purple.PurpleGroupGetName(node)), ""], None, None)
+			#tree.add_row_after(node, ["aasd", ""], None, None)
+		elif purple.PurpleBlistNodeIsContact(node):
+			buddy = purple.PurpleContactGetPriorityBuddy(node)
+			group = purple.PurpleBuddyGetGroup(buddy)
+			#tree.add_row_after(node, [str(purple.PurpleBuddyGetName(buddy)), ""], group, None)
+
+		node = purple.PurpleBlistNodeNext(node, False)
+	win.show()
+
+gnt.gnt_init()
+
+# show_buddylist()
+
 convs = purple.PurpleGetConversations()
 for conv in convs:
     show_conversation(conv)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/file.py	Tue Jul 17 11:09:03 2007 +0000
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+import gnt, sys
+
+def file_selected(widget, path, file, null):
+	sys.stderr.write(path + " " + file)
+	list = widget.get_selected_multi_files()
+	for i in list:
+		sys.stderr.write(i)
+
+gnt.gnt_init()
+
+win = gnt.Window()
+
+files = gnt.FileSel()
+files.set_multi_select(True)
+files.set_title("Files")
+files.connect("file_selected", file_selected, None)
+
+files.show()
+
+gnt.gnt_main()
+
+gnt.gnt_quit()
--- a/finch/libgnt/pygnt/gendef.sh	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/pygnt/gendef.sh	Tue Jul 17 11:09:03 2007 +0000
@@ -17,12 +17,14 @@
 	gntmenu.h
 	gntmenuitem.h
 	gntmenuitemcheck.h
+	gntslider.h
 	gntstyle.h
 	gnttextview.h
 	gnttree.h
 	gntutils.h
 	gntwindow.h
 	gntwm.h
+	gntws.h
 	gnt.h"
 
 # Generate the def file
--- a/finch/libgnt/pygnt/gnt.override	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/pygnt/gnt.override	Tue Jul 17 11:09:03 2007 +0000
@@ -18,12 +18,19 @@
 #include "gntmenu.h"
 #include "gntmenuitem.h"
 #include "gntmenuitemcheck.h"
+#include "gntslider.h"
 #include "gntstyle.h"
 #include "gnttextview.h"
 #include "gnttree.h"
 #include "gntutils.h"
 #include "gntwindow.h"
 #include "gntwm.h"
+#include "gntws.h"
+#include "common.h"
+%%
+include
+ gntfilesel.override
+ gnttree.override
 %%
 modulename gnt
 %%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/gntfilesel.override	Tue Jul 17 11:09:03 2007 +0000
@@ -0,0 +1,33 @@
+/**
+ * pygnt- Python bindings for the GNT toolkit.
+ * Copyright (C) 2007 Sadrul Habib Chowdhury <sadrul@pidgin.im>
+ *
+ *   gntfilesel.override: overrides for the file selector.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+%%
+headrs
+#include "common.h"
+%%
+override gnt_file_sel_get_selected_multi_files noargs
+static PyObject *
+_wrap_gnt_file_sel_get_selected_multi_files(PyGObject *self)
+{
+	GList *list = gnt_file_sel_get_selected_multi_files(GNT_FILE_SEL(self->obj));
+	return create_pyobject_from_string_list(list);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/gnttree.override	Tue Jul 17 11:09:03 2007 +0000
@@ -0,0 +1,103 @@
+/**
+ * pygnt- Python bindings for the GNT toolkit.
+ * Copyright (C) 2007 Sadrul Habib Chowdhury <sadrul@pidgin.im>
+ *
+ *   gnttree.override: overrides for the tree widget.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+%%
+headrs
+#include "common.h"
+%%
+ignore 
+gnt_tree_create_row
+gnt_tree_create_row_from_list
+%%
+override gnt_tree_get_selection_text_list noargs
+static PyObject *
+_wrap_gnt_tree_get_selection_text_list(PyGObject *self)
+{
+	GList *list = gnt_tree_get_selection_text_list(GNT_TREE(self->obj));
+	return create_pyobject_from_string_list(list);
+}
+%%
+override gnt_tree_get_rows noargs
+static PyObject *
+_wrap_gnt_tree_get_rows(PyGObject *self)
+{
+	GList *list = gnt_tree_get_rows(GNT_TREE(self->obj));
+	PyObject *py_list;
+	if (list == NULL) {
+		Py_INCREF(Py_None);
+		return Py_None;
+	}
+	if ((py_list = PyList_New(0)) == NULL) {
+		return NULL;
+	}
+	while (list) {
+		PyObject *obj = pyg_pointer_new(G_TYPE_POINTER, list->data);
+		PyList_Append(py_list, obj);
+		Py_DECREF(obj);
+		list = list->next;
+	}
+	return py_list;
+}
+%%
+override gnt_tree_add_row_after
+static PyObject *
+_wrap_gnt_tree_add_row_after(PyGObject *self, PyObject *args)
+{
+	static char *kwlist[] = {"key", "row", "parent", "bigbro", NULL};
+	PyObject *py_list;
+	gpointer key, parent, bigbro;
+	int len, i;
+	GList *list = NULL;
+	GntTreeRow *row;
+
+	if (!PyArg_ParseTuple(args,
+				"OOOO:GntTree.add_row_after",
+				&key,
+				&py_list,
+				&parent,
+				&bigbro))
+		return NULL;
+
+	len = PySequence_Length(py_list);
+	for (i = 0; i < len; i++) {
+		PyObject *item = PySequence_GetItem(py_list, i);
+		if (!pygobject_check(item, &PyString_Type)) {
+			PyErr_SetString(PyExc_TypeError,
+					"column_list members must be strings");
+			Py_DECREF(item);
+			return NULL;
+		}
+		list = g_list_prepend(list, PyString_AsString(item));
+		Py_DECREF(item);
+	}
+
+	list = g_list_reverse(list);
+	row = gnt_tree_create_row_from_list(GNT_TREE(self->obj), list);
+	gnt_tree_add_row_after(GNT_TREE(self->obj),
+			key,
+			row,
+			parent, bigbro);
+	g_list_free(list);
+
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
--- a/finch/libgnt/pygnt/test.py	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/pygnt/test.py	Tue Jul 17 11:09:03 2007 +0000
@@ -1,8 +1,12 @@
 #!/usr/bin/python
 import gnt
 
-def button_activate(button, entry):
-	entry.set_text("clicked!!!")
+def button_activate(button, tree):
+	list = tree.get_selection_text_list()
+	str = ""
+	for i in list:
+		str = str + i
+	entry.set_text("clicked!!!" + str)
 
 gnt.gnt_init()
 
@@ -16,7 +20,18 @@
 button = gnt.Button("Click!")
 win.add_widget(button)
 
-button.connect("activate", button_activate, entry)
+tree = gnt.Tree()
+tree.set_property("columns", 1)
+win.add_widget(tree)
+
+# so random non-string values can be used as the key for a row in a GntTree!
+last = None
+for i in range(1, 100):
+	tree.add_row_after(i, [str(i), ""], None, i-1)
+tree.add_row_after(entry, ["asd"], None, None)
+tree.add_row_after("b", ["123", ""], entry, None)
+
+button.connect("activate", button_activate, tree)
 
 win.show()
 
--- a/finch/libgnt/test/multiwin.c	Mon Jul 16 23:59:58 2007 +0000
+++ b/finch/libgnt/test/multiwin.c	Tue Jul 17 11:09:03 2007 +0000
@@ -27,6 +27,7 @@
 	gnt_widget_set_name(box2, "box2");
 
 	tree = gnt_tree_new_with_columns(3);
+	gnt_tree_set_search_column(GNT_TREE(tree), 1);
 	GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER);
 	gnt_tree_set_column_titles(GNT_TREE(tree), "12345678901234567890", "column 2", "column3");
 	gnt_tree_set_show_title(GNT_TREE(tree), TRUE);
@@ -62,8 +63,6 @@
 
 	gnt_tree_add_row_after(GNT_TREE(tree), "6", gnt_tree_create_row(GNT_TREE(tree), "6", " long text", "a2"), "4", NULL);
 
-	gnt_tree_add_row_after(GNT_TREE(tree), NULL, gnt_tree_create_separator(GNT_TREE(tree)), NULL, "c");
-
 	int i;
 	for (i = 110; i < 430; i++)
 	{