I am (trying) to write a simple python script for ubuntu based OS. As part of script, a notification is also shown. Now, I have gone through a number of posts over here but with each one I have an accompanying question (and some problem). Following are different ways, I have already tried (and associated issue),
Using notify2
This has largely worked well. However, with following issue,
a. For some reason, icon isn't being shown in notification bubble and there is no error. A simple print statement,print(os.path.abspath('icon.svg')
, returning path, yields correct path but still no image.
Here's the exact code I am using,
def show_notification(title, content):
notify2.init(title)
n = notify2.Notification(title, content, os.path.abspath('icon.svg'))
n.show()
Using from gi.repository import Notify
Following the hello-unity file here. I tried to use Notify. I have not been able to get this running at all! The last time I tried, I got an error ImportError: cannot import name Notify
by running the script like python test.py
.
Running the same using python3 as in python3 test.py
results in a different error ImportError: cannot import name Notify, introspection typelib not found
.
To overcome this, I did try to install python-gobject
and libnotify-bin
but these are already installed on my system (Elementary OS Loki). The errors still persists.
Using subprocess
This has worked without any problem but I am not sure if this is the best way to show notification since I intend to show regular notifications. This is the code I used,
import subprocess as s
s.call(['notify-send','foo','bar'])
Core question
Since this is the first time I am trying to develop for linux community (or rather Ubuntu), I am fairly new to linux development. Trying to search for a simple (and correct) implementation such as that of notification has been rather time consuming and confusing. Apart from suggesting the right way of implementing notifications, I will appreciate if someone could point me in the right direction, something like android developer guide which shows or has api references.
And before anyone asks about my development preferences, I am more comfortable with python. Regarding GUI, again I am not sure which path to take although GTK seems to be more popular.