|
@ -1,5 +1,6 @@ |
|
|
#!/usr/bin/env python |
|
|
#!/usr/bin/env python |
|
|
# coding: utf-8 |
|
|
# coding: utf-8 |
|
|
|
|
|
# vim:et:sta:sts=4:sw=4:ts=8:tw=79: |
|
|
|
|
|
|
|
|
from __future__ import print_function |
|
|
from __future__ import print_function |
|
|
|
|
|
|
|
@ -32,37 +33,47 @@ else: |
|
|
if not os.path.isdir(desktop_dir): |
|
|
if not os.path.isdir(desktop_dir): |
|
|
sys.exit('ERROR: Could not find ' + desktop_dir) |
|
|
sys.exit('ERROR: Could not find ' + desktop_dir) |
|
|
|
|
|
|
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-applications.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-applications.directory') |
|
|
applications = de.getName().encode('utf-8') |
|
|
applications = de.getName().encode('utf-8') |
|
|
applications_icon = de.getIcon() |
|
|
applications_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-accessories.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-accessories.directory') |
|
|
accessories = de.getName().encode('utf-8') |
|
|
accessories = de.getName().encode('utf-8') |
|
|
accessories_icon = de.getIcon() |
|
|
accessories_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-development.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-development.directory') |
|
|
development = de.getName().encode('utf-8') |
|
|
development = de.getName().encode('utf-8') |
|
|
development_icon = de.getIcon() |
|
|
development_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-education.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-education.directory') |
|
|
education = de.getName().encode('utf-8') |
|
|
education = de.getName().encode('utf-8') |
|
|
education_icon = de.getIcon() |
|
|
education_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + 'xdgmenumaker-games.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + 'xdgmenumaker-games.directory') |
|
|
games = de.getName().encode('utf-8') |
|
|
games = de.getName().encode('utf-8') |
|
|
games_icon = de.getIcon() |
|
|
games_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-graphics.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-graphics.directory') |
|
|
graphics = de.getName().encode('utf-8') |
|
|
graphics = de.getName().encode('utf-8') |
|
|
graphics_icon = de.getIcon() |
|
|
graphics_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-multimedia.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-multimedia.directory') |
|
|
multimedia = de.getName().encode('utf-8') |
|
|
multimedia = de.getName().encode('utf-8') |
|
|
multimedia_icon = de.getIcon() |
|
|
multimedia_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-network.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-network.directory') |
|
|
network = de.getName().encode('utf-8') |
|
|
network = de.getName().encode('utf-8') |
|
|
network_icon = de.getIcon() |
|
|
network_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-office.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-office.directory') |
|
|
office = de.getName().encode('utf-8') |
|
|
office = de.getName().encode('utf-8') |
|
|
office_icon = de.getIcon() |
|
|
office_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-settings.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-settings.directory') |
|
|
settings = de.getName().encode('utf-8') |
|
|
settings = de.getName().encode('utf-8') |
|
|
settings_icon = de.getIcon() |
|
|
settings_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename = desktop_dir+'xdgmenumaker-system.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + |
|
|
|
|
|
'xdgmenumaker-system.directory') |
|
|
system = de.getName().encode('utf-8') |
|
|
system = de.getName().encode('utf-8') |
|
|
system_icon = de.getIcon() |
|
|
system_icon = de.getIcon() |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + 'xdgmenumaker-other.directory') |
|
|
de = dentry.DesktopEntry(filename=desktop_dir + 'xdgmenumaker-other.directory') |
|
@ -84,6 +95,7 @@ except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) as e: |
|
|
else: |
|
|
else: |
|
|
terminal_app = 'xterm' |
|
|
terminal_app = 'xterm' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv): |
|
|
def main(argv): |
|
|
global desktop |
|
|
global desktop |
|
|
global seticon |
|
|
global seticon |
|
@ -132,6 +144,7 @@ def main(argv): |
|
|
usage() |
|
|
usage() |
|
|
sys.exit(2) |
|
|
sys.exit(2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def usage(): |
|
|
def usage(): |
|
|
print('USAGE:', os.path.basename(sys.argv[0]), '[OPTIONS]') |
|
|
print('USAGE:', os.path.basename(sys.argv[0]), '[OPTIONS]') |
|
|
print() |
|
|
print() |
|
@ -152,7 +165,9 @@ def usage(): |
|
|
print(' xdgmenumaker -f windowmaker') |
|
|
print(' xdgmenumaker -f windowmaker') |
|
|
print(' xdgmenumaker -i -f fluxbox') |
|
|
print(' xdgmenumaker -i -f fluxbox') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MenuEntry: |
|
|
class MenuEntry: |
|
|
|
|
|
|
|
|
def __init__(self, category, name, icon, command, path): |
|
|
def __init__(self, category, name, icon, command, path): |
|
|
self.category = category |
|
|
self.category = category |
|
|
self.name = name |
|
|
self.name = name |
|
@ -164,6 +179,7 @@ class MenuEntry: |
|
|
return repr((self.category, self.name, self.icon, self.command, |
|
|
return repr((self.category, self.name, self.icon, self.command, |
|
|
self.path)) |
|
|
self.path)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def icon_full_path(icon): |
|
|
def icon_full_path(icon): |
|
|
# 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 |
|
@ -184,6 +200,7 @@ def icon_full_path(icon): |
|
|
icon = icon.get_filename() |
|
|
icon = icon.get_filename() |
|
|
return icon |
|
|
return icon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_entry_info(desktopfile): |
|
|
def get_entry_info(desktopfile): |
|
|
show = True |
|
|
show = True |
|
|
de = dentry.DesktopEntry(filename=desktopfile) |
|
|
de = dentry.DesktopEntry(filename=desktopfile) |
|
@ -214,7 +231,8 @@ def get_entry_info(desktopfile): |
|
|
if not path: |
|
|
if not path: |
|
|
path = None |
|
|
path = None |
|
|
|
|
|
|
|
|
#cleaning up categories and keeping only registered freedesktop.org main categories |
|
|
# cleaning up categories and keeping only registered freedesktop.org main |
|
|
|
|
|
# categories |
|
|
categories = de.getCategories() |
|
|
categories = de.getCategories() |
|
|
if 'AudioVideo' in categories: |
|
|
if 'AudioVideo' in categories: |
|
|
category = multimedia |
|
|
category = multimedia |
|
@ -256,6 +274,7 @@ def get_entry_info(desktopfile): |
|
|
else: |
|
|
else: |
|
|
return None |
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sortedcategories(applist): |
|
|
def sortedcategories(applist): |
|
|
categories = [] |
|
|
categories = [] |
|
|
for e in applist: |
|
|
for e in applist: |
|
@ -263,6 +282,7 @@ def sortedcategories(applist): |
|
|
categories = sorted(set(categories)) |
|
|
categories = sorted(set(categories)) |
|
|
return categories |
|
|
return categories |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def desktopfilelist(): |
|
|
def desktopfilelist(): |
|
|
dirs = [] |
|
|
dirs = [] |
|
|
# some directories are mentioned twice in bd.xdg_data_dirs, once |
|
|
# some directories are mentioned twice in bd.xdg_data_dirs, once |
|
@ -288,6 +308,7 @@ def desktopfilelist(): |
|
|
filelist.append(xdgdir + '/' + i) |
|
|
filelist.append(xdgdir + '/' + i) |
|
|
return filelist |
|
|
return filelist |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def menu(): |
|
|
def menu(): |
|
|
applist = [] |
|
|
applist = [] |
|
|
for desktopfile in desktopfilelist(): |
|
|
for desktopfile in desktopfilelist(): |
|
@ -310,6 +331,7 @@ def menu(): |
|
|
menu.append([c, appsincategory]) |
|
|
menu.append([c, appsincategory]) |
|
|
return menu |
|
|
return menu |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def category_icon(category): |
|
|
def category_icon(category): |
|
|
if category == accessories: |
|
|
if category == accessories: |
|
|
icon = accessories_icon |
|
|
icon = accessories_icon |
|
@ -337,6 +359,7 @@ def category_icon(category): |
|
|
icon = None |
|
|
icon = None |
|
|
return icon |
|
|
return icon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fluxboxmenu(): |
|
|
def fluxboxmenu(): |
|
|
if submenu: |
|
|
if submenu: |
|
|
spacing = ' ' |
|
|
spacing = ' ' |
|
@ -356,7 +379,8 @@ def fluxboxmenu(): |
|
|
cat_icon = category_icon(category) |
|
|
cat_icon = category_icon(category) |
|
|
cat_icon = icon_full_path(cat_icon) |
|
|
cat_icon = icon_full_path(cat_icon) |
|
|
if cat_icon: |
|
|
if cat_icon: |
|
|
print(spacing+'[submenu] ('+category+') <'+cat_icon+'>') |
|
|
print(spacing + '[submenu] (' + |
|
|
|
|
|
category + ') <' + cat_icon + '>') |
|
|
else: |
|
|
else: |
|
|
print(spacing + '[submenu] (' + category + ')') |
|
|
print(spacing + '[submenu] (' + category + ')') |
|
|
else: |
|
|
else: |
|
@ -373,11 +397,13 @@ def fluxboxmenu(): |
|
|
if icon is None: |
|
|
if icon is None: |
|
|
print(spacing + ' [exec] (' + name + ') {' + command + '}') |
|
|
print(spacing + ' [exec] (' + name + ') {' + command + '}') |
|
|
else: |
|
|
else: |
|
|
print(spacing+' [exec] ('+name+') {'+command+'} <'+icon+'>') |
|
|
print(spacing + ' [exec] (' + name + |
|
|
|
|
|
') {' + command + '} <' + icon + '>') |
|
|
print(spacing + '[end] # (' + category + ')') |
|
|
print(spacing + '[end] # (' + category + ')') |
|
|
if submenu: |
|
|
if submenu: |
|
|
print('[end] # (' + applications + ')') |
|
|
print('[end] # (' + applications + ')') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def windowmakermenu(): |
|
|
def windowmakermenu(): |
|
|
print('"' + applications + '" MENU') |
|
|
print('"' + applications + '" MENU') |
|
|
for i in menu(): |
|
|
for i in menu(): |
|
@ -390,6 +416,7 @@ def windowmakermenu(): |
|
|
print(' "' + category + '" END') |
|
|
print(' "' + category + '" END') |
|
|
print('"' + applications + '" END') |
|
|
print('"' + applications + '" END') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def icewmmenu(): |
|
|
def icewmmenu(): |
|
|
if submenu: |
|
|
if submenu: |
|
|
spacing = ' ' |
|
|
spacing = ' ' |
|
@ -415,13 +442,15 @@ def icewmmenu(): |
|
|
icon = j[1] |
|
|
icon = j[1] |
|
|
command = j[2] |
|
|
command = j[2] |
|
|
if seticon and icon is not None: |
|
|
if seticon and icon is not None: |
|
|
print(spacing+' prog "'+name+'" '+icon+' '+command) |
|
|
print(spacing + ' prog "' + name + |
|
|
|
|
|
'" ' + icon + ' ' + command) |
|
|
else: |
|
|
else: |
|
|
print(spacing + ' prog "' + name + '" _none_ ' + command) |
|
|
print(spacing + ' prog "' + name + '" _none_ ' + command) |
|
|
print(spacing + '}') |
|
|
print(spacing + '}') |
|
|
if submenu: |
|
|
if submenu: |
|
|
print('}') |
|
|
print('}') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pekwmmenu(): |
|
|
def pekwmmenu(): |
|
|
if pekwmdynamic: |
|
|
if pekwmdynamic: |
|
|
print("Dynamic {") |
|
|
print("Dynamic {") |
|
@ -432,7 +461,8 @@ def pekwmmenu(): |
|
|
spacing = ' ' |
|
|
spacing = ' ' |
|
|
if seticon: |
|
|
if seticon: |
|
|
app_icon = icon_full_path(applications_icon) |
|
|
app_icon = icon_full_path(applications_icon) |
|
|
print(dspacing+'Submenu = "'+applications+'" { Icon = "'+app_icon+'"') |
|
|
print(dspacing + 'Submenu = "' + applications + |
|
|
|
|
|
'" { Icon = "' + app_icon + '"') |
|
|
else: |
|
|
else: |
|
|
print(dspacing + 'Submenu = "' + applications + '" {') |
|
|
print(dspacing + 'Submenu = "' + applications + '" {') |
|
|
else: |
|
|
else: |
|
@ -442,7 +472,8 @@ def pekwmmenu(): |
|
|
cat_icon = category_icon(category) |
|
|
cat_icon = category_icon(category) |
|
|
cat_icon = icon_full_path(cat_icon) |
|
|
cat_icon = icon_full_path(cat_icon) |
|
|
if seticon and cat_icon is not None: |
|
|
if seticon and cat_icon is not None: |
|
|
print(dspacing+spacing+'Submenu = "'+category+'" { Icon = "'+cat_icon+'"') |
|
|
print(dspacing + spacing + 'Submenu = "' + |
|
|
|
|
|
category + '" { Icon = "' + cat_icon + '"') |
|
|
else: |
|
|
else: |
|
|
print(dspacing + spacing + 'Submenu = "' + category + '" {') |
|
|
print(dspacing + spacing + 'Submenu = "' + category + '" {') |
|
|
for j in i[1]: |
|
|
for j in i[1]: |
|
@ -460,15 +491,18 @@ def pekwmmenu(): |
|
|
# path does not exist |
|
|
# path does not exist |
|
|
command = 'cd ' + path + ' && ' + command + ' || ' + command |
|
|
command = 'cd ' + path + ' && ' + command + ' || ' + command |
|
|
if seticon and icon is not None: |
|
|
if seticon and icon is not None: |
|
|
print(dspacing+spacing+' Entry = "'+name+'" { Icon = "'+icon+'"; Actions = "Exec '+command+' &" }') |
|
|
print(dspacing + spacing + ' Entry = "' + name + |
|
|
|
|
|
'" { Icon = "' + icon + '"; Actions = "Exec ' + command + ' &" }') |
|
|
else: |
|
|
else: |
|
|
print(dspacing+spacing+' Entry = "'+name+'" { Actions = "Exec '+command+' &" }') |
|
|
print(dspacing + spacing + ' Entry = "' + name + |
|
|
|
|
|
'" { Actions = "Exec ' + command + ' &" }') |
|
|
print(dspacing + spacing + '}') |
|
|
print(dspacing + spacing + '}') |
|
|
if submenu: |
|
|
if submenu: |
|
|
print(dspacing + '}') |
|
|
print(dspacing + '}') |
|
|
if pekwmdynamic: |
|
|
if pekwmdynamic: |
|
|
print("}") |
|
|
print("}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def jwmmenu(): |
|
|
def jwmmenu(): |
|
|
print('<?xml version="1.0"?>') |
|
|
print('<?xml version="1.0"?>') |
|
|
print('<JWM>') |
|
|
print('<JWM>') |
|
@ -479,7 +513,8 @@ def jwmmenu(): |
|
|
if app_icon is None: |
|
|
if app_icon is None: |
|
|
print('<Menu label="' + applications + '">') |
|
|
print('<Menu label="' + applications + '">') |
|
|
else: |
|
|
else: |
|
|
print('<Menu icon="'+app_icon+'" label="'+applications+'">') |
|
|
print('<Menu icon="' + app_icon + |
|
|
|
|
|
'" label="' + applications + '">') |
|
|
else: |
|
|
else: |
|
|
print('<Menu label="' + applications + '">') |
|
|
print('<Menu label="' + applications + '">') |
|
|
else: |
|
|
else: |
|
@ -489,7 +524,8 @@ def jwmmenu(): |
|
|
cat_icon = category_icon(category) |
|
|
cat_icon = category_icon(category) |
|
|
cat_icon = icon_full_path(cat_icon) |
|
|
cat_icon = icon_full_path(cat_icon) |
|
|
if seticon and cat_icon is not None: |
|
|
if seticon and cat_icon is not None: |
|
|
print(spacing+'<Menu icon="'+cat_icon+'" label="'+category+'">') |
|
|
print(spacing + '<Menu icon="' + cat_icon + |
|
|
|
|
|
'" label="' + category + '">') |
|
|
else: |
|
|
else: |
|
|
print(spacing + '<Menu label="' + category + '">') |
|
|
print(spacing + '<Menu label="' + category + '">') |
|
|
for j in i[1]: |
|
|
for j in i[1]: |
|
@ -500,9 +536,11 @@ def jwmmenu(): |
|
|
if path is not None: |
|
|
if path is not None: |
|
|
command = 'cd ' + path + ' ; ' + command |
|
|
command = 'cd ' + path + ' ; ' + command |
|
|
if seticon and icon is not None: |
|
|
if seticon and icon is not None: |
|
|
print(spacing+' <Program icon="'+icon+'" label="'+name+'">'+command+'</Program>') |
|
|
print(spacing + ' <Program icon="' + icon + |
|
|
|
|
|
'" label="' + name + '">' + command + '</Program>') |
|
|
else: |
|
|
else: |
|
|
print(spacing+' <Program label="'+name+'">'+command+'</Program>') |
|
|
print(spacing + ' <Program label="' + |
|
|
|
|
|
name + '">' + command + '</Program>') |
|
|
print(spacing + '</Menu>') |
|
|
print(spacing + '</Menu>') |
|
|
if submenu: |
|
|
if submenu: |
|
|
print('</Menu>') |
|
|
print('</Menu>') |
|
|