Posts: 51
swiftlinuxcreator
Joined: 15 Nov 2010
#1
I'm trying to improve this script for Swift Linux, and I think antiX Linux could use the improvements I plan to make. (I want to make the menu look and feel more like that of Puppy Linux.)

Somehow, the script pulls up the various categories of programs in the OS (System, Office, Multimedia, etc.). But I can't for the life of me figure out how it's doing so. The old script went through all of the *.desktop files in the /usr/share/applications directory. For the life of me, I can't figure out what the new script is doing. My questions:
1. Exactly where is the list of various categories of programs?
2. Exactly how is this list accessed or created?
3. Exactly where is the list of programs to be included in the menu?
4. Exactly how is this list accessed or created?

Two of the critical steps in the process are:
menu = xdg.Menu.parse()
process_menu(menu)

def parse(filename=None):
# conver to absolute path
if filename and not os.path.isabs(filename):
filename = __getFileName(filename)

# use default if no filename given
if not filename:
candidate = os.environ.get('XDG_MENU_PREFIX', '') +
"applications.menu"
filename = __getFileName(candidate)

if not filename:
raise ParsingError('File not found',"/etc/xdg/menus/%s" %
candidate)

# check if it is a .menu file
if not os.path.splitext(filename)[1] ==".menu":
raise ParsingError('Not a .menu file', filename)

# create xml parser
try:
doc = xml.dom.minidom.parse(filename)
except xml.parsers.expat.ExpatError:
raise ParsingError('Not a valid .menu file', filename)

# parse menufile
tmp["Root"] =""
tmp["mergeFiles"] = []
tmp["DirectoryDirs"] = []
tmp["cache"] = MenuEntryCache()

__parse(doc, filename, tmp["Root"])
__parsemove(tmp["Root"])
__postparse(tmp["Root"])

tmp["Root"].Doc = doc
tmp["Root"].Filename = filename

# generate the menu
__genmenuNotOnlyAllocated(tmp["Root"])
__genmenuOnlyAllocated(tmp["Root"])

# and finally sort
sort(tmp["Root"])

return tmp["Root"]

The process_menu function is:
def process_menu(menu):
for entry in menu.getEntries():
if isinstance(entry, xdg.Menu.Menu):
name = entry.getName() or entry.DesktopFileID
icon = find_icon(entry) or default_folder_icon

if entire_menu:
print ("menu \"%s\" \"%s\" {" % (name, icon)).encode(encoding)
process_menu(entry)
print"}".encode(encoding)
else:
print (("menuprog \"%s\" \"%s\" %s" % (name, icon,
sys.argv[0])) +
(" --root-folder \"%s\"" % entry.getPath(org=True)) +
(" --terminal \"%s\"" % terminal) +
(" --default-folder-icon \"%s\"" % default_folder_icon) +
(" --default-entry-icon \"%s\"" % default_entry_icon) +
(" --theme \"%s\"" % xdg.Config.icon_theme) +
(" --icon-size \"%d\"" % icon_size) +
(with_theme_paths and" --with-theme-paths" or
"")).encode(encoding),
if locale_str:
print (" --locale \"%s\"" % locale_str).encode(encoding),
print
elif isinstance(entry, xdg.Menu.MenuEntry):
de = entry.DesktopEntry
name = de.getName() or entry.DesktopFileID
icon = find_icon(de) or default_entry_icon
execute = exec_clean2_re.sub('%', exec_clean1_re.sub('',
de.getExec()))
if de.getTerminal(): execute = terminal % execute
print ("prog \"%s\" \"%s\" %s" % (name, icon,
execute)).encode(encoding)
Posts: 1,081
OU812
Joined: 29 Sep 2007
#2
Hello. I believe it uses /etc/xdg/menus/lxde-applications.menu. The actual script that uses lxde-applications.menu has a pointer /etc/xdg/menus/applications.menu that points to the lxde menu. Also look for /usr/local/bin/auto-fluxbox-menu which is the script that does the work and references the data in lxde-applications.menu.

This way of doing things is better than the old script as it can find apps installed on your system - even if they don't have .desktop files. Good luck.

john
Posts: 1,228
secipolla
Joined: 15 Jun 2008
#3
As OU812 said, it uses the LXDE menu (package lxmenu-data), which generates the menu listing from desktop files.
It needs the desktop files for that (as any freedesktop compatible menu generator), but it's more complete than the older script as it includes all the proper locations (/usr/share/applications, /usr/local/share/applications and ~/.local/share/applications) and the entries are localized.

So I'm not a programmer but I can tell you that the desktop file parsing is done by lxmenu-data, which generates the menu file /etc/xdg/menus/lxde-applications.menu. It's symlinked to /etc/xdg/menus/applications.menu which is read by icewm-xdg-menu to create ~/.icewm/menu.
icewm-xdg-menu is an IceWM menu generator that has some options like setting the icon theme to be used and the default terminal emulator (and anticapitalista tweaked it to create a Fluxbox menu generator too).

So if you intend on tweaking the categories, for instance, you should look into lxmenu-data and the freedesktop.org menu specs.