~ubuntu-branches/debian/sid/guake/sid

« back to all changes in this revision

Viewing changes to src/notifier.py

  • Committer: Package Import Robot
  • Author(s): Daniel Echeverry
  • Date: 2015-04-26 19:15:06 UTC
  • mfrom: (1.1.7)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: package-import@ubuntu.com-20150426191506-mo8037vk6pueer5b
Tags: upstream-0.7.0
ImportĀ upstreamĀ versionĀ 0.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Copyright (C) 2013 Maxim Ivanov <ulidtko@gmail.com>
3
 
 
4
 
This program is free software; you can redistribute it and/or
5
 
modify it under the terms of the GNU General Public License as
6
 
published by the Free Software Foundation; either version 2 of the
7
 
License, or (at your option) any later version.
8
 
 
9
 
This program is distributed in the hope that it will be useful,
10
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
General Public License for more details.
13
 
 
14
 
You should have received a copy of the GNU General Public
15
 
License along with this program; if not, write to the
16
 
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
Boston, MA 02111-1307, USA.
18
 
"""
19
 
 
20
 
import glib
21
 
import pynotify
22
 
 
23
 
pynotify.init("Guake")
24
 
 
25
 
__all__ = ['show_message']
26
 
 
27
 
RETRY_INTERVAL = 3  # seconds
28
 
 
29
 
retry_limit = 5  # tries
30
 
 
31
 
 
32
 
def show_message(brief, body=None, icon=None):
33
 
    try:
34
 
        notification = pynotify.Notification(brief, body, icon)
35
 
        notification.show()
36
 
    except glib.GError:
37
 
        print_warning()
38
 
        glib.timeout_add_seconds(RETRY_INTERVAL, lambda: retry(brief, body, icon))
39
 
 
40
 
 
41
 
def retry(*args):
42
 
    global retry_limit
43
 
 
44
 
    if retry_limit <= 0:
45
 
        return False
46
 
 
47
 
    retry_limit -= 1
48
 
    show_message(*args)
49
 
 
50
 
 
51
 
def print_warning():
52
 
    if not hasattr(print_warning, 'already_printed'):
53
 
        print """
54
 
Notification service is not running (yet). Guake can't display notifications!
55
 
  We'll retry a few times more a bit later, but you can use
56
 
  the following command to disable the startup notification:
57
 
$ gconftool-2 --type bool --set /apps/guake/general/use_popup false
58
 
        """.strip()
59
 
        print_warning.already_printed = True