aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/image.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-04-04 03:18:18 +0200
committerMattias Andrée <maandree@operamail.com>2015-04-04 03:18:18 +0200
commitb664d714806b9a2acc80cc647622bf417ec5217c (patch)
tree2c9362bebcb4476b01fdfd0fa833991ef1fd474c /src/plugins/image.py
parentimplement icon search (diff)
downloadxpybar-b664d714806b9a2acc80cc647622bf417ec5217c.tar.gz
xpybar-b664d714806b9a2acc80cc647622bf417ec5217c.tar.bz2
xpybar-b664d714806b9a2acc80cc647622bf417ec5217c.tar.xz
image: select best of the best icons
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--src/plugins/image.py20
1 files changed, 18 insertions, 2 deletions
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]