📜 ⬆️ ⬇️

Gnome forismatic notify applet

Good day!
Having started using python for my admin purposes, a la writing simple scripts, I couldn’t enjoy the simplicity of this language. Almost immediately, there was a desire to try to write a full-fledged application in python. But he could not think of what would create such that it was interesting and useful not only for me. The idea came after reading this topic on Habré, unfortunately it is not available now, but, briefly, we are talking about displaying quotes from forismatic.com when opening the console.
I decided that it would be nice to write an applet for gnome that will show the same quotes, but with the help of notifications. Then I wouldn’t have to open a new console to read the next quote. I liked the result and wanted to share it with the community.

Briefly about the program

The applet itself is a regular icon on the gnome panel.

When you click on the icon with the left mouse button, a quote appears in the form of a pop-up notification. But even if you do not click on the applet, then notifications with quotations will still appear every 30 minutes (by default).

All settings are summarized in a small menu.
Using the menu you can:

Pressing the middle mouse button on the applet icon will open the page with the latest quote on forismatic.com. The action is duplicated using the ShowQuote menu item .

Technical details

The applet is written in pygtk. All the additional modules that had to be used included the standard python set, so problems with dependencies should not be.
Quotes are collected using the API in the form of xml and after parsing are stored in the Gconf keys at /apps/panel/applets/applet_ id /pref/ . This allows you to run multiple copies of the applet with different settings. The Preferences window was created in the glade program.
This article was very helpful in creating the applet, with which the template for the applet was successfully linked.


So far I can single out only one global problem - the hang of the entire applet while receiving a regular quote from the site. As I understand it, after rereading a lot of thematic forums, this can only be solved using threading. Select one stream to draw graphics, and the second stream to work with the API.

The second item in the TODO sheet is to make an error reporting system. Currently, in debug mode, errors are displayed only in stdout. And in applet mode, error notifications are completely absent. If someone else likes the program, I will try to find time and refine it.

I cannot fail to complain about GTK itself and its strange handling of mouse clicks due to which a beautiful idea with the opening of the site failed with a double click. It is possible that it is correct that before generating the 2BUTTON_PRESS event, two BUTTON_PRESS events are generated , but because of this I did not think of a normal way to hang different actions on a single or double mouse click.
If someone from the Habr community tells you how to implement it, I will be very grateful.


There was an idea to create a deb package, but, unfortunately, after an evening spent reading the documentation, I did not understand how to do this in the case of python. Therefore, to install the applet, you can download the source from github.com or launchpad.net and manually copy the files into the necessary folders:
sudo cp -a ForismaticApplet /usr/share/
sudo cp forismatic_notify.server /usr/lib/bonobo/servers/

For greater certainty, I would recommend restarting gnome
After that, the Forismatic Applet appears in the PCM-> add to panel.


This is my first experience in programming GUI applications, so I hope that the criticism will be constructive and not very strict.
Naturally, I will try to take into account and correct all the found bugs.

UPD: Added the deb package (thanks to fenrirgray ), you can download it from the same github.com and launchpad.net . For example, a link from the last ForismaticNotify_Applet_0.7b-1_all.deb . But, nevertheless, it will be better to go to the repository and download there, to be sure that this is the latest version of the package.

Source: https://habr.com/ru/post/102076/

All Articles