Python AppIndicator绑定 -> 如何检查菜单是否已打开?

15

这是一个最小化的AppIndicator示例:

#!/usr/bin/python

import gobject
import gtk
import appindicator

if __name__ == "__main__":
    ind = appindicator.Indicator("example-simple-client", "gtk-execute", appindicator.CATEGORY_APPLICATION_STATUS)
    ind.set_status (appindicator.STATUS_ACTIVE)
    menu = gtk.Menu()
    menu_items = gtk.MenuItem('Quit')
    menu.append(menu_items)
    menu_items.connect("activate", gtk.main_quit)
    menu_items.show()
    ind.set_menu(menu)
    gtk.main()

不幸的是,这方面文档非常不完整。我正在寻找一种方法来检查用户是否打开了AppIndicator菜单(例如,单击了指示器图标)。因此,是否有信号在菜单打开时被发射?


可能文档已经很完整了,而且功能设计上本来就非常有限。如果你还没有尝试过,可以去 Freenode 并直接询问 Unity 的相关人员。 - dumbmatter
1
这并不是不完整,而是故意的。AppIndicator的主要动机是实现外观使用上的一致性统一性。如果人们开始为单击图标或右键单击图标创建随意操作,很快每个应用程序都会以自己的定制方式这样做,指示器将像系统托盘一样混乱无序。 - MestreLion
2个回答

8
很遗憾,看起来答案是否定的。
print gobject.signal_list_names(ind)
('new-icon', 'new-attention-icon', 'new-status', 'new-label', 'x-ayatana-new-label', 'connection-changed', 'new-icon-theme-path')

我已经尝试了所有的方法,但当点击指示器时,它们似乎都无法激活。就我所知,Unity开发人员似乎希望所有指示器的行为方式保持统一,因此这可能是故意限制的。


这也是文档所说的:http://developer.ubuntu.com/api/ubuntu-11.04/libappindicator/libappindicator-app-indicator.html#AppIndicator - skrat
当然,这是故意的。一旦允许应用程序为右键单击、双击、鼠标悬停等创建自定义操作,一致性和统一性就会被抛弃。这在Windows中是一种瘟疫,我很高兴在AppIndicator中不允许这样做。 - MestreLion

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接