Coverage for /home/antoine/projects/xpra-git/dist/python3/lib64/python/xpra/notifications/pynotify_notifier.py : 19%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
2# This file is part of Xpra.
3# Copyright (C) 2011-2020 Antoine Martin <antoine@xpra.org>
4# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
5# later version. See the file COPYING for details.
7import sys
8import notify2 #@UnresolvedImport
10from xpra.notifications.notifier_base import NotifierBase
13class PyNotify_Notifier(NotifierBase):
15 def show_notify(self, dbus_id, tray, nid,
16 app_name, replaces_nid, app_icon,
17 summary, body, actions, hints, timeout, icon):
18 if not self.dbus_check(dbus_id):
19 return
20 icon_string = self.get_icon_string(nid, app_icon, icon)
21 notify2.init(app_name or "Xpra")
22 n = notify2.Notification(summary, body, icon_string)
23 n.set_urgency(notify2.URGENCY_LOW)
24 n.set_timeout(timeout)
25 if actions and False:
26 while len(actions)>=2:
27 action_id, action_label = actions[:2]
28 self.add_action(n, action_id, action_label)
29 actions = actions[2:]
30 n.show()
31 if icon_string:
32 def notification_closed(*_args):
33 self.clean_notification(nid)
34 n.connect("closed", notification_closed)
36 def add_action(self, n, action_id, action_label):
37 #n.add_action("foo", "Foo!", foo_action)
38 def callback(*_args):
39 pass
40 n.add_action(action_id, action_label, callback)
42 def close_notify(self, nid):
43 pass
46def main(args):
47 import gi
48 gi.require_version("Gtk", "3.0")
49 from gi.repository import GLib, Gtk
50 summary = "Summary"
51 body = "Body..."
52 if len(args)>1:
53 summary = args[1]
54 if len(args)>2:
55 body = args[2]
56 def show():
57 n = PyNotify_Notifier()
58 n.show_notify("", None, 0, "Test", 0, "", summary, body, ["0", "Hello", "1", "Bye"], {}, 0, "")
59 return False
60 GLib.idle_add(show)
61 GLib.timeout_add(20000, Gtk.main_quit)
62 Gtk.main()
65if __name__ == "__main__":
66 main(sys.argv)