Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- import shlex
- import subprocess
- import os
- import sys
- import pyglet
- from pyglet.window import mouse
- import ConfigParser
- import operator
- import fnmatch
- import xdg.IconTheme
- class my_apps:
- def __init__(self, name , execute , icon=None):
- self.name = name
- self.execute = execute
- self.icon = icon
- class application_list:
- def __init__(self):
- self.known_cats = ['Favorites', 'Audio', 'Audio Video', 'Development', 'Education',
- 'Game' , 'Graphics', 'Network' , 'Office' , 'Science' ,
- 'Settings' , 'System' , 'Utility']
- self.list = {'Favorites':[], 'Audio':[], 'Audio Video':[], 'Development':[], 'Education':[],
- 'Game':[] , 'Graphics':[], 'Network':[] , 'Office':[] , 'Science':[] ,
- 'Settings':[] , 'System':[] , 'Utility':[]}
- self.get_app_list()
- for i in self.list.items():
- i[1].sort(key = operator.attrgetter('name'))
- self.known_cats.sort()
- def launch_ap(self, application):
- a = shlex.split(application)
- subprocess.Popen(a)
- def get_menu_items(self, app):
- #path = '/usr/share/applications/'
- section = 'Desktop Entry'
- config = ConfigParser.ConfigParser()
- config.readfp(open(app))
- exe = config.get(section,'Exec')
- name = config.get(section, 'Name')
- try:
- t = config.get(section, 'Type')
- except :
- t = None
- try:
- categories = config.get(section, 'Categories')
- cats = categories.split(";")
- except:
- cats = None
- try:
- icon = config.get(section, 'Icon')
- except :
- icon = None
- return name, exe , t, cats, icon
- def get_cats(self, categories):
- rt = []
- if categories:
- if len(categories) > 0:
- for i in categories:
- if i in self.known_cats:
- rt.append(i)
- return rt
- def find_icon_path(self):
- pass
- def get_app_list(self):
- apps=[]
- path = '/usr/share/applications/'
- for (path, dir , filename) in os.walk(path):
- for fn in filename:
- full_path = os.path.join(path, fn)
- filen, filee = os.path.splitext(fn)
- if filee == ".desktop":
- name, exe, t , cats, icon = self.get_menu_items(full_path)
- cat = self.get_cats(cats)
- exe = self.check_execute(exe)
- iconp = self.get_icon_path(icon)
- if cat is not None:
- for d in cat:
- my_a = my_apps(name, exe , iconp)
- self.list[d].append(my_a)
- def print_list(self):
- for i in self.list.items():
- for j in i[1]:
- print("{0} : {1}".format( j.name, j.execute, j.icon))
- def check_execute(self, execute):
- checklist = ['%U' , '%u', '%F' , '%f', '%i' , '%c', '%k']
- for i in checklist:
- execute = execute.replace(i, "")
- execute = execute.strip()
- return execute
- def get_icon_path_old(self, icon):
- file_found = None
- icon_path = None
- icon_path_home = '/home/jason/.icons/ProphetIcon13/apps/'
- knonw_file_icon_type = ['.png', '.jpg']
- if icon:
- try:
- with open(icon) as f:
- file_found = True
- icon_p = icon
- except IOError as e:
- file_found = False
- if not file_found:
- file_found = False
- icon_path = None
- matches = []
- if icon:
- for root, dirnames, filenames in os.walk(icon_path_home):
- for filename in fnmatch.filter(filenames, icon+'.*'):
- print filename
- matches.append(os.path.join(root, filename))
- print len(matches)
- if len(matches) > 0:
- icon_p = matches[0]
- fileName, fileExtension = os.path.splitext(icon_p)
- if fileExtension in knonw_file_icon_type:
- file_found = True
- icon_path = icon_p
- else:
- icon_path = None
- else:
- icon_path = None
- print icon , icon_path
- return icon_path
- def get_icon_path(self, icon):
- size = 64
- if icon:
- return xdg.IconTheme.getIconPath(icon,size)
- else:
- return None
Add Comment
Please, Sign In to add comment