Author: gwadavel
Date: 2008-11-30 23:17:31 +0100 (Sun, 30 Nov 2008)
New Revision: 2943
Added:
software_suite_v2/software/scripts/pidgin/trunk/tux_pidgin_chat.py
Log:
add tux_pidgin_chat pidgin IM + Chat
Added: software_suite_v2/software/scripts/pidgin/trunk/tux_pidgin_chat.py
===================================================================
--- software_suite_v2/software/scripts/pidgin/trunk/tux_pidgin_chat.py
(rev 0)
+++ software_suite_v2/software/scripts/pidgin/trunk/tux_pidgin_chat.py
2008-11-30 22:17:31 UTC (rev 2943)
@@ -0,0 +1,189 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# -----------------------------------------------------------------------------
+# Tux Droid - Pidgin InterFace
+#
+# 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, 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.
+# -----------------------------------------------------------------------------
+# $Id: $
+# -----------------------------------------------------------------------------
+
+"""
+CHANGES
+=======
+2008/11/26 - version 0.3
+ - Add Chat messages, language English and French
+2008/11/26 - version 0.2.1:
+ - Translation TuxDroid V2 by Gwadavel
+2007/05/26 - version 0.2:
+ - Tuxdroid speaks with TTS voices that say the contact on pidgin
+
+2007/05/21 - version 0.1:
+ - Initial version
+
+TODO LIST
+========
+- Make some actions when a conversation started
+- Make Gadget
+"""
+
+__author__ = "Thomas CARPENTIER <[EMAIL PROTECTED]> & Julien Ruchaud \
+& Gwadavel"
+__appname__ = "TuxPidgin"
+__version__ = "0.3"
+__date__ = "2007/05/26"
+__license__ = "GPL"
+
+# -----------------------------------------------
+# Initalization of modules
+# -----------------------------------------------
+import sys
+import dbus
+import dbus.glib
+import dbus.decorators
+import gobject
+import os
+import re
+import time
+import sgmllib
+from tuxisalive.api import *
+#------------------------------------------------
+#------------------------------------------------
+
+# Uncomment or Comment for french language
+# Décommentez ou commentez pour le français
+
+# tg_langue = "French"
+
+# Uncomment or Comment for English language
+# Décommentez ou commentez pour l'anglais
+
+tg_langue = "English"
+
+# Debug
+
+DEBUG = False
+
+# True : for use chat, False : for don't use
+# True : pour utiliser les salons de discutions, False : ne pas utiliser
+
+CHAT = True
+# CHAT = False
+
+# True : for use Instant Messenger, False : for don't use
+# True : pour utiliser les Messageries Instantanées, False : ne pas utiliser
+
+IM = True
+# IM = False
+
+class MessageParser(sgmllib.SGMLParser):
+ """I found this snippets in this website :
+ http://quickies.seriot.ch/index.php"""
+ def __init__(self):
+ sgmllib.SGMLParser.__init__(self)
+
+ def strip(self, some_html):
+ self.theString = ""
+ self.feed(some_html)
+ self.close()
+ return self.theString
+
+ def handle_data(self, data):
+ self.theString += data
+
+def langue(l):
+ """ Select Language """
+ # u for unicode
+ if l == "French":
+ return [u"French", u"dit", u"est en ligne", "Julie",\
+ u"pidgin n'est pas lancé", u"Tux Pidgin est démarré"]
+ else:
+ return [u"English", u"says", u"is on line", "Heather",\
+ u"Pidgin is not launched", u"TuxPidgin is started"]
+
+
+def tuxConnect():
+ """ Wait connected """
+ tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'TuxPidgin', 'NONE')
+ tux.server.waitConnected(10.0)
+ tux.dongle.waitConnected(10.0)
+ tux.radio.waitConnected(10.0)
+
+def received_im_msg(account, name, message, conversation, flags):
+ """ This method is execute when a message is receive """
+ buddy = purple.PurpleFindBuddy(account, name)
+ if buddy != 0:
+ alias = purple.PurpleBuddyGetAlias(buddy)
+ else:
+ alias = name
+ #text = re.sub("<.*?>", "", text)#html2text
+ MessageP = MessageParser()
+ message = MessageP.strip(message)
+ text = "%s %s %s" % (alias, lang[1], message)
+ tux_speak(text)
+
+def buddy_signed_on(buddyid):
+ """ This method is excute when a buddy is sign on """
+ alias = purple.PurpleBuddyGetAlias(buddyid)
+ text = "%s %s" % (alias, lang[2])
+ tux_speak(text)
+
+
+def tux_speak(text):
+ """ Tux speak the text """
+ if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):
+ if DEBUG: print("tux connect")
+ text = text.encode('latin-1') # unicode to str
+ if DEBUG: print(text)
+ tux.mouth.open()
+ tux.tts.speak(text,lang[3],100)
+ tux.mouth.close()
+ tux.access.release()
+
+# Main
+tux = TuxAPI('127.1.1.1', 270)
+tuxConnect()
+lang = langue(tg_langue)
+if DEBUG: print lang
+bus = dbus.SessionBus()
+
+try:
+ obj = bus.get_object("im.pidgin.purple.PurpleService",
+ "/im/pidgin/purple/PurpleObject")
+ purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
+except dbus.DBusException:
+ tux_speak(lang[4])
+ sys.exit(1)
+
+if IM: bus.add_signal_receiver(received_im_msg,
+ dbus_interface = "im.pidgin.purple.PurpleInterface",
+ signal_name = "ReceivedImMsg")
+
+bus.add_signal_receiver(buddy_signed_on,
+ dbus_interface = "im.pidgin.purple.PurpleInterface",
+ signal_name = "BuddySignedOn")
+
+
+if CHAT: bus.add_signal_receiver(received_im_msg,
+ dbus_interface = "im.pidgin.purple.PurpleInterface",
+ signal_name = "ReceivedChatMsg")
+
+tux_speak(lang[5])
+loop = gobject.MainLoop()
+loop.run()
+tux.server.disconnect()
+tux.destroy()
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn