Olá, Visitante. Por favor Entre ou Registe-se se ainda não for membro.
Perdeu o seu e-mail de activação?
20 de Novembro de 2008, 21:30
231009 Mensagens em 23421 Tópicos por 7935 Membros
Membro Mais Recente: Ricardo25
Portugal-a-Programar  |  Desenvolvimento  |  Python  |  [PyTeam] Desktop Notifications using libnotify « anterior seguinte »
Páginas: [1]
Autor Tópico: [PyTeam] Desktop Notifications using libnotify  (Lida 1820 vezes)
djthyrax
SPAM::erase();
Moderador
Stack Overflow
*
Online Online

Mensagens: 11353



« em: 18 de Dezembro de 2007, 01:43 »

Vi este artigo sobre o uso da libnotify a partir do Python numa das minhas sessões de googling e achei que era mais que positivo postá-lo aqui. Smiley



Desktop Notifications is a system for consolidating an API, UI and mechanism to allow applications, applets, services, etc. to notify the user when something interesting happens.

The software for this is currently hosted under the Galago project, which is listed on freedesktop.org.

This software consists of a notification-daemon, a client API implemented by the libnotify library, the DBus system for tying things together, and finally various language bindings (so far only python and of course C)

The simplest way to add notifications to your app is to call the notify-send utility. But this is quite limited, and so not very interesting.

To use libnotify in a python application do the following:
Código
GeSHi (python):
try:
   import pynotify
   if pynotify.init("My Application Name"):
       n = pynotify.Notification("Title", "message")
       n.show()
   else:
       print "there was a problem initializing the pynotify module"
except:
   print "you don't seem to have pynotify installed"
Created by GeSHI 1.0.7.20
You can set the urgency level to one of three values using the following:
Código
GeSHi (python):
       n.set_urgency(pynotify.URGENCY_LOW)
       n.set_urgency(pynotify.URGENCY_NORMAL)
       n.set_urgency(pynotify.URGENCY_CRITICAL)
Created by GeSHI 1.0.7.20
One option to the Notification() call is to add an icon. This can use one of three methods:
1. a URI specifying the icon file name (e.g. file://path/to/my-icon.png)
2. a 'stock' icon name. One that would succeed in a call to gtk_icontheme_lookup() (e.g. 'stock-delete') Note: these are not necessarily normal GTK stock icons - any theme icon will work.
3. a pixbuf

For the first two methods, just specify the icon name or URI as the 3rd parameter to the Notification() call.
Código
GeSHi (python):
       n = pynotify.Notification("Title", "message", "icon-name")
Created by GeSHI 1.0.7.20
For the pixbuf method use: (where 'icon' is a pixbuf)
Código
GeSHi (python):
       n.set_icon_from_pixbuf(icon)
Created by GeSHI 1.0.7.20
To set the timeout value for the displayed message:
Código
GeSHi (python):
       n.set_timeout(seconds)
Created by GeSHI 1.0.7.20
To position the message (e.g. to associate it with a toolbar applet)
Código
GeSHi (python):
       n.attach_to_widget(widget) # 'self' often works
     # or position it explicitly
     #  n.set_hint("x", x-coordinate)
     #  n.set_hint("y", y-coordinate)
Created by GeSHI 1.0.7.20
You can close the notification before it has timed out using
Código
GeSHi (python):
       n.close()
Created by GeSHI 1.0.7.20
There's lots more you can do, such as putting buttons on the messages and getting callbacks when they are clicked, but that is beyond this tutorial. See the examples that come with the pynotify package to learn more.
Registado


Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
rolando2424
PyTeam
CRLF
*
Offline Offline

Mensagens: 629


RAMON - PORN ACTOR OF THE 60´s AND PYTHON PROGRAMM


WWW
« Responder #1 em: 18 de Dezembro de 2007, 16:47 »

Não sei se devias ter colocado isto como Pyteam, afinal nem traduzistes nem nada Tongue

Mas dá sempre jeito saber isto.
Registado

Não me responsabilizo por qualquer dano ocorrido no seguimento dos meus conselhos.
Prontos, a minha pessoa está oficialmente protegida legalmente Cheesy

Heckel is not a meme. (<---- Bem, este não durou muito, venha o próximo.)

You have been completely annihilated. Congratulations.
djthyrax
SPAM::erase();
Moderador
Stack Overflow
*
Online Online

Mensagens: 11353



« Responder #2 em: 18 de Dezembro de 2007, 17:28 »

Não sei se devias ter colocado isto como Pyteam, afinal nem traduzistes nem nada Tongue
A PyTeam não produz exclusivamente material, também divulga, como é o caso deste tópico. Smiley
Registado


Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
rolando2424
PyTeam
CRLF
*
Offline Offline

Mensagens: 629


RAMON - PORN ACTOR OF THE 60´s AND PYTHON PROGRAMM


WWW
« Responder #3 em: 18 de Dezembro de 2007, 18:02 »

...

Está bem, safaste desta Tongue
Registado

Não me responsabilizo por qualquer dano ocorrido no seguimento dos meus conselhos.
Prontos, a minha pessoa está oficialmente protegida legalmente Cheesy

Heckel is not a meme. (<---- Bem, este não durou muito, venha o próximo.)

You have been completely annihilated. Congratulations.
Kratos
PyTeam
void
*
Offline Offline

Mensagens: 87


sys.humanidade is corrupt, reboot universo? (Y/N)


WWW
« Responder #4 em: 19 de Janeiro de 2008, 11:43 »

Pena que só existe para Linux
Registado

"Vejo sempre além, pois me apóio em ombro de Gigantes"

JoaoRodrigues
Moderador
Unsigned User
*
Offline Offline

Mensagens: 1885


« Responder #5 em: 19 de Janeiro de 2008, 14:35 »

Mais vale traduzires Wink
Registado




Mas sem "axaxinar" o português tá? Wink
djthyrax
SPAM::erase();
Moderador
Stack Overflow
*
Online Online

Mensagens: 11353



« Responder #6 em: 19 de Janeiro de 2008, 14:47 »

Pena que só existe para Linux
A libnotify é uma lib do X11, para Windows não conheço nada.

Mais vale traduzires Wink
No time for it. :\ Se quiseres, força!
Registado


Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
JoaoRodrigues
Moderador
Unsigned User
*
Offline Offline

Mensagens: 1885


« Responder #7 em: 21 de Janeiro de 2008, 02:18 »

Huuum... não prometo para perto... mas lá para Março deve estar :d
Registado




Mas sem "axaxinar" o português tá? Wink
Tharis
Líder da PyTeam
Líder de Equipas
Unsigned User
*****
Online Online

Mensagens: 1422


I'M A GENIUS AND YOU SUCK!


« Responder #8 em: 22 de Janeiro de 2008, 17:43 »

Eu posso traduzir, se for só este o texto, se for mais, não me candidato.
Registado

Python Does the Job!

Why do People love hating and hate loving?
djthyrax
SPAM::erase();
Moderador
Stack Overflow
*
Online Online

Mensagens: 11353



« Responder #9 em: 22 de Janeiro de 2008, 18:39 »

Isto não é candidatar, é vir e pumba. Além disso, é só isto sim.
Registado


Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum!
Tharis
Líder da PyTeam
Líder de Equipas
Unsigned User
*****
Online Online

Mensagens: 1422


I'M A GENIUS AND YOU SUCK!


« Responder #10 em: 30 de Janeiro de 2008, 12:26 »

Isto não é candidatar, é vir e pumba. Além disso, é só isto sim.
Eu quando falei em candidatar era avançar e fazer. Tongue
Registado

Python Does the Job!

Why do People love hating and hate loving?
Páginas: [1]
Portugal-a-Programar  |  Desenvolvimento  |  Python  |  [PyTeam] Desktop Notifications using libnotify « anterior seguinte »
    Ir para: