ScolaSync  1.0
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
notification.py
Aller à la documentation de ce fichier.
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # $Id: notification.py 29 2010-12-11 15:39:59Z georgesk $
4 
5 licence={}
6 licence['en']="""
7  file notification.py
8  this file is part of the project scolasync
9 
10  Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
11 
12  This program is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version3 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program. If not, see <http://www.gnu.org/licenses/>.
24 """
25 
26 import dbus
27 
28 
29 ##
30 #
31 # Une classe pour afficher des notifications à l'écran. Doit
32 # fonctionner avec tous les gestionnaires de bureau qui adhèrent aux
33 # standards de freedesktop.org.
34 # Cette classe est basée sur la documentation disponible à
35 # http://www.galago-project.org/specs/notification/0.9/x408.html
36 #
38 
39  ##
40  #
41  # Le constructeur
42  # @param app_name nom d'une application, valeur par défaut =""
43  # @param replaces_id identifiant d'une notification à remplacer valeur par défaut=0
44  # @param app_icon nom d'un fichier servant pour l'icône valeur par défaut=""
45  # @param summary description brève de la notification valeur par défaut =""
46  # @param body le texte de la notification, valeur pa défaut=""
47  # @param actions une liste de paires représeantant des actions, valeur par défaut=[]
48  # @param hints un dictionnaire de suggestions, valeur par défaut={},
49  # @param expire_timeout durée maximale d'affichage en millisecondes, valeur par défaut=1000
50  #
51  def __init__(self, app_name ="", replaces_id=0, app_icon="",
52  summary="", body="", actions=[], hints={},
53  expire_timeout=1000):
54  self.app_name = app_name
55  self.replaces_id = replaces_id
56  self.app_icon = app_icon
57  self.summary = summary
58  self.body = body
59  self.actions = actions
60  self.hints = hints
61  self.expire_timeout = expire_timeout
62 
63  try:
64  session_bus = dbus.SessionBus()
65  obj = session_bus.get_object("org.freedesktop.Notifications","/org/freedesktop/Notifications")
66  self.interface = dbus.Interface(obj, "org.freedesktop.Notifications")
67  except Exception:
68  self.interface = None
69 
70  def notify(self):
71  self.interface.Notify(self.app_name, self.replaces_id, self.app_icon, self.summary, self.body, self.actions, self.hints, self.expire_timeout)
72 
73 
74 if __name__=="__main__":
75  notif = Notification(app_name="AppliTest",
76  summary="Notification de test",
77  body="Voici le corps de la notification",
78  app_icon="/usr/share/pixmaps/vlc.png",
79  expire_timeout=7000)
80  notif.notify()
81