Author: gwadavel
Date: 2009-04-01 23:09:42 +0200 (Wed, 01 Apr 2009)
New Revision: 4319

Added:
   software_suite_v2/software/scripts/pidgin/branches/api_0.3.0/
   software_suite_v2/software/scripts/pidgin/branches/api_0.3.0/tux_pidgin.py
Modified:
   software_suite_v2/software/scripts/pidgin/trunk/tux_pidgin.py
Log:
remove problem with variable message if alias = CIA - Add new branches 
tuxpidgin/api_0.3.0

Added: 
software_suite_v2/software/scripts/pidgin/branches/api_0.3.0/tux_pidgin.py
===================================================================
--- software_suite_v2/software/scripts/pidgin/branches/api_0.3.0/tux_pidgin.py  
                        (rev 0)
+++ software_suite_v2/software/scripts/pidgin/branches/api_0.3.0/tux_pidgin.py  
2009-04-01 21:09:42 UTC (rev 4319)
@@ -0,0 +1,237 @@
+#!/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/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.4"
+__date__    = "2008/12/19"
+__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 *
+#------------------------------------------------
+#------------------------------------------------
+
+
+# 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')
+       tux.server.waitConnected(10.0)
+       tux.dongle.waitConnected(10.0)
+       tux.radio.waitConnected(10.0)
+       
+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     
+    #text = re.sub("<.*?>", "", text)#html2text
+    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()
+        tux.tts.speak(text)
+        tux.mouth.close()
+        tux.access.release()
+
+# Main
+
+tux = TuxAPI(tgp_ip, tgp_port)
+tuxConnect()
+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()

Modified: software_suite_v2/software/scripts/pidgin/trunk/tux_pidgin.py
===================================================================
--- software_suite_v2/software/scripts/pidgin/trunk/tux_pidgin.py       
2009-04-01 15:54:00 UTC (rev 4318)
+++ software_suite_v2/software/scripts/pidgin/trunk/tux_pidgin.py       
2009-04-01 21:09:42 UTC (rev 4319)
@@ -170,8 +170,8 @@
     else:
         alias = name     
     #text = re.sub("<.*?>", "", text)#html2text
-    if tgp_cia and alias[:3] == "CIA":
-        message = LANGUAGE["commit"]
+    if tgp_cia and alias[:3].upper() == "CIA":
+        text = LANGUAGE["commit"]
     else:
         MessageP = MessageParser()
         message = MessageP.strip(message)


------------------------------------------------------------------------------
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to