Browse Source

Improve icon extension handling

In addition to other icon file types, also detect svgz icons. Do not
use them in any case, since none of the supported WMs can use them.

Also, make the extension detection case-insensitive. I've never seen an
icon extension with capitals in the wild, but who knows...

Finally, clean up the code a bit, so it reads easier.
pull/9/head
George Vlahavas 8 years ago
parent
commit
85dffdd9a5
  1. 13
      src/xdgmenumaker

13
src/xdgmenumaker

@ -269,12 +269,10 @@ def usage():
def icon_strip(icon): def icon_strip(icon):
# strip the directory and extension from the icon name # strip the directory and extension from the icon name
icon = os.path.basename(icon) icon = os.path.basename(icon)
if icon.endswith('.png'): main, ext = os.path.splitext(icon)
icon = icon.replace('.png', '') ext = ext.lower()
elif icon.endswith('.svg'): if ext == '.png' or ext == '.svg' or ext == '.svgz' or ext == '.xpm':
icon = icon.replace('.svg', '') return main
elif icon.endswith('.xpm'):
icon = icon.replace('.xpm', '')
return icon return icon
@ -299,7 +297,8 @@ def icon_full_path(icon):
# But we don't want to do this for svg icons, since none of the WMs # But we don't want to do this for svg icons, since none of the WMs
# supports them. In that case, just fall back to looking for the icon # supports them. In that case, just fall back to looking for the icon
# elsewhere in the system. # elsewhere in the system.
if os.path.exists(icon) and os.path.splitext(icon)[1] != ".svg": ext = os.path.splitext(icon)[1].lower()
if os.path.exists(icon) and ext != ".svg" and ext != ".svgz":
if max_icon_size: if max_icon_size:
return icon_max_size(icon) return icon_max_size(icon)
else: else:

Loading…
Cancel
Save