@ -2,9 +2,9 @@
# coding: utf-8
# coding: utf-8
# vim:et:sta:sts=4:sw=4:ts=8:tw=79:
# vim:et:sta:sts=4:sw=4:ts=8:tw=79:
import argparse
import os
import os
import sys
import sys
import getopt
import fnmatch
import fnmatch
import xdg.DesktopEntry as dentry
import xdg.DesktopEntry as dentry
import xdg.Exceptions as exc
import xdg.Exceptions as exc
@ -153,7 +153,7 @@ if not terminal_app:
terminal_app = 'xterm'
terminal_app = 'xterm'
def main(argv ):
def main():
global desktop
global desktop
global seticon
global seticon
global iconsize
global iconsize
@ -162,58 +162,61 @@ def main(argv):
global pekwmdynamic
global pekwmdynamic
global twmtitles
global twmtitles
global max_icon_size
global max_icon_size
try:
parser = argparse.ArgumentParser(usage='%(prog)s -f FORMAT [OPTIONS]',
opts, args = getopt.getopt(argv, "hins:f:", ["help", "icons",
formatter_class=argparse.RawDescriptionHelpFormatter,
"no-submenu",
epilog='''\
"pekwm-dynamic",
"twm-titles",
examples:
"max-icon-size",
xdgmenumaker -f windowmaker
"no-svg",
xdgmenumaker -i -f fluxbox
"size=",
''')
"format="])
parser.add_argument('-f', '--format', metavar='FORMAT', required=True,
except getopt.GetoptError:
choices=['amiwm', 'blackbox', 'compizboxmenu',
usage()
'fluxbox', 'fvwm', 'icewm', 'jwm', 'pekwm',
sys.exit(2)
'twm', 'windowmaker'],
for opt, arg in opts:
help='the output format to use. Valid options are '
if opt in ("-h", "--help"):
'%(choices)s')
usage()
parser.add_argument('-i', '--icons', action='store_true',
sys.exit(0)
help='enable support for icons in the menus. Does '
elif opt in ("-i", "--icons"):
'not work with windowmaker or amiwm')
seticon = True
parser.add_argument('--no-svg', action='store_false', dest='svg',
elif opt in ("-s", "--size"):
help='Do not use SVG icons even for WMs that support '
try:
'it')
iconsize = int(arg)
parser.add_argument('-s', '--size', type=int, default=16, dest='iconsize',
except ValueError:
help='preferred icon size in pixels (default: '
usage()
'%(default)s)')
sys.exit('ERROR: size must be a number')
parser.add_argument('-n', '--no-submenu', action='store_false',
elif opt in ("-n", "--no-submenu"):
dest='submenu',
submenu = False
help='do not create a submenu. Does not work with '
elif opt in ("--pekwm-dynamic",):
'windowmaker')
pekwmdynamic = True
parser.add_argument('--max-icon-size', action='store_true',
elif opt in ("--twm-titles",):
help='restrict the icon sizes to the specified size')
twmtitles = True
parser.add_argument('--pekwm-dynamic', action='store_true',
elif opt in ("--max-icon-size",):
help='generate dynamic menus for pekwm')
try:
parser.add_argument('--twm-titles', action='store_true',
# Pillow is optional and loaded only if we want to restrict the
help='show menu titles in twm menus')
# icon sizes (useful for Fvwm). Yeah, I know it's not a good
args = parser.parse_args()
# idea to load a module in here, but I really don't want to
desktop = args.format
# load it by default at the top. It would make xdgmenumaker a
seticon = args.icons
# bit slower to run even if it is not needed. This way it only
iconsize = args.iconsize
# slows down when it is actually needed.
nosvg = not args.svg
global Image
submenu = args.submenu
from PIL import Image
pekwmdynamic = args.pekwm_dynamic
max_icon_size = True
twmtitles = args.twm_titles
except ImportError:
if args.max_icon_size is True:
usage()
try:
sys.exit('ERROR: --max-icon-size requires Pillow')
# Pillow is optional and loaded only if we want to restrict the
elif opt == "--no-svg":
# icon sizes (useful for Fvwm). Yeah, I know it's not a good
nosvg = True
# idea to load a module in here, but I really don't want to
elif opt in ("-f", "--format"):
# load it by default at the top. It would make xdgmenumaker a
desktop = arg
# bit slower to run even if it is not needed. This way it only
if not desktop:
# slows down when it is actually needed.
usage()
global Image
sys.exit('ERROR: You must specify the output format with -f')
from PIL import Image
elif desktop == "blackbox":
max_icon_size = True
except ImportError:
parser.error('--max-icon-size requires Pillow')
if desktop == "blackbox":
blackbox()
blackbox()
elif desktop == "fluxbox":
elif desktop == "fluxbox":
fluxbox()
fluxbox()
@ -236,32 +239,7 @@ def main(argv):
seticon = False
seticon = False
amiwm()
amiwm()
else:
else:
usage()
parser.error('INTERNAL ERROR: unhandled format %s' % desktop)
sys.exit(2)
def usage():
print('USAGE:', os.path.basename(sys.argv[0]), '[OPTIONS]')
print()
print('OPTIONS:')
print(' -f, --format the output format to use.')
print(' Valid options are amiwm, blackbox, compizboxmenu,')
print(' fluxbox, fvwm, twm, icewm, jwm, windowmaker and pekwm')
print(' -i, --icons enable support for icons in the')
print(' menus. Does not work with windowmaker or amiwm')
print(' --no-svg Do not use SVG icons even for WMs that support it')
print(' -s, --size preferred icon size in pixels (default: 16)')
print(' -n, --no-submenu do not create a submenu. Does not work with')
print(' windowmaker')
print(' --max-icon-size restrict the icon sizes to the specified size')
print(' --pekwm-dynamic generate dynamic menus for pekwm')
print(' --twm-titles show menu titles in twm menus')
print(' -h, --help show this help message')
print(' You have to specify the output format using the -f switch.')
print()
print('EXAMPLES:')
print(' xdgmenumaker -f windowmaker')
print(' xdgmenumaker -i -f fluxbox')
def icon_strip(icon):
def icon_strip(icon):
@ -887,4 +865,4 @@ def amiwm():
if __name__ == "__main__":
if __name__ == "__main__":
main(sys.argv[1:] )
main()