我正在用QML开发一个屏幕截图应用程序,我希望使用统一7通知,类似于Rhythmbox在通知用户一首新歌已经启动或音量被更改时所使用的内容。
是否存在这样的API?一个小的编码示例将是有帮助的。
发布于 2014-10-27 08:42:56
据我所知,没有这样的API从QML组件调用libnotify。
为了避免仅仅为了获取桌面应用程序的通知而创建C++插件,我将使用吡咯苷调用一个小的python模块来完成以下工作:
安装pyotherside:sudo ap-get install pyotherside
首先,QML:
import QtQuick 2.0
import Ubuntu.Components 1.1
import io.thp.pyotherside 1.2
Rectangle {
width: 200
height: 200
Button {
text: "press"
anchors.centerIn: parent
onClicked: {
py.call('notify.pressme', [], function() {});
}
}
Python {
id: py
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('.'));
importModule('notify', function() {});
}
}
}和python代码(都放在同一个目录中),一个名为notify.py的文件:
#!/usr/bin/env python3
import subprocess
def pressme():
subprocess.call(["notify-send", "hello", "world"])按下QML Button之后,您将得到一个类似于此的通知:

请阅读通知-发送手册页以获得更多选项。
https://askubuntu.com/questions/540352
复制相似问题