Python AppIndicator bindings -> howto check if the menu is open?

柔情痞子 提交于 2019-12-05 11:22:32

问题


Here is a minimal example of an 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()

Unfortunately the documentation on this is very incomplete. What I'm looking for is a way to check if the AppIndicator menu was opend by the user (e.g. the indicator icon was clicked). So is there a signal, that is emitted when the menu is opened?


回答1:


It looks like the answer is no unfortunately.

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')

I tried all of them and none of them appear to activate when the indicator is clicked. For what it's worth the unity devs seem to want to keep all indicators behaving in a uniform way, so it's quite possible that it's deliberately limited.




回答2:


There is a bug filed about it on Launchpad https://bugs.launchpad.net/screenlets/+bug/522152

Notice that "activate" signal is available for AppIndicator submenus.



来源:https://stackoverflow.com/questions/7063743/python-appindicator-bindings-howto-check-if-the-menu-is-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!