Gtk notifications don't display body holding '<'

550 views Asked by At

I'm trying to display notifications with the Notification module of pygobject (version 3.16) in python. My code works well, except when there is a < in the body message. In this case, the body is not displayed.

For example with this code, all is OK:

from gi.repository import Gtk, Notify

def callback(notification, action_name):
    notification.close()
    Gtk.main_quit()

Notify.init('test')
notification = Notify.Notification.new('Title', 'body')
notification.set_timeout(Notify.EXPIRES_NEVER)
notification.add_action('quit', 'Quit', callback)
notification.show()

Gtk.main()

But with this one there is a problem:

from gi.repository import Gtk, Notify

def callback(notification, action_name):
    notification.close()
    Gtk.main_quit()

Notify.init('test')
notification = Notify.Notification.new('Title', '<body')
notification.set_timeout(Notify.EXPIRES_NEVER)
notification.add_action('quit', 'Quit', callback)
notification.show()

Gtk.main()

I get that: Notification where the body is not displayed

When the < is in the title, or when I use a > there is no problem.

I tried to escape the <, but it didn't do anything. So, how could I display a body text containing a < ?

1

There are 1 answers

0
AudioBubble On BEST ANSWER

I've noticed that in Gtk there is sometimes html code, like when using set_markup.I tried with the hmtl equivalent &lt; and it worked fine:

from gi.repository import Gtk, Notify

def callback(notification, action_name):
    notification.close()
    Gtk.main_quit()

Notify.init('test')
notification = Notify.Notification.new('Title', '&lt;body&gt;')
notification.set_timeout(Notify.EXPIRES_NEVER)
notification.add_action('quit', 'Quit', callback)
notification.show()