Python 中的跨平台桌面通知程序 [英] Cross-platform desktop notifier in Python

查看:34
本文介绍了Python 中的跨平台桌面通知程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Python 中寻找 Growl 之类的 Windows 气球提示式通知库.想象一下编写如下代码:

<预><代码>>>>将桌面通知程序导入为 dn>>>dn.notify('Title', '长描述在这里')

.. 并且会在 Mac、Windows 和 Linux 上通过相应的工具提示进行通知.有这样的图书馆吗?如果没有,我怎么自己写一个?

  • Mac 是否带有默认通知程序?Growl 是否应该单独安装?
  • 在 Windows 上,我认为这可能需要 pywin32?
  • 在 Linux 上,假设使用 GNOME,是否有 GNOME API(使用 gnome-python)可以执行此操作?
  • 我可以在所有平台上使通知具有粘性"(即永远不会淡出)吗?

更新:我倾向于依赖像 PyQT4 和 wxPython 这样的巨大 GUI 框架来完成这样的简单任务.

解决方案

这是我几年前使用 wxPython 编写的桌面通知程序 - 它在 Windows 和 Linux 上的行为相同,也应该在 OSX 上运行.它包含一个线程事件循环,可用于为包含可单击的图标和消息的通知窗口设置动画.它可能需要进行一些调整才能根据您自己的目的对其进行自定义,但基础工作已经完成.

I am looking for Growl-like, Windows balloon-tip-like notifications library in Python. Imagine writing code like:

>>> import desktopnotifier as dn
>>> dn.notify('Title', 'Long description goes here')

.. and that would notify with corresponding tooltips on Mac, Windows and Linux. Does such a library exist? If not, how would I go about writing one myself?

  • Does Mac come with a default notifier? Is Growl something that I should install separately?
  • On Windows, I assume this may require pywin32?
  • On Linux, assuming GNOME, is there a GNOME API (using gnome-python) that does this?
  • Can I make notifications 'sticky' (i.e., don't fade out ever) on all platforms?

Update: My preference is to not depend on gigantic GUI frameworks like PyQT4 and wxPython for a simple task such as this.

解决方案

Here's a desktop notifier I wrote a few years ago using wxPython - it behaves identically across Windows and Linux and should also run on OSX. It contains a threaded event loop that can be used to animate a notification window containing an icon and message that can be clicked on. It probably needs a couple of tweaks to customize it for your own purpose but the ground work is done.

这篇关于Python 中的跨平台桌面通知程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆