#!/usr/bin/env python import sys import dbus import time DBUSMENU_IFACE = "com.canonical.dbusmenu" def die(error): sys.stderr.write("ERROR: %s\n" % error) sys.stderr.flush() sys.exit(-1) class MenuItem(object): def __init__(self, menu_id, label): self.menu_id = menu_id self.label = label def __str__(self): return "%d: %s" % (self.menu_id, self.label.encode("utf-8")) def get_children(iface, menu_id): revision, item = iface.GetLayout(menu_id, 1, []) lst = [] for child in item[2]: child_id = child[0] child_label = child[1].get("label", "") lst.append(MenuItem(child_id, child_label)) return lst def main(args): if len(args) != 2: die("Missing args") dest, path = args bus = dbus.SessionBus() proxy = bus.get_object(dest, path) iface = dbus.Interface(proxy, dbus_interface=DBUSMENU_IFACE) children = get_children(iface, 0) print "# menubar items" for child in children: print child first_menu = children[0] print print "# Calling AboutToShow" iface.AboutToShow(first_menu.menu_id) time.sleep(1) print print "# children of '%s'" % first_menu.label children = get_children(iface, first_menu.menu_id) for child in children: print child return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:])) # vi: ts=4 sw=4 et