changeset 15932:8fd5ab3f9716

python bindings for libgnt. dbus-gnt is a gnt-ui (sort of) for gaim over dbus. It allows continuing with the currently opened conversations. pygnt/README.txt explains what to do. Use at your own risk.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 26 Mar 2007 04:19:35 +0000
parents f00f2e283ffb
children 7fae8140b5b3
files finch/libgnt/pygnt/Files.txt finch/libgnt/pygnt/README.txt finch/libgnt/pygnt/dbus-gnt finch/libgnt/pygnt/gendef.sh finch/libgnt/pygnt/gnt.override finch/libgnt/pygnt/gntmodule.c finch/libgnt/pygnt/test.py
diffstat 7 files changed, 246 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/Files.txt	Mon Mar 26 04:19:35 2007 +0000
@@ -0,0 +1,6 @@
+gendef.sh
+gnt.override
+Makefile
+test.py
+dbus-gnt
+gntmodule.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/README.txt	Mon Mar 26 04:19:35 2007 +0000
@@ -0,0 +1,4 @@
+Run these in sequence:
+
+./gendef.sh
+make gnt.so
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/dbus-gnt	Mon Mar 26 04:19:35 2007 +0000
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+
+# This script requires Python 2.4 and pygnt bindings
+#
+# Note that all function names are resolved dynamically, no
+# purple-specific library is needed.
+
+import dbus
+import dbus.glib
+import dbus.decorators
+import gobject
+import os
+import gnt
+
+from time import strftime
+
+convwins = {}
+
+def buddysignedon():
+    pass
+
+def conv_closed(conv):
+    key = get_dict_key(conv)
+    stuff = convwins[key]
+    stuff[0].destroy()
+    convwins[key] = None
+
+def wrote_msg(account, who, msg, conv, flags):
+    stuff = show_conversation(conv)
+    tv = stuff[1]
+    tv.append_text_with_flags("\n", 0)
+    tv.append_text_with_flags(strftime("(%X) "), 8)
+    tv.append_text_with_flags(who + ": ", 1)
+    tv.append_text_with_flags(msg, 0)
+    tv.scroll(0)
+
+gnt.gnt_init()
+
+bus = dbus.SessionBus()
+obj = bus.get_object("net.sf.purple.PurpleService", "/net/sf/purple/PurpleObject")
+purple = dbus.Interface(obj, "net.sf.purple.PurpleInterface")
+
+bus.add_signal_receiver(buddysignedon,
+                        dbus_interface = "net.sf.purple.PurpleInterface",
+                        signal_name = "BuddySignedOn")
+
+bus.add_signal_receiver(wrote_msg,
+                        dbus_interface = "net.sf.purple.PurpleInterface",
+                        signal_name = "WroteImMsg")
+
+bus.add_signal_receiver(wrote_msg,
+                        dbus_interface = "net.sf.purple.PurpleInterface",
+                        signal_name = "WroteChatMsg")
+
+bus.add_signal_receiver(conv_closed,
+                        dbus_interface = "net.sf.purple.PurpleInterface",
+                        signal_name = "DeletingConversation")
+
+def get_dict_key(conv):
+    val = purple.PurpleConversationGetName(conv)
+    return val
+
+def send_im_cb(entry, key, conv):
+    if key[0] == '\r':
+        # XXX: do something about the / commands
+        type = purple.PurpleConversationGetType(conv)
+        if type == 1:
+            imdata = purple.PurpleConversationGetImData(conv)
+            purple.PurpleConvImSend(imdata, entry.get_text())
+        else:
+            chatdata = purple.PurpleConversationGetChatData(conv)
+            purple.PurpleConvChatSend(chatdata, entry.get_text())
+        entry.clear()
+
+def show_conversation(conv):
+    key = get_dict_key(conv)
+    if key in convwins:
+        return convwins[key]
+    win = gnt.Window()
+    vbox = gnt.Box(0, 1)
+    win.add_widget(vbox)
+    win.set_title(purple.PurpleConversationGetName(conv))
+    win.set_pad(0)
+    vbox.set_pad(0)
+    tv = gnt.TextView()
+    entry = gnt.Entry("")
+    vbox.add_widget(tv)
+    entry.set_size(40, 1)
+    vbox.add_widget(entry)
+    entry.connect("key_pressed", send_im_cb, conv)
+    tv.clear()
+    win.show()
+    convwins[key] = [win, tv, entry]
+    return convwins[key]
+
+convs = purple.PurpleGetConversations()
+for conv in convs:
+    show_conversation(conv)
+
+gnt.gnt_main()
+
+gnt.gnt_quit()
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/gendef.sh	Mon Mar 26 04:19:35 2007 +0000
@@ -0,0 +1,51 @@
+#!/bin/sh
+FILES="
+	gntwidget.h
+	gntbindable.h
+	gntbox.h
+	gntbutton.h
+	gntcheckbox.h
+	gntclipboard.h
+	gntcolors.h
+	gntcombobox.h
+	gntentry.h
+	gntfilesel.h
+	gntkeys.h
+	gntlabel.h
+	gntline.h
+	gntmarshal.h
+	gntmenu.h
+	gntmenuitem.h
+	gntmenuitemcheck.h
+	gntstyle.h
+	gnttextview.h
+	gnttree.h
+	gntutils.h
+	gntwindow.h
+	gntwm.h
+	gnt.h"
+
+# Generate the def file
+rm gnt.def
+for file in $FILES
+do
+	python /usr/share/pygtk/2.0/codegen/h2def.py ../$file >> gnt.def
+done
+
+# Remove the definitions about the enums
+ENUMS="
+GNT_TYPE_ALIGNMENT
+GNT_TYPE_COLOR_TYPE
+GNT_TYPE_MENU_TYPE
+GNT_TYPE_STYLE
+GNT_TYPE_KEY_PRESS_MODE
+GNT_TYPE_ENTRY_FLAG
+GNT_TYPE_TEXT_FORMAT_FLAGS
+"
+
+for enum in $ENUMS
+do
+	sed -ie s/^.*gtype-id\ \"$enum\".*$//g gnt.def
+done
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/gnt.override	Mon Mar 26 04:19:35 2007 +0000
@@ -0,0 +1,34 @@
+%%
+headers
+#include <Python.h>
+#include "pygobject.h"
+#include "gnt.h"
+#include "gntbindable.h"
+#include "gntwidget.h"
+#include "gntbox.h"
+#include "gntbutton.h"
+#include "gntcheckbox.h"
+#include "gntcolors.h"
+#include "gntcombobox.h"
+#include "gntentry.h"
+#include "gntfilesel.h"
+#include "gntkeys.h"
+#include "gntlabel.h"
+#include "gntline.h"
+#include "gntmenu.h"
+#include "gntmenuitem.h"
+#include "gntmenuitemcheck.h"
+#include "gntstyle.h"
+#include "gnttextview.h"
+#include "gnttree.h"
+#include "gntutils.h"
+#include "gntwindow.h"
+#include "gntwm.h"
+%%
+modulename gnt
+%%
+import gobject.GObject as PyGObject_Type
+%%
+ignore-glob
+	*_get_gtype
+%%
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/gntmodule.c	Mon Mar 26 04:19:35 2007 +0000
@@ -0,0 +1,22 @@
+#include <pygobject.h>
+ 
+void gnt_register_classes (PyObject *d); 
+extern PyMethodDef gnt_functions[];
+ 
+DL_EXPORT(void)
+initgnt(void)
+{
+    PyObject *m, *d;
+ 
+    init_pygobject ();
+ 
+    m = Py_InitModule ("gnt", gnt_functions);
+    d = PyModule_GetDict (m);
+ 
+    gnt_register_classes (d);
+ 
+    if (PyErr_Occurred ()) {
+        Py_FatalError ("can't initialise module sad");
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/libgnt/pygnt/test.py	Mon Mar 26 04:19:35 2007 +0000
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+import gnt
+
+def button_activate(button, entry):
+	entry.set_text("clicked!!!")
+
+gnt.gnt_init()
+
+win = gnt.Window()
+
+entry = gnt.Entry("")
+
+win.add_widget(entry)
+win.set_title("Entry")
+
+button = gnt.Button("Click!")
+win.add_widget(button)
+
+button.connect("activate", button_activate, entry)
+
+win.show()
+
+gnt.gnt_main()
+
+gnt.gnt_quit()
+