Author: Gwadavel
Date: 2009-04-17 13:49:52 +0200 (Fri, 17 Apr 2009)
New Revision: 4546
Added:
softwares_suite_v3/community/script/pidgin/trunk/tux_pidgin.py
Log:
move script from branche 0.3.0 software suite v2
Copied: softwares_suite_v3/community/script/pidgin/trunk/tux_pidgin.py (from
rev 4544,
software_suite_v2/software/scripts/pidgin/branches/api_0.3.0/tux_pidgin.py)
===================================================================
--- softwares_suite_v3/community/script/pidgin/trunk/tux_pidgin.py
(rev 0)
+++ softwares_suite_v3/community/script/pidgin/trunk/tux_pidgin.py
2009-04-17 11:49:52 UTC (rev 4546)
@@ -0,0 +1,252 @@
+#!/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
+=======
+2009/04/08 - version 0.5
+ - Add "cia" says "svn commit" if alias = CIA , channel #tuxdroid on irc
+ - Add test if server, dongle, radio are connected and for TTS
+2008/12/19 - version 0.4
+ - Add "away" speaks only if your statut are "away"
+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
+- Speaks only when your name is mentioned in chat
+"""
+
+__author__ = "Thomas CARPENTIER <[email protected]> & Julien Ruchaud \
+& Gwadavel"
+__appname__ = "TuxPidgin"
+__version__ = "0.5"
+__date__ = "2009/04/08"
+__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.TuxAPI import * # For api 0.3.0
+#------------------------------------------------
+#------------------------------------------------
+
+
+# True : for use chat, False : for don't use
+# True : pour utiliser les salons de discutions, False : ne pas utiliser
+
+tgp_chat = True
+# tgp_chat = False
+
+# True : for use Instant Messenger, False : for don't use
+# True : pour utiliser les Messageries Instantanées, False : ne pas utiliser
+
+tgp_im = True
+# tgp_im = False
+
+# True : speak only if your status is "away"
+# True : ne parle que si votre status est "absent"
+
+# tgp_away = True
+tgp_away = False
+
+# Don't say svn commit, CIA alias
+tgp_cia = True
+#tgp_cia = False
+
+# Address and port of Tux HTTP server
+
+tgp_ip = "127.0.0.1"
+tgp_port = 270
+
+
+LANGUAGE = ""
+
+FR = {"say": "dit", "online": "est en ligne", "pidginoff": "pidgin n'est pas
lancé", "pidginon": "Tux pidgin est démarré", "commit": "commit sur le s v n"}
+EN = {"say": "says", "online": "is on line", "pidginoff": "Pidgin is not
launched", "pidginon": "TuxPidgin is started", "commit":"s v n commit"}
+
+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 lang():
+ """ Search LANGUAGE in os.environ """
+
+ global LANGUAGE
+
+ if "fr_" in os.environ['LANG']:
+ locutor = "Bruno"
+ pitch = 100
+ LANGUAGE = FR
+ elif ("en_" in os.environ['LANG']) or ("us_" in os.environ['LANG']):
+ locutor = "Ryan"
+ pitch = 100
+ LANGUAGE = EN
+ else: # for other language
+ locutor = "Ryan"
+ pitch = 100
+ LANGUAGE = EN
+ tux.tts.setLocutor(locutor)
+ tux.tts.setPitch(pitch)
+
+
+def tuxConnect():
+ """ Wait connected """
+ tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'TuxPidgin', 'NONE')
+ if tux.server.waitConnected(10.0):
+ if tux.dongle.waitConnected(10.0):
+ if tux.radio.waitConnected(10.0):
+ return True
+ else:
+ print "radio not connected"
+ return False
+ else:
+ print "radio not connected"
+ return False
+ else:
+ print "server not connected"
+ return False
+
+def away():
+ """ Test status away ou available """
+
+ # i found this here http://arstechnica.com/reviews/apps/pidgin-2-0.ars/4
+ # Iterate through every active account
+
+ for acctID in purple.PurpleAccountsGetAllActive():
+
+ # Retrieve the current status
+ status = purple.PurpleSavedstatusGetCurrent()
+ type = purple.PurpleSavedstatusGetType(status)
+ if type == 5: # 5 = away 2 = available
+ return True
+ else:
+ return False
+
+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
+ if tgp_cia and alias[:3].upper() == "CIA":
+ text = LANGUAGE["commit"]
+ else:
+ MessageP = MessageParser()
+ message = MessageP.strip(message)
+ text = "%s %s %s" % (alias, LANGUAGE["say"], message)
+ text = text.encode('utf-8')
+ 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, LANGUAGE["online"])
+ text = text.encode('utf-8')
+ tux_speak(text)
+
+
+def tux_speak(text):
+ """ Tux speak the text """
+
+ if tgp_away and (not away()):
+ return
+ if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):
+ tux.mouth.open()
+ if not tux.tts.speak(text):
+ print "TTS error"
+ tux.mouth.close()
+ tux.access.release()
+
+# Main
+
+tux = TuxAPI(tgp_ip, tgp_port)
+if not tuxConnect():
+ sys.exit(1)
+tux.tts.setEncoding("utf-8")
+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(LANGUAGE["pidginoff"])
+ sys.exit(1)
+
+if tgp_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 tgp_chat: bus.add_signal_receiver(received_im_msg,
+ dbus_interface = "im.pidgin.purple.PurpleInterface",
+ signal_name = "ReceivedChatMsg")
+
+tux_speak(LANGUAGE["pidginon"])
+
+loop = gobject.MainLoop()
+loop.run()
+
+tux.server.disconnect()
+tux.destroy()
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn