Action callback does not get executed, unless I call other module.
Recently I was trying out notify2
package, but actions added with add_action
(i.e.
n.add_action('closed', 'Open', lambda x,y:webbrowser.open('https://www.example.com/'))
) did not get executed. However, when I later called playsound.playsound()
(from playsound
, another package), they got executed all at once (i.e. since I called n.show()
and clicked several times, my web browser opened like 10 tabs, all at www.example.com
).
I thought it was a problem with bus communication not being flushed. However, I still didn’t point out what’s the matter.
I have Ubuntu 20.04 LTS with Python 3.8.5, and I installed notify2 from pip.
Comments (4)
-
repo owner -
reporter Does it mean I and others have to switch programming language? 🧐
-
repo owner No, it definitely doesn’t mean that. GTK has Python wrappers - see the lazka.github.io link I posted above. I know less about KDE, but there’s bound to be some way to use it in Python. And if you’re not using either of those frameworks, you can use a Python D-Bus binding to send notifications directly with a bit more effort - e.g. here’s an example using my library ‘Jeepney’:
https://gitlab.com/takluyver/jeepney/-/blob/master/examples/blocking_notify.py
(That doesn’t show handling actions, which would unfortunately add a fair bit of complexity)
-
repo owner Oh, you may also want to look at the
desktop_notify
package, which is very similar to this one but has a release in 2020. - Log in to comment
This probably comes down to dbus-python, which notify2 uses to communicate with the notification server. It attempts to support the GTK & Qt event loops, but it’s kind of awkward, and it recommends using GTK & Qt’s own classes for D-Bus instead.
For GTK, see:
It doesn’t look like there’s an exact equivalent in Qt itself, though KDE frameworks have one:
I’m no longer working on or using pynotify2.