web-dev-qa-db-fra.com

Les notifications système rapidement ne fonctionnent pas ("import pynotify" échoue)

Si je crée un projet rapide avec la commande suivante dans le terminal:

 quickly create ubuntu-application helloworld

puis ajoutez dans HelloworldWindow.py les lignes suivantes,

import sys
import pynotify

la ligne "import pynotify" produit la sortie d'erreur suivante sur mon système lorsque je souhaite exécuter l'application avec

quickly run

erreur-sortie:

/usr/lib/python2.7/dist-packages/gobject/constants.py:24: Avertissement: g_boxed_type_register_static: assertion g_type_from_name (name) == 0' failed import gobject._gobject /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: specified class size for typePyGtkGenericCellRenderer 'est plus petit que le GtkCellRenderer' class size from gtk import _gtk /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:40: Warning: g_type_get_qdata: assertion _node! Ng! importer _gtk

L'application ne démarre pas.

Mais si je veux lancer l'application python suivante

 #!/usr/bin/python
 import sys
 import pynotify

 if __== "__main__":
if not pynotify.init("icon-summary-body"):
    sys.exit(1)

n = pynotify.Notification(
    "Notification",
    "Hello notify! It works!",
    "notification-message-im")
n.show()

par exemple. en enregistrant le code dans un nom de fichier "notify.py", je peux exécuter le code avec la commande dans le terminal:

python notify.py

et la notification fonctionne bien!

Quel est le problème avec la via rapidement créée python applicaton ?? Pourquoi l'importation ne fonctionne pas? Je suis nouveau avec rapidement et python.

3
Marian Lux

Je viens de rencontrer exactement le même problème.

Voici ma solution.

from gi.repository import Notify

Notify.init ('Application')
notification = Notify.Notification.new ('Title', 'Message', 'dialog-information')
notification.show ()
7
RobinJ

pynotify a été écrit pour fonctionner avec pygtk, une manière plus ancienne d’utiliser GTK via Python. La nouvelle méthode s'appelle l'introspection de gobject et a des importations telles que:

from gi.repository import Gtk

Vous ne pouvez pas utiliser l'ancien et le nouveau système dans la même application, et le modèle Rapid utilise le nouveau système. Vous ne pouvez donc pas utiliser pynotify avec celui-ci.

J'ai un remplacement compatible avec le nouveau système: notify2 . Ce n'est pas encore précis, mais j'ai soumis une demande de backport pour cela.

2
Thomas K