How to customise your DeMuDi menu
DeMuDi creates a top-level Sound menu using a Python script, /etc/menu/sound. Copying this script into ~/.menu/ makes sure that it is read when you call update-menus as an ordinary user.
$ cp /etc/menu/sound ~/.menu/sound-menu.py $ chmod 755 ~/.menu/sound-menu.py
I modified the script so that ~/.menu gets searched for menu entries when update-menus is called as user. So it now reads like this:
$ cat ~/.menu/sound-menu.py
#!/usr/bin/python
import sys
import os
import re
import string
# Removed commented out section here
entries = ((file( '/usr/share/demudi/menu/entries', 'r')).read()).split('\n')
entries.pop()
prefix = 'section'
for entry in entries:
pattern = re.compile("^([^:]*):[ \t]*(.*)$")
match = pattern.match(entry)
if match:
package = match.group(1)
path = match.group(2)
title = "Sound"
for section in string.split(path,"/"):
section.capitalize()
title = title + "/" + section.capitalize()
# Try to find menu entry in ~/.menu/ first
try:
menu = ((file( '~/.menu/%s' % (package), 'r')).read())
menu = string.replace(menu, "\n", " ")
menu = string.replace(menu, " ?package", "\n?package")
menu = string.replace(menu, "\\", " ")
menu = re.sub('section=(\"[^"]*\"|[^ \\$]*)', 'section="%s"' % (title), menu)
if (string.find(menu, "icon=") == -1):
try:
icon='/usr/share/pixmaps/%s.xpm' % (package)
file(icon)
menu += ' icon="%s"' % (icon)
except IOError:
try:
icon='/usr/share/pixmaps/demudi_%s.xpm' % string.replace(string.replace(path, "/", "_"), "section", "demudi")
file(icon)
menu += ' icon="%s"' % (icon)
except IOError:
foo = 'foo'
print '%s' % (menu)
except IOError:
# Otherwise look for entry in /usr/share/menu/
# /usr/lib/menu/ is deprecated, best not to use it
try:
menu = ((file( '/usr/share/menu/%s' % (package), 'r')).read())
menu = string.replace(menu, "\n", " ")
menu = string.replace(menu, " ?package", "\n?package")
menu = string.replace(menu, "\\", " ")
menu = re.sub('section=(\"[^"]*\"|[^ \\$]*)', 'section="%s"' % (title), menu)
if (string.find(menu, "icon=") == -1):
try:
icon='/usr/share/pixmaps/%s.xpm' % (package)
file(icon)
menu += ' icon="%s"' % (icon)
except IOError:
try:
icon='/usr/share/pixmaps/demudi_%s.xpm' % string.replace(string.replace(path, "/", "_"), "section", "demudi")
file(icon)
menu += ' icon="%s"' % (icon)
except IOError:
foo = 'foo'
print '%s' % (menu)
except IOError:
continue
It will probably work fine to copy and paste this if it doesn't make sense to you. You can now add menu entries for applications that lack them like this:
$ cat ~/.menu/bristol
?package(bristol):\ needs="x11"\ section="Apps/Sound"\ title="bristol"\ command="/usr/bin/startBristol -alsa"\ hints="Synthesis,Softsynth"
The rules for constructing menu entries are laid out in the Debian Menu System manual. Next, we need to add Bristol to the secret list that DeMuDi uses to populate the Sound menu by adding a line like this:
bristol: synthesis
to /usr/share/demudi/menu/entries - it's just a plain text file. Be warned that this file will get overwritten when the demudi package is upgraded. Any better ideas, post them here.
Once you've done that, all you have to do is perform
$ update-menus
Note, all of this is performed as a normal user. This should work on most standards compliant window managers, although some may require restarting before the changes take effect. It's often easier just to log out and back in again at this point.
Using this method it is possible to make menu entries for all sorts of different applications, home grown scripts and custom commands.

