Browse Source

Added support for icons.

Fixed an error message text.
pull/1/merge
gapan 13 years ago
parent
commit
2f3090d8c4
  1. 30
      src/xdgmenumaker

30
src/xdgmenumaker

@ -3,6 +3,7 @@
import os import os
import sys import sys
import getopt import getopt
import gtk
import xdg.DesktopEntry as dentry import xdg.DesktopEntry as dentry
import xdg.Exceptions as exc import xdg.Exceptions as exc
from operator import attrgetter from operator import attrgetter
@ -38,8 +39,9 @@ other = de.getName().encode('utf-8')
def main(argv): def main(argv):
global desktop global desktop
global seticon
try: try:
opts, args = getopt.getopt(argv, "hf:", ["help", "format="]) opts, args = getopt.getopt(argv, "hif:", ["help", "icons" ,"format="])
except getopt.GetoptError: except getopt.GetoptError:
usage() usage()
sys.exit(2) sys.exit(2)
@ -47,14 +49,17 @@ def main(argv):
if opt in ("-h", "--help"): if opt in ("-h", "--help"):
usage() usage()
sys.exit(0) sys.exit(0)
elif opt in ("-i", "--icons"):
seticon = True
elif opt in ("-f", "--format"): elif opt in ("-f", "--format"):
desktop = arg desktop = arg
if desktop is False: if desktop is False:
usage() usage()
sys.exit('ERROR: You can only specify either a .dep file with the -f switch or dependencies using the -d switch.') sys.exit('ERROR: You must specify the output format with -f')
elif desktop == "fluxbox": elif desktop == "fluxbox":
fluxboxmenu() fluxboxmenu()
elif desktop == "windowmaker": elif desktop == "windowmaker":
seticon = False
windowmakermenu() windowmakermenu()
else: else:
usage() usage()
@ -65,11 +70,13 @@ def usage():
print print
print 'OPTIONS:' print 'OPTIONS:'
print ' -f, --format the output format to use. Valid options are fluxbox and windowmaker' print ' -f, --format the output format to use. Valid options are fluxbox and windowmaker'
print ' -i, --icons enable support for icons in the menus. Only works with fluxbox'
print ' -h, --help show this help message' print ' -h, --help show this help message'
print ' You have to specify the output format using the -f switch.' print ' You have to specify the output format using the -f switch.'
print print
print 'EXAMPLES:' print 'EXAMPLES:'
print ' xdgmenumaker -f fluxbox' print ' xdgmenumaker -f windowmaker'
print ' xdgmenumaker -i -f fluxbox'
class MenuEntry: class MenuEntry:
def __init__(self, category, name, icon, command): def __init__(self, category, name, icon, command):
@ -83,13 +90,24 @@ class MenuEntry:
def get_entry_info(desktopfile): def get_entry_info(desktopfile):
global desktop global desktop
global seticon
show = True show = True
de = dentry.DesktopEntry(filename = desktopfile) de = dentry.DesktopEntry(filename = desktopfile)
name = de.getName().encode('utf-8') name = de.getName().encode('utf-8')
if seticon == True: if seticon == True:
# need to find a way to get the full path of the icon for the current theme # strip the directory and extension from the icon name
icon = de.getIcon() icon = os.path.basename(de.getIcon())
if icon.endswith('.png'):
icon = icon.replace('.png', '')
elif icon.endswith('.svg'):
icon = icon.replace('.svg', '')
elif icon.endswith('.xpm'):
icon = icon.replace('.xpm', '')
icon_theme = gtk.icon_theme_get_default()
icon = icon_theme.lookup_icon(icon, 16, gtk.ICON_LOOKUP_NO_SVG)
if icon:
icon = icon.get_filename()
else: else:
icon = None icon = None

Loading…
Cancel
Save