You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openbox/xdg-menu

27 lines
773 B

#!/usr/bin/env python
import gmenu, sys
from xml.sax.saxutils import escape
def walk_menu(entry):
if entry.get_type() == gmenu.TYPE_DIRECTORY:
print '<menu id="%s" label="%s">' \
% (escape(entry.menu_id), escape(entry.get_name()))
map(walk_menu, entry.get_contents())
print '</menu>'
elif entry.get_type() == gmenu.TYPE_ENTRY and not entry.is_excluded:
print """
<item label="%s">
<action name="Execute"><command>%s</command></action>
</item> """ % (escape(entry.get_name()), escape(entry.get_exec()))
if len(sys.argv) > 1:
menu = sys.argv[1] + '.menu'
else:
menu = 'applications.menu'
print '<?xml version="1.0" encoding="UTF-8"?>'
print '<openbox_pipe_menu>'
map(walk_menu, gmenu.lookup_tree(menu).root.get_contents())
print '</openbox_pipe_menu>'