notification.py

Aller à la documentation de ce fichier.
00001 #!/usr/bin/python
00002 # -*- coding: utf-8 -*-
00003 #       $Id: notification.py 29 2010-12-11 15:39:59Z georgesk $ 
00004 
00005 licence={}
00006 licence['en']="""
00007     file notification.py
00008     this file is part of the project scolasync
00009     
00010     Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
00011 
00012     This program is free software: you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation, either version3 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00024 """
00025 
00026 import dbus
00027  
00028 
00029 ##
00030 # 
00031 #     Une classe pour afficher des notifications à l'écran. Doit
00032 #     fonctionner avec tous les gestionnaires de bureau qui adhèrent aux
00033 #     standards de freedesktop.org.
00034 #     Cette classe est basée sur la documentation disponible à
00035 #     http://www.galago-project.org/specs/notification/0.9/x408.html
00036 #     
00037 class Notification:
00038  
00039     ##
00040     # 
00041     #             Le constructeur
00042     #             @param app_name nom d'une application, valeur par défaut =""
00043     #             @param replaces_id identifiant d'une notification à remplacer valeur par défaut=0
00044     #             @param app_icon nom d'un fichier servant pour l'icône valeur par défaut=""
00045     #             @param summary description brève de la notification valeur par défaut =""
00046     #             @param body le texte de la notification, valeur pa défaut=""
00047     #             @param actions une liste de paires représeantant des actions, valeur par défaut=[]
00048     #             @param hints un dictionnaire de suggestions, valeur par défaut={},
00049     #             @param expire_timeout durée maximale d'affichage en millisecondes, valeur par défaut=1000
00050     #             
00051     def __init__(self, app_name ="", replaces_id=0, app_icon="",
00052                      summary="", body="", actions=[], hints={},
00053                      expire_timeout=1000):
00054             self.app_name = app_name
00055             self.replaces_id = replaces_id
00056             self.app_icon = app_icon
00057             self.summary = summary
00058             self.body = body
00059             self.actions = actions
00060             self.hints = hints
00061             self.expire_timeout = expire_timeout
00062             
00063             try:
00064                 session_bus = dbus.SessionBus()
00065                 obj = session_bus.get_object("org.freedesktop.Notifications","/org/freedesktop/Notifications")
00066                 self.interface = dbus.Interface(obj, "org.freedesktop.Notifications")
00067             except Exception:
00068                 self.interface = None
00069  
00070     def notify(self):
00071         self.interface.Notify(self.app_name, self.replaces_id, self.app_icon, self.summary, self.body, self.actions, self.hints, self.expire_timeout)
00072             
00073             
00074 if __name__=="__main__":
00075     notif = Notification(app_name="AppliTest",
00076                          summary="Notification de test",
00077                          body="Voici le corps de la notification",
00078                          app_icon="/usr/share/pixmaps/vlc.png",
00079                          expire_timeout=7000)
00080     notif.notify()
00081