Last active
August 29, 2015 14:07
-
-
Save infirit/2fa0c59532d3a0c65dc2 to your computer and use it in GitHub Desktop.
Notify example for mate-notification-daemon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function, unicode_literals | |
| from gi.repository import Notify, GLib, Gdk | |
| screen = Gdk.Screen.get_default() | |
| monitor = screen.get_monitor_geometry(0) | |
| x_hint = GLib.Variant('i', monitor.width / 2) | |
| y_hint = GLib.Variant('i', monitor.height / 2) | |
| sound_hint = GLib.Variant('s', '/usr/share/sounds/freedesktop/stereo/dialog-information.oga') | |
| icon_name = "mate" | |
| summary = "Test" | |
| message =\ | |
| """\ | |
| <b>bold</b>, <i>italic</i>, <u>underline</u> | |
| and even <a href="http://mate-desktop.org">links</a> are supported! | |
| """ | |
| # Initialize the notification, argument is application name | |
| Notify.init("MATE") | |
| # Setup a loop so that callback/signals are send | |
| loop = GLib.MainLoop() | |
| # Callback function that handles the action responses | |
| def response_cb(notification, action_id, data): | |
| if action_id == "confirm": | |
| print("You pressed \"Confirm\"") | |
| if data: | |
| print("I also got data from you \o/") | |
| print("Data: %s" % data) | |
| if action_id == "deny": | |
| print("You pressed \"Deny\"") | |
| if data: | |
| print("I also got data from you \o/") | |
| print("Data: %s" % data) | |
| # Function to terminate mainloop when notification is closed | |
| def on_closed(notification, data): | |
| data.quit() | |
| # Create notification | |
| n = Notify.Notification.new(summary, message, icon_name) | |
| # Set some properties | |
| # Never expire | |
| n.set_timeout(3000) | |
| # OMG MFG this one is super uber urgent | |
| n.set_urgency(Notify.Urgency.CRITICAL) | |
| # Add some actions, args passed below in order are: | |
| # action id, label, callback function, data | |
| n.add_action("confirm", "Confirm", response_cb, "Confirmed: This is send as 3rd arg to callback") | |
| n.add_action("deny", "Deny", response_cb, "Denied: This is send as 3rd arg to callback") | |
| # Add some hints | |
| n.set_hint("x", x_hint) | |
| n.set_hint("y", y_hint) | |
| n.set_hint("sound-file", sound_hint) | |
| # Connect the closed signal | |
| n.connect("closed", on_closed, loop) | |
| # Show the notification | |
| n.show() | |
| # Run the mainloop to fire signals | |
| loop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment