djthyrax Posted December 18, 2007 at 01:43 AM Report Share #154924 Posted December 18, 2007 at 01:43 AM 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. 😛 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: 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" You can set the urgency level to one of three values using the following: n.set_urgency(pynotify.URGENCY_LOW) n.set_urgency(pynotify.URGENCY_NORMAL) n.set_urgency(pynotify.URGENCY_CRITICAL) 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. n = pynotify.Notification("Title", "message", "icon-name") For the pixbuf method use: (where 'icon' is a pixbuf) n.set_icon_from_pixbuf(icon) To set the timeout value for the displayed message: n.set_timeout(seconds) To position the message (e.g. to associate it with a toolbar applet) n.attach_to_widget(widget) # 'self' often works # or position it explicitly # n.set_hint("x", x-coordinate) # n.set_hint("y", y-coordinate) You can close the notification before it has timed out using n.close() 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. 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! Link to comment Share on other sites More sharing options...
rolando2424 Posted December 18, 2007 at 04:47 PM Report Share #155021 Posted December 18, 2007 at 04:47 PM Não sei se devias ter colocado isto como Pyteam, afinal nem traduzistes nem nada 😛 Mas dá sempre jeito saber isto. Não me responsabilizo por qualquer dano ocorrido no seguimento dos meus conselhos. Prontos, a minha pessoa está oficialmente protegida legalmente 😄 Link to comment Share on other sites More sharing options...
djthyrax Posted December 18, 2007 at 05:28 PM Author Report Share #155023 Posted December 18, 2007 at 05:28 PM Não sei se devias ter colocado isto como Pyteam, afinal nem traduzistes nem nada 😛 A PyTeam não produz exclusivamente material, também divulga, como é o caso deste tópico. 😄 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! Link to comment Share on other sites More sharing options...
rolando2424 Posted December 18, 2007 at 06:02 PM Report Share #155027 Posted December 18, 2007 at 06:02 PM ... Está bem, safaste desta 😛 Não me responsabilizo por qualquer dano ocorrido no seguimento dos meus conselhos. Prontos, a minha pessoa está oficialmente protegida legalmente 😄 Link to comment Share on other sites More sharing options...
Kratos Posted January 19, 2008 at 11:43 AM Report Share #160850 Posted January 19, 2008 at 11:43 AM Pena que só existe para Linux "Vejo sempre além, pois me apóio em ombro de Gigantes" Link to comment Share on other sites More sharing options...
JoaoRodrigues Posted January 19, 2008 at 02:35 PM Report Share #160885 Posted January 19, 2008 at 02:35 PM Mais vale traduzires 😞 Link to comment Share on other sites More sharing options...
djthyrax Posted January 19, 2008 at 02:47 PM Author Report Share #160892 Posted January 19, 2008 at 02:47 PM Pena que só existe para Linux A libnotify é uma lib do X11, para Windows não conheço nada. Mais vale traduzires 😞 No time for it. :\ Se quiseres, força! 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! Link to comment Share on other sites More sharing options...
JoaoRodrigues Posted January 21, 2008 at 02:18 AM Report Share #161216 Posted January 21, 2008 at 02:18 AM Huuum... não prometo para perto... mas lá para Março deve estar 🙂 Link to comment Share on other sites More sharing options...
Tharis Posted January 22, 2008 at 05:43 PM Report Share #161526 Posted January 22, 2008 at 05:43 PM Eu posso traduzir, se for só este o texto, se for mais, não me candidato. Link to comment Share on other sites More sharing options...
djthyrax Posted January 22, 2008 at 06:39 PM Author Report Share #161542 Posted January 22, 2008 at 06:39 PM Isto não é candidatar, é vir e pumba. Além disso, é só isto sim. 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! Link to comment Share on other sites More sharing options...
Tharis Posted January 30, 2008 at 12:26 PM Report Share #163122 Posted January 30, 2008 at 12:26 PM Isto não é candidatar, é vir e pumba. Além disso, é só isto sim. Eu quando falei em candidatar era avançar e fazer. 🙂 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now