Python notify2 module

Python notify2 Module

notify2 python module
In this article we will cover python notify2 module. Python notify2 module enable user to send notification to desktop at any position.

Let’s get started.

Installation of python notify2 module.
pip install notify2

Beagle:~ kumarshubham$ pip install notify2
Collecting notify2
Downloading notify2-0.3.1-py2.py3-none-any.whl
Installing collected packages: notify2
Successfully installed notify2-0.3.1

notify2.init(app_name, mainloop=None):
Initialise the D-Bus connection. Must be called before you send any notifications, or retrieve server info or capabilities.
To get callbacks from notifications, DBus must be integrated with a mainloop.

    There are three ways to achieve this:

  • Set a default mainloop (dbus.set_default_main_loop) before calling init()
  • Pass the mainloop parameter as a string ‘glib’ or ‘qt’ to integrate with those mainloops. (N.B. passing ‘qt’ currently makes that the default dbus mainloop, because that’s the only way it seems to work.)
  • Pass the mainloop parameter a DBus compatible mainloop instance, such as dbus.mainloop.glib.DBusGMainLoop().

If you only want to display notifications, without receiving information back from them, you can safely omit mainloop.

Creating and showing notification
Class notify2.Notification(summary, message=’any message’, icon=path)
Example:
>>> import notify2
>>> notify.init("test")
>>> n = notify2.Notification("hello", message="This is test")
>>> n.show()

you can also update the current notification
update(summary, message=”, icon=None)
Replace the summary and body of the notification, and optionally its icon. You should call show() again after this to display the updated notification.
close(). Ask the server to close this notification.

>>> n.update("New Update", message="Hello world")
>>> n.show()
>>> n.close()

Go though the other parameters and test

Extra parameters
class notify2.Notification
    set_urgency(level)
    Set the urgency level to one of URGENCY_LOW, URGENCY_NORMAL or     URGENCY_CRITICAL.

    set_timeout(timeout):
    Set the display duration in milliseconds, or one of the special values EXPIRES_DEFAULT or EXPIRES_NEVER. This is a request, which the server might ignore.
Only exists for compatibility with pynotify; you can simply set:
n.timeout = 5000


    set_category(category):
    Set the ‘category’ hint for this notification.
    See categories in the spec.

    set_location(x, y):
    Set the notification location as (x, y), if the server supports it.
     
    set_icon_from_pixbuf(icon):
    Set a custom icon from a GdkPixbuf.

    set_hint(key, value):
    n.set_hint(key, value) <–> n.hints[key] = value
    See hints in the spec.
    Only exists for compatibility with pynotify.

set_hint_byte(key, value):
Set a hint with a dbus byte value. The input value can be an integer or a bytes string of length 1.

Constants:
notify2.URGENCY_LOW
notify2.URGENCY_NORMAL
notify2.URGENCY_CRITICAL
Urgency levels to pass to Notification.set_urgency().

Note: Notify2 API documentation Notify2

Plz Share Share on FacebookShare on Google+Share on LinkedInTweet about this on TwitterEmail this to someoneShare on RedditShare on TumblrDigg thisBuffer this pagePrint this pagePin on PinterestShare on StumbleUponFlattr the author
Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *