Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
print " { \"%s\", submenu%d }," % (entry, i)
i += 1
print '}'
if len(sys.argv) > 1:
menufile = sys.argv[1] + '.menu'
else:
menufile = 'applications.menu'
lang = os.environ.get('LANG')
if lang:
xdg.Config.setLocale(lang)
# lie to get the same menu as in GNOME
xdg.Config.setWindowManager('GNOME')
if icons:
theme = Gtk.IconTheme.get_default()
menu = xdg.Menu.parse(menufile)
#map(walk_menu, menu.getEntries())
map(generate_awesome_menu, menu.getEntries())
generate_main_menu()
def __setFilename(self):
if not xdg.Config.root_mode:
path = xdg_data_dirs[0]
else:
path = xdg_data_dirs[1]
if self.DesktopEntry.getType() == "Application":
dir_ = os.path.join(path, "applications")
else:
dir_ = os.path.join(path, "desktop-directories")
self.DesktopEntry.filename = os.path.join(dir_, self.Filename)
# check if it has an extension and strip it
if os.path.splitext(iconname)[1][1:] in extensions:
iconname = os.path.splitext(iconname)[0]
# parse theme files
try:
if themes[0].name != theme:
themes = []
__addTheme(theme)
except IndexError:
__addTheme(theme)
# more caching (icon looked up in the last 5 seconds?)
tmp = "".join([iconname, str(size), theme, "".join(extensions)])
if eache.has_key(tmp):
if int(time.time() - eache[tmp][0]) >= xdg.Config.cache_time:
del eache[tmp]
else:
return eache[tmp][1]
for thme in themes:
icon = LookupIcon(iconname, size, thme, extensions)
if icon:
eache[tmp] = [time.time(), icon]
return icon
# cache stuff again (directories lookuped up in the last 5 seconds?)
for directory in icondirs:
if (not dache.has_key(directory) \
or (int(time.time() - dache[directory][1]) >= xdg.Config.cache_time \
and dache[directory][2] < os.path.getmtime(directory))) \
and os.path.isdir(directory):
theme.
extensions :
List of preferred file extensions.
Example::
>>> getIconPath("inkscape", 32)
'/usr/share/icons/hicolor/32x32/apps/inkscape.png'
"""
global themes
if size == None:
size = xdg.Config.icon_size
if theme == None:
theme = xdg.Config.icon_theme
# if we have an absolute path, just return it
if os.path.isabs(iconname):
return iconname
# check if it has an extension and strip it
if os.path.splitext(iconname)[1][1:] in extensions:
iconname = os.path.splitext(iconname)[0]
# parse theme files
if (themes == []) or (themes[0].name != theme):
themes = list(__get_themes(theme))
# more caching (icon looked up in the last 5 seconds?)
tmp = (iconname, size, theme, tuple(extensions))
try:
def getIconPath(iconname, size = None, theme = None, extensions = ["png", "svg", "xpm"]):
global themes
if size == None:
size = xdg.Config.icon_size
if theme == None:
theme = xdg.Config.icon_theme
# if we have an absolute path, just return it
if os.path.isabs(iconname):
return iconname
# check if it has an extension and strip it
if os.path.splitext(iconname)[1][1:] in extensions:
iconname = os.path.splitext(iconname)[0]
# parse theme files
try:
if themes[0].name != theme:
themes = []
__addTheme(theme)
except IndexError:
__addTheme(theme)
def __setFilename(self):
if xdg.Config.root_mode == False:
path = xdg_data_dirs[0]
else:
path= xdg_data_dirs[1]
if self.DesktopEntry.getType() == "Application":
dir = os.path.join(path, "applications")
else:
dir = os.path.join(path, "desktop-directories")
self.DesktopEntry.filename = os.path.join(dir, self.Filename)
entry.Show = "NoDisplay"
self.Visible -= 1
elif entry.Directory.DesktopEntry.getHidden():
entry.Show = "Hidden"
self.Visible -= 1
elif isinstance(entry, MenuEntry):
if entry.DesktopEntry.getNoDisplay():
entry.Show = "NoDisplay"
self.Visible -= 1
elif entry.DesktopEntry.getHidden():
entry.Show = "Hidden"
self.Visible -= 1
elif entry.DesktopEntry.getTryExec() and not entry.DesktopEntry.findTryExec():
entry.Show = "NoExec"
self.Visible -= 1
elif xdg.Config.windowmanager:
if (entry.DesktopEntry.OnlyShowIn != [] and (
xdg.Config.windowmanager not in entry.DesktopEntry.OnlyShowIn
)
) or (
xdg.Config.windowmanager in entry.DesktopEntry.NotShowIn
):
entry.Show = "NotShowIn"
self.Visible -= 1
elif isinstance(entry, Separator):
self.Visible -= 1
# remove separators at the beginning and at the end
if len(self.Entries) > 0:
if isinstance(self.Entries[0], Separator):
self.Entries[0].Show = False
if len(self.Entries) > 1:
def LookupIcon(iconname, size, theme, extensions):
# look for the cache
if theme.name not in cache:
cache[theme.name] = []
cache[theme.name].append(time.time() - (xdg.Config.cache_time + 1)) # [0] last time of lookup
cache[theme.name].append(0) # [1] mtime
cache[theme.name].append(dict()) # [2] dir: [subdir, [items]]
# cache stuff (directory lookuped up the in the last 5 seconds?)
if int(time.time() - cache[theme.name][0]) >= xdg.Config.cache_time:
cache[theme.name][0] = time.time()
for subdir in theme.getDirectories():
for directory in icondirs:
dir = os.path.join(directory,theme.name,subdir)
if (dir not in cache[theme.name][2] \
or cache[theme.name][1] < os.path.getmtime(os.path.join(directory,theme.name))) \
and subdir != "" \
and os.path.isdir(dir):
cache[theme.name][2][dir] = [subdir, os.listdir(dir)]
cache[theme.name][1] = os.path.getmtime(os.path.join(directory,theme.name))
for dir, values in cache[theme.name][2].items():
if DirectoryMatchesSize(values[0], size, theme):
for extension in extensions:
if iconname + "." + extension in values[1]:
return os.path.join(dir, iconname + "." + extension)
def getIconPath(iconname, size = None, theme = None, extensions = ["png", "svg", "xpm"]):
global themes
if size == None:
size = xdg.Config.icon_size
if theme == None:
theme = xdg.Config.icon_theme
# if we have an absolute path, just return it
if os.path.isabs(iconname):
return iconname
# check if it has an extension and strip it
if os.path.splitext(iconname)[1][1:] in extensions:
iconname = os.path.splitext(iconname)[0]
# parse theme files
try:
if themes[0].name != theme:
themes = []
__addTheme(theme)
except IndexError:
__addTheme(theme)
def LookupIcon(iconname, size, theme, extensions):
# look for the cache
if theme.name not in theme_cache:
theme_cache[theme.name] = []
theme_cache[theme.name].append(time.time() - (xdg.Config.cache_time + 1)) # [0] last time of lookup
theme_cache[theme.name].append(0) # [1] mtime
theme_cache[theme.name].append(dict()) # [2] dir: [subdir, [items]]
# cache stuff (directory lookuped up the in the last 5 seconds?)
if int(time.time() - theme_cache[theme.name][0]) >= xdg.Config.cache_time:
theme_cache[theme.name][0] = time.time()
for subdir in theme.getDirectories():
for directory in icondirs:
dir = os.path.join(directory,theme.name,subdir)
if (dir not in theme_cache[theme.name][2] \
or theme_cache[theme.name][1] < os.path.getmtime(os.path.join(directory,theme.name))) \
and subdir != "" \
and os.path.isdir(dir):
theme_cache[theme.name][2][dir] = [subdir, os.listdir(dir)]
theme_cache[theme.name][1] = os.path.getmtime(os.path.join(directory,theme.name))