消息菜单的动态快捷方式?

Dmi*_*nev 7 indicator python programming messaging-menu application-development

我是Unity Mail开发人员,我想知道是否可以从应用程序中添加到 Messaging Menu 的快捷方式(它是用 Python 编写的)。

我需要将它连接user-display到应用程序中的一个函数。例如,这是“全部标记为已读”命令所必需的。

规范仅说明了添加到 .desktop 文件的静态快捷方式:

.desktop文件本身中,应用程序可以指定无论程序是否正在运行都可以调用的快捷操作。这些操作的语法在ApplicationShortcuts 中定义。

Ted*_*uld 3

是的,尽管手工构建的绑定不会公开它,但您必须使用 GObject Introspected 绑定来执行此操作。不幸的是,还没有使用这些的教程。

为此,您需要获取 IndicateServer 并在其上调用 set_menu。它采用您想要提供的 Dbusmenu 作为参数。有很多方法可以做到这一点,但让我给你一些快速的伪代码(因为我不太熟悉 Python)。希望有编辑权限的人可以提供帮助。

menuserver = Dbusmenu.Server("/my/unique/path")
root = Dbusmenu.Menuitem()
menuserver.set_root(root)

first = Dbusmenu.Menuitem()
first.property_set("label", "First")
first.connect("item-activated", call_me_on_click)
root.child_append(first)

second = Dbusmenu.Menuitem()
second.property_set("label", "Second")
root.append_child(second)

indicateserver.set_menu(menuserver)
Run Code Online (Sandbox Code Playgroud)

还可以在菜单项上设置其他属性来执行您想要的任何操作。如果您使用 .GTK 菜单更舒服,您也可以从 GTK 菜单构建它们DbusmenuGtk.parse_menu_structure()。还有DbusMenu 的 API 文档