def main(): desktops = [] # init empty list # List of the categories we are interested in categories = ['Network' , 'Office', 'System', 'Development', 'Game', 'AudioVideo', 'Graphics', 'Settings'] categories.sort() path = '/usr/share/applications/' files = os.listdir(path) # Init our config object for file in files: if fnmatch(file, '*.desktop'): entry = DesktopEntry(os.path.join(path, file)) desktops.append(entry) for category in categories: print('my' + category + ' = { ') for entry in desktops: if category in entry.getCategories(): if getIconPath(entry.getIcon()) and not (fnmatch(getIconPath(entry.getIcon()), '*.ico') or fnmatch(getIconPath(entry.getIcon()), '*.svg')): # awesome fails with ico/svg print(' { "' + entry.getName() + '", "' + entry.getExec() + '", "' + getIconPath(entry.getIcon()) + '" },') else: print(' { "' + entry.getName() + '", "' + entry.getExec() + '" },') print('}\n') print('myprogmenu {') for category in categories: print(' { "' + category + '", my' + category + ' },') print('}\n') return 0
def parse_menu (menu, fvwm_menu = None): ''' parse menu file ''' prefix = "+" if fvwm_menu == None: print '' print 'DestroyMenu "%s"' % menu print 'AddToMenu "%s"' % menu else: print 'DestroyMenu recreate %s' % fvwm_menu prefix = "AddToMenu %s" % fvwm_menu for entry in menu.getEntries(): if isinstance(entry, xdg.Menu.Menu): icon = entry.getIcon() print u'%s "%s%%menu/folder.png%%" Popup "%s"' % (prefix, entry.getName(), entry) elif isinstance(entry, xdg.Menu.MenuEntry): desktop = DesktopEntry(entry.DesktopEntry.getFileName()) icon = desktop.getIcon() ind = icon.rfind('.') if ind != -1: icon = icon[0:ind] cmd = desktop.getExec().rstrip('%FUfu') cache_icon(icon) print u'%s "%s%%menu/%s.png%%" Exec exec %s' % (prefix, desktop.getName(), os.path.basename(icon), cmd) else: pass for entry in menu.getEntries(): if isinstance(entry, xdg.Menu.Menu): parse_menu(entry)
def parse_menu(menu, fvwm_menu=None): """ parse menu file """ prefix = "+" if fvwm_menu == None: print "" print 'DestroyMenu "%s"' % menu print 'AddToMenu "%s"' % menu else: print "DestroyMenu recreate %s" % fvwm_menu prefix = "AddToMenu %s" % fvwm_menu for entry in menu.getEntries(): if isinstance(entry, xdg.Menu.Menu): icon = entry.getIcon() print u'%s "%s%%menu/folder.png%%" Popup "%s"' % (prefix, entry.getName(), entry) elif isinstance(entry, xdg.Menu.MenuEntry): desktop = DesktopEntry(entry.DesktopEntry.getFileName()) icon = desktop.getIcon() ind = icon.rfind(".") if ind != -1: icon = icon[0:ind] cmd = desktop.getExec().rstrip("%FUfu") cache_icon(icon) print u'%s "%s%%menu/%s.png%%" Exec exec %s' % (prefix, desktop.getName(), os.path.basename(icon), cmd) else: pass for entry in menu.getEntries(): if isinstance(entry, xdg.Menu.Menu): parse_menu(entry)
def parse_qlaunch(): ''' parse recently opened files ''' for f in sorted(glob("%s/ydesk/qlaunch/*.desktop" % xdg_data_home)): if f.endswith(".desktop"): desktop = DesktopEntry(f) icon = desktop.getIcon() cache_icon(icon) cmd = desktop.getExec().rstrip('%FUfu') print('+ "%s%%%s.png%%" Exec exec %s' % (desktop.getName(), os.path.basename(icon), cmd))
def parsemenu(menu, name=""): if not name: name = menu.getPath() # print 'DestroyMenu "%s"' % name printtext('AddToMenu "%s"' % name) for entry in menu.getEntries(): if isinstance(entry, xdg.Menu.Menu): printmenu(entry.getName(), entry.getIcon(), 'Popup "%s"' % entry.getPath()) elif isinstance(entry, xdg.Menu.MenuEntry): desktop = DesktopEntry(entry.DesktopEntry.getFileName()) printmenu(desktop.getName(), desktop.getIcon(), options.exec_command + " " + desktop.getExec()) else: printtext('# not supported: ' + str(entry)) print for entry in menu.getEntries(): if isinstance(entry, xdg.Menu.Menu): parsemenu(entry)
def getservices(): # get list of desktop files from kde command = "grep -l kcmshell4 /usr/share/kde4/services/*.desktop" files = subprocess.getoutput(command).splitlines() # get list of desktop files from big command = "ls -d -1 " + os.getcwd() + "/includes/*.desktop" files += subprocess.getoutput(command).splitlines() # get current theme command = "kreadconfig --group 'Icons' --key 'Theme'" theme = subprocess.getoutput(command) # output output = {} # Map categories category_types = { "X-KDE-settings-accessibility": _("DESKTOP"), "X-KDE-settings-components": _("DESKTOP"), "X-KDE-settings-desktop": _("DESKTOP"), "X-KDE-settings-looknfeel": _("LOOK AND FEEL"), "X-KDE-settings-network": _("NETWORK AND CONNECTIVITY"), "X-KDE-settings-webbrowsing": _("NETWORK AND CONNECTIVITY"), "X-KDE-settings-peripherals": _("HARDWARE"), "X-KDE-settings-hardware": _("HARDWARE"), "X-KDE-settings-power": _("SYSTEM"), "X-KDE-settings-security": _("SECURITY"), "X-KDE-settings-sound": _("HARDWARE"), "X-KDE-settings-system": _("SYSTEM"), "X-KDE-settings-bluetooth": _("NETWORK AND CONNECTIVITY"), "X-KDE-settings-system-administration": _("SYSTEM"), "X-KDE-settings-user_manager": _("SYSTEM"), "X-KDE-information": _("INFORMATIONS OF SYSTEM") } # extra configurations apps_remove = open(os.getcwd() + "/conf/remove.conf").read().splitlines() apps_category = open(os.getcwd() + "/conf/category.conf").read().splitlines() # get informations from files for file in files: entry = DesktopEntry() # parse file try: entry.parse(file) except: continue # data from file name = entry.getName() comment = entry.getComment() icon = str(getIconPath(entry.getIcon(), theme=theme, size=32)) filename = os.path.splitext(os.path.basename(file))[0] category = None # fix error on get icon path if icon == "None": icon = str(getIconPath("preferences-system", theme=theme, size=32)) # get all categories from file file_categories = entry.getCategories() # use last category for elem in file_categories: category = elem # big applications if "/usr/share/kde4" not in file: execute = entry.getExec() category = _(category.upper()) # kde applications else: # remove applications if filename in apps_remove: continue execute = "kcmshell4 " + str(filename) # get category from file try: if category is None: raise Exception() category = category_types[category] except: category = _("OTHERS CONFIGURATIONS") # check recategorize regex = re.compile(filename + "=*") for line in apps_category: if regex.search(line): category = _(line.split("=")[1].upper()) # convert to upper category = category.upper() # fill array service if category not in output: output[category] = [] output[category].append({ "execute": execute, "comment": comment, "icon": icon, "name": name }) output = OrderedDict(sorted(output.items())) return output
def getservices(): # get list of desktop files from kde command = "grep -l kcmshell4 /usr/share/kde4/services/*.desktop" files = subprocess.getoutput(command).splitlines() # get list of desktop files from big command = "ls -d -1 " + os.getcwd() + "/includes/*.desktop" files += subprocess.getoutput(command).splitlines() # get current theme command = "kreadconfig --group 'Icons' --key 'Theme'" theme = subprocess.getoutput(command) # output output = {} # Map categories category_types = { "X-KDE-settings-accessibility": _("DESKTOP"), "X-KDE-settings-components": _("DESKTOP"), "X-KDE-settings-desktop": _("DESKTOP"), "X-KDE-settings-looknfeel": _("LOOK AND FEEL"), "X-KDE-settings-network": _("NETWORK AND CONNECTIVITY"), "X-KDE-settings-webbrowsing": _("NETWORK AND CONNECTIVITY"), "X-KDE-settings-peripherals": _("HARDWARE"), "X-KDE-settings-hardware": _("HARDWARE"), "X-KDE-settings-power": _("SYSTEM"), "X-KDE-settings-security": _("SECURITY"), "X-KDE-settings-sound": _("HARDWARE"), "X-KDE-settings-system": _("SYSTEM"), "X-KDE-settings-bluetooth": _("NETWORK AND CONNECTIVITY"), "X-KDE-settings-system-administration": _("SYSTEM"), "X-KDE-settings-user_manager": _("SYSTEM"), "X-KDE-information": _("INFORMATIONS OF SYSTEM") } # extra configurations apps_remove = open(os.getcwd() + "/conf/remove.conf").read().splitlines() apps_category = open(os.getcwd() + "/conf/category.conf").read().splitlines() # get informations from files for file in files: entry = DesktopEntry() # parse file try: entry.parse(file) except: continue # data from file name = entry.getName() comment = entry.getComment() icon = str(getIconPath(entry.getIcon(), theme=theme, size=32)) filename = os.path.splitext(os.path.basename(file))[0] category = None # fix error on get icon path if icon == "None": icon = str(getIconPath("preferences-system", theme=theme, size=32)) # get all categories from file file_categories = entry.getCategories() # use last category for elem in file_categories: category = elem # big applications if "/usr/share/kde4" not in file: execute = entry.getExec() category = _(category.upper()) # kde applications else: # remove applications if filename in apps_remove: continue execute = "kcmshell4 " + str(filename) # get category from file try: if category is None: raise Exception() category = category_types[category] except: category = _("OTHERS CONFIGURATIONS") # check recategorize regex=re.compile(filename + "=*") for line in apps_category: if regex.search(line): category = _(line.split("=")[1].upper()) # convert to upper category = category.upper() # fill array service if category not in output: output[category] = [] output[category].append({ "execute": execute, "comment": comment, "icon": icon, "name": name }) output = OrderedDict(sorted(output.items())) return output
#!/usr/bin/env python3 # # This file is a part of the NsCDE - Not so Common Desktop Environment # Author: Hegel3DReloaded # Licence: GPLv3 # import sys import os.path import xdg.IconTheme import xdg.Locale from xdg.DesktopEntry import * import xdg.BaseDirectory as basedir for finditem in basedir.xdg_data_dirs: possible = finditem + "/applications/" + sys.argv[2] + ".desktop" if os.path.exists(possible): entry = DesktopEntry(filename=possible) # print (entry) # print (possible) icon = entry.getIcon() comment = entry.getComment() execln = entry.getExec() iconpath = xdg.IconTheme.getIconPath(icon, int(sys.argv[1]), "NsCDE", ["png", "xpm", "svg"]) print(iconpath) # print (comment) # print (execln) break