From b664d714806b9a2acc80cc647622bf417ec5217c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 4 Apr 2015 03:18:18 +0200 Subject: image: select best of the best icons MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/plugins/image.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/plugins/image.py b/src/plugins/image.py index 2f30fed..b87703e 100644 --- a/src/plugins/image.py +++ b/src/plugins/image.py @@ -205,7 +205,23 @@ class Image: return files[0] return None - best = [f for f in [find_best(d) for d in directories] if f is not None] + best = [(f, d) for f, d in zip([find_best(d) for d in directories], directories) if f is not None] + if len(best) == 0: + return None - return None if len(best) == 0 else best[0] + best = [(f, t(lambda : int(f[len(d):].split('/')[2]).split('x')[0], -1)) for f, d in best] + max_size = 1 + max(s for _f, s in best) + best = [(f, max_size if s < 0 else s) for (f, s) in best] + if preferred_size is None: + preferred_size = max_size + + high = [(f, s) for f, s in best if (s >= preferred_size)] + low = [(f, s) for f, s in best if (s < preferred_size)] + high.sort() + low.sort() + high = [(f, s) for f, s in high] + low = [(f, s) for f, s in reversed(low)] + best = high + low + + return best[0][0] -- cgit v1.2.3-70-g09d2