From fea6f8948ebfa924d313cd78dcf28b5aa3665ff1 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Wed, 14 May 2014 23:33:25 +0300 Subject: [PATCH] Add icons search algorithm --- youtube_dl_gui/Utils.py | 61 ++++++++++++++++++++++++++++++++++ youtube_dl_gui/YoutubeDLGUI.py | 6 ++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/youtube_dl_gui/Utils.py b/youtube_dl_gui/Utils.py index 3c0f804..2f9b137 100644 --- a/youtube_dl_gui/Utils.py +++ b/youtube_dl_gui/Utils.py @@ -142,3 +142,64 @@ def get_time(seconds): dtime['seconds'] = seconds % 86400 % 3600 % 60 return dtime + + +def get_icon_path(): + ''' Return icon path else return None. Search package_path/icons, + $HOME/.icons, $XDG_DATA_DIRS/icons, /usr/share/pixmaps in that order''' + SIZES = ('256x256', '128x128', '64x64', '32x32', '16x16') + ICON_NAME = 'youtube-dl-gui_' + ICON_EXTENSION = '.png' + + ICONS_LIST = [ICON_NAME + s + ICON_EXTENSION for s in SIZES] + + # Package path backwards 2 times + # e.g. /home/user/test/t1/t2 + # /home/user/test/t1/t2/icons + # /home/user/test/t1/icons + path = abs_path(__file__) + for i in range(2): + temp_path = fix_path(path) + 'icons' + + for icon in ICONS_LIST: + p = fix_path(temp_path) + icon + + if file_exist(p): + return p + + path = path.split(path_seperator()) + path.pop() + path = path_seperator().join(path) + + # $HOME/.icons + path = fix_path(get_home()) + '.icons' + + for icon in ICONS_LIST: + temp_path = fix_path(path) + icon + + if file_exist(temp_path): + return path + + # $XDG_DATA_DIRS/icons + path = os.getenv('XDG_DATA_DIRS') + for temp_path in path.split(':'): + temp_path = fix_path(temp_path) + 'icons' + temp_path = fix_path(temp_path) + 'hicolor' + + for size in SIZES: + p = fix_path(temp_path) + size + p = fix_path(p) + 'apps' + p = fix_path(p) + ICON_NAME + size + ICON_EXTENSION + + if file_exist(p): + return p + + # /usr/share/pixmaps + path = '/usr/share/pixmaps/' + for icon in ICONS_LIST: + temp_path = path + icon + + if file_exist(temp_path): + return temp_path + + return None diff --git a/youtube_dl_gui/YoutubeDLGUI.py b/youtube_dl_gui/YoutubeDLGUI.py index 21315a0..2d0734f 100644 --- a/youtube_dl_gui/YoutubeDLGUI.py +++ b/youtube_dl_gui/YoutubeDLGUI.py @@ -19,11 +19,11 @@ from .Utils import ( get_user_config_path, video_is_dash, audio_is_dash, + get_icon_path, shutdown_sys, file_exist, get_time, fix_path, - abs_path, open_dir, os_type ) @@ -67,7 +67,7 @@ SUBS_LANG = [ "German" ] -ICON = fix_path(abs_path(__file__)) + 'icons/youtube-dl-gui.ico' +ICON = get_icon_path() CONFIG_PATH = fix_path(get_user_config_path()) + __appname__.lower() @@ -81,7 +81,7 @@ class MainFrame(wx.Frame): self.init_gui() # set app icon - self.SetIcon(wx.Icon(ICON, wx.BITMAP_TYPE_ICO)) + self.SetIcon(wx.Icon(ICON, wx.BITMAP_TYPE_PNG)) # set publisher for update thread Publisher.subscribe(self.update_handler, "update")