~mzanetti/unity8/quicklist-unset-model-before-closing

« back to all changes in this revision

Viewing changes to tests/autopilot/unity8/shell/emulators/create_interactive_notification.py

  • Committer: Michael Zanetti
  • Date: 2013-08-27 06:59:04 UTC
  • mfrom: (235.1.20 trunk)
  • Revision ID: michael.zanetti@canonical.com-20130827065904-tdybcnq9cek07slp
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
4
#
 
5
# Unity Autopilot Test Suite
 
6
# Copyright (C) 2012-2013 Canonical
 
7
#
 
8
# This program is free software: you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation, either version 3 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# This program is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
 
 
22
import argparse
 
23
from gi.repository import GLib, Notify
 
24
import signal
 
25
 
 
26
 
 
27
def action_callback(notification, action_id, data):
 
28
    print action_id
 
29
 
 
30
 
 
31
def quit_callback(notification):
 
32
    loop.quit()
 
33
 
 
34
 
 
35
if __name__ == '__main__':
 
36
    parser = argparse.ArgumentParser(
 
37
        description='Create an interactive notification'
 
38
    )
 
39
 
 
40
    parser.add_argument(
 
41
        '--summary',
 
42
        help='summary text of the notification',
 
43
        default='Summary'
 
44
    )
 
45
    parser.add_argument(
 
46
        '--body',
 
47
        help='body text of the notification',
 
48
        default='Body'
 
49
    )
 
50
    parser.add_argument(
 
51
        '--icon',
 
52
        help='path to the icon to display',
 
53
        default=None
 
54
    )
 
55
    parser.add_argument(
 
56
        '--action',
 
57
        help='id and label for the callback in the format: id,label',
 
58
        action='append',
 
59
        default=[]
 
60
    )
 
61
    parser.add_argument(
 
62
        '--urgency',
 
63
        help='LOW, NORMAL, CRITICAL',
 
64
        choices=['LOW', 'NORMAL', 'CRITICAL'],
 
65
        default='NORMAL'
 
66
    )
 
67
    parser.add_argument(
 
68
        '--hints',
 
69
        help='list of comma sep options',
 
70
        action='append',
 
71
        default=[]
 
72
    )
 
73
 
 
74
    args = parser.parse_args()
 
75
 
 
76
    Notify.init('Interactive Notifications')
 
77
 
 
78
    notification = Notify.Notification.new(args.summary, args.body, args.icon)
 
79
 
 
80
    for hint in args.hints:
 
81
        key, value = hint.split(',', 1)
 
82
        notification.set_hint_string(key, value)
 
83
 
 
84
    for action in args.action:
 
85
        action_id, action_label = action.split(',', 1)
 
86
        notification.add_action(
 
87
            action_id,
 
88
            action_label,
 
89
            action_callback,
 
90
            None,
 
91
            None
 
92
        )
 
93
 
 
94
    def signal_handler(signam, frame):
 
95
        loop.quit()
 
96
 
 
97
    signal.signal(signal.SIGINT, signal_handler)
 
98
 
 
99
    loop = GLib.MainLoop.new(None, False)
 
100
    notification.connect('closed', quit_callback)
 
101
    notification.show()
 
102
    loop.run()