notificaciones en el escritorio

6 04 2009

Distintas formas de mostrar una notificación en el escritorio:

usando python y pynotify

#import os
import sys
#os.environ['DISPLAY']=':0'
try:
import pynotify
except:
print "pynotify not installed"
else:
if pynotify.init("pyMessage"):
n = pynotify.Notification(sys.argv[1], sys.argv[2], "info")
n.set_urgency(pynotify.URGENCY_CRITICAL)
n.set_timeout(20000)
n.show()
else:
print "there was a problem initializing the pynotify module"

conectando python con dbus

import dbus
#import os
import sys
#os.environ['DISPLAY']=':0'
print "Inicializando el bus de tipo session"
bus = dbus.SessionBus()
print "Obteniendo el objeto Notifications"
notify_object = bus.get_object('org.freedesktop.Notifications','/org/freedesktop/Notifications')
print "Obteniendo una interface de tipo Notificatios del objecto"
notify_interface = dbus.Interface(notify_object,'org.freedesktop.Notifications')
print "Lanzando la notificacion"
noti_id = notify_interface.Notify("Messenger", 0, "info", sys.argv[1],sys.argv[2], '',{},20000)
print "Tenemos la notificacion con el ID: ",noti_id

notify-send con un script en bash

#!/bin/bash
#export DISPLAY=:0
/usr/bin/notify-send --urgency=critical --expire-time=20000 --icon=info $1 $2

El DISPLAY=:0 me permite enviar una notificación a esa pantalla desde un terminal remoto.

Advertisement

Acciones

Información

Deja un comentario

Please log in using one of these methods to post your comment:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s




Seguir

Get every new post delivered to your Inbox.