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

« back to all changes in this revision

Viewing changes to src/guake/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
from __future__ import absolute_import
 
20
from __future__ import division
 
21
from __future__ import print_function
 
22
 
 
23
from textwrap import dedent
 
24
 
 
25
import glib
 
26
import pynotify
 
27
 
 
28
pynotify.init("Guake")
 
29
 
 
30
__all__ = ['show_message']
 
31
 
 
32
RETRY_INTERVAL = 3  # seconds
 
33
 
 
34
retry_limit = 5  # tries
 
35
 
 
36
 
 
37
def show_message(brief, body=None, icon=None):
 
38
    try:
 
39
        notification = pynotify.Notification(brief, body, icon)
 
40
        notification.show()
 
41
    except glib.GError:
 
42
        print_warning()
 
43
        glib.timeout_add_seconds(RETRY_INTERVAL, lambda: retry(brief, body, icon))
 
44
 
 
45
 
 
46
def retry(*args):
 
47
    global retry_limit
 
48
 
 
49
    if retry_limit <= 0:
 
50
        return False
 
51
 
 
52
    retry_limit -= 1
 
53
    show_message(*args)
 
54
 
 
55
 
 
56
def print_warning():
 
57
    if not hasattr(print_warning, 'already_printed'):
 
58
        print(dedent('''
 
59
            Notification service is not running (yet). Guake can't display notifications!
 
60
              We'll retry a few times more a bit later, but you can use
 
61
              the following command to disable the startup notification:
 
62
            $ gconftool-2 --type bool --set /apps/guake/general/use_popup false
 
63
        ''').strip())
 
64
        print_warning.already_printed = True