Browse Source

Update utils.py to handle new UI changes

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
97adefb8fd
1 changed files with 19 additions and 60 deletions
  1. 79
      youtube_dl_gui/utils.py

79
youtube_dl_gui/utils.py

@ -262,15 +262,14 @@ def get_locale_file():
Note: Note:
Paths that get_locale_file() func searches. Paths that get_locale_file() func searches.
__main__ dir, library dir, /usr/share/youtube-dlg/locale
__main__ dir, library dir
""" """
DIR_NAME = 'locale'
DIR_NAME = "locale"
SEARCH_DIRS = [ SEARCH_DIRS = [
os.path.join(absolute_path(sys.argv[0]), DIR_NAME), os.path.join(absolute_path(sys.argv[0]), DIR_NAME),
os.path.join(os_path_dirname(__file__), DIR_NAME), os.path.join(os_path_dirname(__file__), DIR_NAME),
os.path.join('/usr', 'share', __appname__.lower(), DIR_NAME)
] ]
for directory in SEARCH_DIRS: for directory in SEARCH_DIRS:
@ -286,76 +285,36 @@ def get_icon_file():
Returns: Returns:
The path to youtube-dlg icon file if exists, else returns None. The path to youtube-dlg icon file if exists, else returns None.
Note:
Paths that get_icon_file() function searches.
__main__ dir, library dir, $XDG_DATA_DIRS
""" """
ICON_NAME = "youtube-dl-gui.png" ICON_NAME = "youtube-dl-gui.png"
SIZES = ("256", "128", "64", "48", "32", "16")
DIR_TEMPLATE = os.path.join("icons", "hicolor", "{size}x{size}", "apps", ICON_NAME)
ICONS = [DIR_TEMPLATE.format(size=size) for size in SIZES]
pixmaps_dir = get_pixmaps_dir()
search_dirs = [
os.path.join(absolute_path(sys.argv[0]), "data"),
os.path.join(os_path_dirname(__file__), "data"),
]
if pixmaps_dir is not None:
icon_file = os.path.join(pixmaps_dir, ICON_NAME)
# Append $XDG_DATA_DIRS on search_dirs
path = os_getenv("XDG_DATA_DIRS")
if path is not None:
for xdg_path in path.split(':'):
search_dirs.append(xdg_path)
# Also append /usr/share/pixmaps on search_dirs
#search_dirs.append("/usr/share/pixmaps")
for directory in search_dirs:
for icon in ICONS:
icon_file = os.path.join(directory, icon)
if os_path_exists(icon_file):
return icon_file
if os_path_exists(icon_file):
return icon_file
return None return None
def get_pixmaps_dir(): def get_pixmaps_dir():
"""Return absolute path to the pixmaps icons folder."""
# TODO probably will need support for other directories py2exe etc
return os.path.join(absolute_path(__file__), "data", "pixmaps")
"""Return absolute path to the pixmaps icons folder.
def json_load(filename):
if os_path_exists(filename):
with open(filename) as input_json_file:
return json.load(input_json_file)
return []
def json_store(filename, item):
with open(filename, 'w') as output_json_file:
json.dump(item, output_json_file)
def read_formats():
"""Returns a twodict containing all the formats from 'data/formats'."""
# TODO Support for other directories? Test with py2exe
formats_file = os.path.join(absolute_path(__file__), "data", "formats")
if os_path_exists(formats_file):
formats_dict = TwoWayOrderedDict()
Note:
Paths we search: __main__ dir, library dir
with open(formats_file) as input_file:
for line in input_file:
format_id, format_label = line.split('-')
"""
search_dirs = [
os.path.join(absolute_path(sys.argv[0]), "data"),
os.path.join(os_path_dirname(__file__), "data")
]
formats_dict[format_id.strip()] = format_label.strip()
for directory in search_dirs:
pixmaps_dir = os.path.join(directory, "pixmaps")
return formats_dict
if os_path_exists(pixmaps_dir):
return pixmaps_dir
return None return None
Loading…
Cancel
Save