Author: simplet
Date: 2008-11-29 15:46:46 +0100 (Sat, 29 Nov 2008)
New Revision: 2923

Added:
   software_suite_v2/software/scripts/ThunderBird_DBUS/readEmail.py
Modified:
   
software_suite_v2/software/scripts/ThunderBird_DBUS/AlerteEmailDbusThunderbird_2.py
Log:

* Added readEmail.py to overcome the Dbus lock.
* Cleaned the code a little.



Modified: 
software_suite_v2/software/scripts/ThunderBird_DBUS/AlerteEmailDbusThunderbird_2.py
===================================================================
--- 
software_suite_v2/software/scripts/ThunderBird_DBUS/AlerteEmailDbusThunderbird_2.py
 2008-11-29 14:21:49 UTC (rev 2922)
+++ 
software_suite_v2/software/scripts/ThunderBird_DBUS/AlerteEmailDbusThunderbird_2.py
 2008-11-29 14:46:46 UTC (rev 2923)
@@ -2,36 +2,30 @@
 # -*- coding: latin1 -*-
 
 """
+
 Author: Simplet <simplet _at_ ptigeek _dot_ net>
 
-Script tournant en tache de fond et monitorant les messages DBUS envoyés
-par l'extension DBUS de Thunderbird lors de réception d'emails.
+This script runs in the backgorund and monitor DBUS messages DBUS sent
+by the thunderbird extension "DBUS Thunderbird" when an new mail comes in.
 
 Thunderbid DBUS extension can be downloaded here :
 http://www.mumbles-project.org/wp-content/uploads/2007/08/thunderbird_dbus.xpi
 
+NOTE:
+To make TUX read the email, I use another little script (ReadEmail.py) because
+if I read it inside the DBUS loop, it disconnect the TUX (timeout).
 
+
 TODO
 =====
-- Ajouter une attitune ou un WAV avant le message
-- filtres possible (pour ne pas tout annoncer) sur le
-  folder source ou autre (sujet, emetteur, ...)
+- Add an attitune or WAV before reading the email
+- filters: source folder, subject containing, sender, ...
 
 
+History:
+========
+2008/11/29: first version (simplet).
 
- ------------------------
- /!\ BUG : help needed !
- ------------------------
- 
- First, if I only use the Dbus code and print result on the screen, it works 
flawlessly.
- 
- If I start using speak or led function, then it stop working after a few 
seconds since I started the script :
- the print work but not the TUX function (tts, led).
- 
- The problem come from the tux api but I don't know why.
-
- If you want to see by yourself, simply comment or uncomment Tux functions in 
"SayThat()".
-  
 """
 
 
@@ -42,49 +36,22 @@
 __license__ = 'GPL'
 
 
-
 import os
-import sys
-
-sys.path.append("/home/simplet/REMI/developpement/test/tuxisaliveAPI")
-from TuxAPI import TuxAPI
-from TuxAPIConst import *
-
 from sys import path
 import dbus, gobject, dbus.glib
-
 from dbus.mainloop.glib import DBusGMainLoop
 
 
-def SayThat(text):
-  tux.led.both.blinkAsync(4,25, LFX_FADE)
-  text = text.encode("latin1")
-  print text
-  tux.tts.speak(text, "Julie", 100)
-  tux.led.both.off()
-
-
 def OnEmail(subject, author):
-  SayThat("Vous avez recu un email de la part de : [" + author.split("<")[0] + 
"] et qui a pour objet : [" + subject + ".]")
+  os.system(os.getcwd()+"/readEmail.py \"" + author.split("<")[0] + "\" \"" + 
subject + "\"")
 
 
-tux = TuxAPI('192.168.1.5', 270)
-tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'ThunderbirdDBUS', 'NONE')
-tux.server.waitConnected(10.0)
-tux.dongle.waitConnected(10.0)
-tux.radio.waitConnected(10.0)
-if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):
+dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+bus = dbus.SessionBus()
 
-  dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
-  bus = dbus.SessionBus()
-
-  bus.add_signal_receiver(OnEmail,
+bus.add_signal_receiver(OnEmail,
                         dbus_interface="org.mozilla.thunderbird.DBus",
                         signal_name="NewMail")
 
-  loop = gobject.MainLoop()
-  loop.run()
-
-tux.access.release()
-tux.server.disconnect()
-tux.destroy()
+loop = gobject.MainLoop()
+loop.run()

Added: software_suite_v2/software/scripts/ThunderBird_DBUS/readEmail.py
===================================================================
--- software_suite_v2/software/scripts/ThunderBird_DBUS/readEmail.py            
                (rev 0)
+++ software_suite_v2/software/scripts/ThunderBird_DBUS/readEmail.py    
2008-11-29 14:46:46 UTC (rev 2923)
@@ -0,0 +1,55 @@
+#!/usr/bin/python
+# -*- coding: latin1 -*-
+
+"""
+
+ This script is called by the "Thunderbird DBUS Tux script".
+ 
+ Author: Simplet <simplet _at_ ptigeek _dot_ net>
+ 
+ 
+ 
+ BUG:
+ ====
+ 
+ - I have a problem when I receive email with é è in the subject.
+   Python throw an exception, saying it can't decode/encode :(
+ 
+"""
+
+__author__  = 'Simplet <simplet _at_ ptigeek _dot_ net>'
+__appname__ = 'Thunderbird DBUS script (readEmail part)'
+__version__ = '0.0.1'
+__date__    = '2008/11/29'
+__license__ = 'GPL'
+
+
+import os
+import sys
+
+sys.path.append("/home/simplet/REMI/developpement/test/tuxisaliveAPI")
+from TuxAPI import TuxAPI
+from TuxAPIConst import *
+
+
+
+def SayThat(text):
+  tux.led.both.blinkAsync(4,25, LFX_FADE)
+  text = unicode(text, sys.stdin.encoding)
+  text = text.encode("utf8")
+  tux.tts.speak(text, "Julie", 100)
+  tux.led.both.off()
+
+
+tux = TuxAPI('192.168.1.5', 270)
+tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'ThunderbirdDBUSemailRead', 
'NONE')
+tux.server.waitConnected(10.0)
+tux.dongle.waitConnected(10.0)
+tux.radio.waitConnected(10.0)
+if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):
+
+  SayThat("Vous avez recu un email de la part de : [" + sys.argv[1] + "] et 
qui a pour objet : [" + sys.argv[2] + ".]") 
+
+tux.access.release()
+tux.server.disconnect()
+tux.destroy()


Property changes on: 
software_suite_v2/software/scripts/ThunderBird_DBUS/readEmail.py
___________________________________________________________________
Name: svn:executable
   + *


-------------------------------------------------------------------------
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

Reply via email to