Browse Source

Add --size command line option

Add a --size (or -s) command line option that sets the preferred icon
size.
pull/4/head
George Vlahavas 11 years ago
parent
commit
fd6123eca6
  1. 16
      src/xdgmenumaker

16
src/xdgmenumaker

@ -11,6 +11,7 @@ import ConfigParser
from operator import attrgetter from operator import attrgetter
seticon = False seticon = False
iconsize = 16
desktop = False desktop = False
submenu = True submenu = True
pekwmdynamic = False pekwmdynamic = False
@ -70,11 +71,12 @@ except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e:
def main(argv): def main(argv):
global desktop global desktop
global seticon global seticon
global iconsize
global submenu global submenu
global pekwmdynamic global pekwmdynamic
try: try:
opts, args = getopt.getopt(argv, "hinf:", ["help", "icons" , opts, args = getopt.getopt(argv, "hins:f:", ["help", "icons" ,
"no-submenu", "pekwm-dynamic", "format="]) "no-submenu", "pekwm-dynamic", "size=", "format="])
except getopt.GetoptError: except getopt.GetoptError:
usage() usage()
sys.exit(2) sys.exit(2)
@ -84,6 +86,12 @@ def main(argv):
sys.exit(0) sys.exit(0)
elif opt in ("-i", "--icons"): elif opt in ("-i", "--icons"):
seticon = True seticon = True
elif opt in ("-s", "--size"):
try:
iconsize = int(arg)
except ValueError:
usage()
sys.exit('ERROR: size must be a number')
elif opt in ("-n", "--no-submenu"): elif opt in ("-n", "--no-submenu"):
submenu = False submenu = False
elif opt in ("--pekwm-dynamic",): elif opt in ("--pekwm-dynamic",):
@ -114,6 +122,7 @@ def usage():
print 'OPTIONS:' print 'OPTIONS:'
print ' -f, --format the output format to use. Valid options are fluxbox, icewm, jwm, windowmaker and pekwm' print ' -f, --format the output format to use. Valid options are fluxbox, icewm, jwm, windowmaker and pekwm'
print ' -i, --icons enable support for icons in the menus. Does not work with windowmaker' print ' -i, --icons enable support for icons in the menus. Does not work with windowmaker'
print ' -s, --size preferred icon size in pixels (default: 16)'
print ' -n, --no-submenu do not create a submenu. Does not work with windowmaker' print ' -n, --no-submenu do not create a submenu. Does not work with windowmaker'
print ' --pekwm-dynamic generate dynamic menus for pekwm' print ' --pekwm-dynamic generate dynamic menus for pekwm'
print ' -h, --help show this help message' print ' -h, --help show this help message'
@ -136,6 +145,7 @@ class MenuEntry:
self.path)) self.path))
def icon_full_path(icon): def icon_full_path(icon):
global iconsize
# If the icon path is absolute and exists, leave it alone. # If the icon path is absolute and exists, leave it alone.
# This takes care of software that has its own icons stored # This takes care of software that has its own icons stored
# in non-standard directories # in non-standard directories
@ -150,7 +160,7 @@ def icon_full_path(icon):
elif icon.endswith('.xpm'): elif icon.endswith('.xpm'):
icon = icon.replace('.xpm', '') icon = icon.replace('.xpm', '')
icon_theme = gtk.icon_theme_get_default() icon_theme = gtk.icon_theme_get_default()
icon = icon_theme.lookup_icon(icon, 16, gtk.ICON_LOOKUP_NO_SVG) icon = icon_theme.lookup_icon(icon, iconsize, gtk.ICON_LOOKUP_NO_SVG)
if icon: if icon:
icon = icon.get_filename() icon = icon.get_filename()
return icon return icon

Loading…
Cancel
Save