本文整理汇总了Python中PyQt5.QtDBus.QDBusConnection.registerObject方法的典型用法代码示例。如果您正苦于以下问题:Python QDBusConnection.registerObject方法的具体用法?Python QDBusConnection.registerObject怎么用?Python QDBusConnection.registerObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtDBus.QDBusConnection
的用法示例。
在下文中一共展示了QDBusConnection.registerObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Notifier
# 需要导入模块: from PyQt5.QtDBus import QDBusConnection [as 别名]
# 或者: from PyQt5.QtDBus.QDBusConnection import registerObject [as 别名]
class Notifier(QObject):
def __init__(self, *, taskModel, frontendSettings, parent):
super().__init__(parent)
self.__taskModel = taskModel
self.__frontendSettings = frontendSettings
self._conn = QDBusConnection("Xware Desktop").sessionBus()
self._interface = QDBusInterface(_DBUS_NOTIFY_SERVICE,
_DBUS_NOTIFY_PATH,
_DBUS_NOTIFY_INTERFACE,
self._conn)
self._notified = {} # a dict of notifyId: taskDict
self.__taskModel.taskCompleted.connect(self.notifyTaskCompleted, Qt.DirectConnection)
self._conn.registerObject(_DBUS_NOTIFY_PATH, self) # you must register it before connect
self._capabilities = self._getCapabilities()
if "actions" in self._capabilities:
successful = self._conn.connect(_DBUS_NOTIFY_SERVICE,
_DBUS_NOTIFY_PATH,
_DBUS_NOTIFY_INTERFACE,
"ActionInvoked", self.slotActionInvoked)
if not successful:
logging.error("ActionInvoked connect failed.")
self._qSound_complete = QSound(":/sound/download-complete.wav", self)
@property
def isConnected(self):
return self._conn.isConnected()
@pyqtSlot("QObject", result = "void")
def notifyTaskCompleted(self, taskItem):
if self.__frontendSettings.getbool("notifybysound"):
self._qSound_complete.play()
if not self.__frontendSettings.getbool("popnotifications"):
return
self._dbus_notifyCompleted(taskItem)
def _getCapabilities(self):
# get libnotify server caps and remember it.
qdBusMsg = self._interface.call(
"GetCapabilities"
)
if qdBusMsg.errorName():
logging.error("cannot get org.freedesktop.Notifications.GetCapabilities")
return []
else:
return qdBusMsg.arguments()[0]
def _dbus_notifyCompleted(self, task: "TaskItem"):
if "actions" in self._capabilities:
actions = QDBusArgument(["open", "打开", "viewOneFile", "在文件夹中显示"], QMetaType.QStringList)
else:
actions = QDBusArgument([], QMetaType.QStringList)
qdBusMsg = self._interface.call(
"Notify",
QDBusArgument("Xware Desktop", QMetaType.QString), # app_name
QDBusArgument(0, QMetaType.UInt), # replace_id
QDBusArgument("xware-desktop", QMetaType.QString), # app_icon
QDBusArgument("下载完成", QMetaType.QString), # summary
QDBusArgument(task.name, QMetaType.QString), # body
actions,
{
"category": "transfer.complete",
}, # hints
QDBusArgument(5000, QMetaType.Int), # timeout
)
if qdBusMsg.errorName():
logging.error("DBus, notifyTask {}: {}".format(qdBusMsg.errorName(),
qdBusMsg.errorMessage()))
else:
# add it to the dict
notificationId = qdBusMsg.arguments()[0]
self._notified[notificationId] = task.id
@pyqtSlot(QDBusMessage)
def slotActionInvoked(self, msg):
notifyId, action = msg.arguments()
taskId = self._notified.get(notifyId, None)
if not taskId:
# other applications' notifications
return
taskItem = self.__taskModel.adapterMap.get(taskId, None)
if not taskItem:
logging.debug("taskItem cannot be found anymore in TaskModel.")
return
fullpath = taskItem.fullpath # path + name
if action == "open":
return systemOpen(fullpath)
elif action == "viewOneFile":
return viewOneFile(fullpath)
elif action == "default": # Unity's notify osd always have a default action.
return
else:
#.........这里部分代码省略.........