Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-platform desktop notifier in Python

I am looking for Growl-like, Windows balloon-tip-like notifications library in Python. Imagine writing code like:

>>> import desktopnotifier as dn >>> dn.notify('Title', 'Long description goes here') 

.. and that would notify with corresponding tooltips on Mac, Windows and Linux. Does such a library exist? If not, how would I go about writing one myself?

  • Does Mac come with a default notifier? Is Growl something that I should install separately?
  • On Windows, I assume this may require pywin32?
  • On Linux, assuming GNOME, is there a GNOME API (using gnome-python) that does this?
  • Can I make notifications 'sticky' (i.e., don't fade out ever) on all platforms?

Update: My preference is to not depend on gigantic GUI frameworks like PyQT4 and wxPython for a simple task such as this.

like image 263
Sridhar Ratnakumar Avatar asked Feb 10 '10 22:02

Sridhar Ratnakumar


2 Answers

Here's a desktop notifier I wrote a few years ago using wxPython - it behaves identically across Windows and Linux and should also run on OSX. It contains a threaded event loop that can be used to animate a notification window containing an icon and message that can be clicked on. It probably needs a couple of tweaks to customize it for your own purpose but the ground work is done.

like image 59
Stephen McDonald Avatar answered Oct 05 '22 12:10

Stephen McDonald


At Pycon 2010 there was a presentation on cross-platform Python development. There was a html page about it as well, containing some advice for cross-platform notification. However, I don't find it online anymore, but I saved a local copy, and this is the part on notifications:

There are occasions in which your application wants to notify the user about something: software updates are available, a new instant message have been received, the 300 page print job has finally finished, etc.

  • To keep notifications easy to port cross-platform, don't make them interactive. For example Ubuntu does not support notifications that require user interaction.

  • These are the most important libraries:

    o Linux: pynotify.

    o Mac OS X: Growl, which is not standard, is usually installed.

    o Windows: a good wxPython solution is ToasterBox of Andrea Gavana, which mimics the look of Firefox or Thunderbird notifications.

  • For Phatch we developed a library that unifies these three systems in one API: phatch/lib/notify.py.

The linked python file is very interesting, and I think you should be able to use the linked python file almost as is. The code is also very clear, so you'll quickly see what it does.

The basic approach is it detects what notification systems are available, almost regardless of the platform, and tries to use them in a certain order but falls back to more simple systems if necessary. This way, if the user has e.g. Growl installed it'll use it, regardless of the platform.

You could adapt it to provide support for other notification systems than the three mentioned above.

like image 42
Rabarberski Avatar answered Oct 05 '22 14:10

Rabarberski