SHOW:
|
|
- or go back to the newest paste.
| 1 | #! /usr/bin/env python | |
| 2 | ||
| 3 | - | import os |
| 3 | + | import os, sys |
| 4 | import ConfigParser | |
| 5 | import xdg.IconTheme | |
| 6 | ||
| 7 | class my_apps: | |
| 8 | def __init__(self, name , execute , icon=None): | |
| 9 | self.name = name | |
| 10 | self.execute = execute | |
| 11 | self.icon = icon | |
| 12 | ||
| 13 | class application_list: | |
| 14 | def __init__(self): | |
| 15 | self.known_cats = ['Audio', 'Audio Video', 'Development', 'Education', | |
| 16 | 'Game' , 'Graphics', 'Network' , 'Office' , 'Science' , | |
| 17 | 'Settings' , 'System' , 'Utility', 'Other'] | |
| 18 | self.list = {'Audio':[], 'Audio Video':[], 'Development':[], 'Education':[],
| |
| 19 | 'Game':[] , 'Graphics':[], 'Network':[] , 'Office':[] , 'Science':[] , | |
| 20 | 'Settings':[] , 'System':[] , 'Utility':[], 'Other':[]} | |
| 21 | self.get_app_list() | |
| 22 | #for i in self.list.items(): | |
| 23 | #i.sort(key = operator.attrgetter('name'))
| |
| 24 | ||
| 25 | ||
| 26 | def get_menu_items(self, app): | |
| 27 | - | #path = '/usr/share/applications/' |
| 27 | + | |
| 28 | config = ConfigParser.ConfigParser() | |
| 29 | config.readfp(open(app)) | |
| 30 | ||
| 31 | try: | |
| 32 | exe = config.get(section,'Exec') | |
| 33 | except: | |
| 34 | exe = '\dev\Null' | |
| 35 | ||
| 36 | try: | |
| 37 | name = config.get(section, 'Name') | |
| 38 | except: | |
| 39 | name = 'N/A' | |
| 40 | ||
| 41 | try: | |
| 42 | t = config.get(section, 'Type') | |
| 43 | except : | |
| 44 | t = None | |
| 45 | try: | |
| 46 | categories = config.get(section, 'Categories') | |
| 47 | cats = categories.split(";")
| |
| 48 | except: | |
| 49 | cats = ['Other'] | |
| 50 | ||
| 51 | try: | |
| 52 | icon = config.get(section, 'Icon') | |
| 53 | except: | |
| 54 | icon = None | |
| 55 | ||
| 56 | #print ("Name:{0}\n\tExec:{1}\n\tType:{2}\n\tCat:{3}").format(name, exe, t, cats)
| |
| 57 | return name, exe , t, cats , icon | |
| 58 | ||
| 59 | def get_cats(self, categories): | |
| 60 | rt = [] | |
| 61 | if categories: | |
| 62 | if len(categories) > 0: | |
| 63 | for i in categories: | |
| 64 | if i in self.known_cats: | |
| 65 | rt.append(i) | |
| 66 | return rt | |
| 67 | ||
| 68 | def get_app_list(self): | |
| 69 | apps=[] | |
| 70 | path = str(sys.argv[1]) | |
| 71 | - | path = '/home/jason/.local/share/applications/' |
| 71 | + | |
| 72 | for fn in filename: | |
| 73 | full_path = os.path.join(path, fn) | |
| 74 | filen, filee = os.path.splitext(fn) | |
| 75 | if filee == ".desktop": | |
| 76 | name, exe, t , cats , icon = self.get_menu_items(full_path) | |
| 77 | cat = self.get_cats(cats) | |
| 78 | exe = self.check_execute(exe) | |
| 79 | icon = self.check_icon(icon) | |
| 80 | if cat is not None: | |
| 81 | for d in cat: | |
| 82 | my_a = my_apps(name, exe, icon) | |
| 83 | self.list[d].append(my_a) | |
| 84 | ||
| 85 | - | #print("Done ------------")
|
| 85 | + | |
| 86 | checklist = ['%U' , '%u', '%F' , '%f', '%i' , '%c', '%k'] | |
| 87 | - | def print_list(self): |
| 87 | + | |
| 88 | - | print " outputing List" |
| 88 | + | |
| 89 | - | for i in self.list.items(): |
| 89 | + | |
| 90 | - | for j in i[1]: |
| 90 | + | |
| 91 | - | print("{0} : {1} ".format( j.name, j.execute))
|
| 91 | + | |
| 92 | ||
| 93 | def check_icon(self,icon): | |
| 94 | if icon is not None: | |
| 95 | if os.path.isfile(icon): | |
| 96 | return icon | |
| 97 | else: | |
| 98 | try: | |
| 99 | - | #print execute |
| 99 | + | |
| 100 | except: | |
| 101 | icon = "" | |
| 102 | return icon | |
| 103 | else: | |
| 104 | return "" | |
| 105 | ||
| 106 | ml = application_list() | |
| 107 | print "<openbox_pipe_menu>" | |
| 108 | for j in ml.known_cats: | |
| 109 | if len(ml.list[j]) > 0 : | |
| 110 | print "<menu id=\"user-{0}\" label=\"{0}\">".format(j)
| |
| 111 | for i in ml.list[j]: | |
| 112 | print "<item label=\"{0}\" icon=\"{2}\">\n\t<action name=\"Execute\">\n\t\t<execute>{1}</execute>\n\t</action>\n</item>".format(i.name,i.execute,i.icon)
| |
| 113 | print "</menu>" | |
| 114 | print "</openbox_pipe_menu>" |