From fb4c7230aeb750b70470f5b3a58df94bd2c5535e Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Wed, 20 Jun 2018 23:51:26 +0200 Subject: [PATCH] support {icon} --- py3status/modules/file_status.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/py3status/modules/file_status.py b/py3status/modules/file_status.py index 2814f29101..0a85eed474 100644 --- a/py3status/modules/file_status.py +++ b/py3status/modules/file_status.py @@ -92,12 +92,12 @@ def post_config_hook(self): raise Exception(STRING_NO_PATH) # deprecation - on = getattr(self, 'icon_available', None) - off = getattr(self, 'icon_unavailable', None) - if self.format == DEFAULT_FORMAT and (on or off): - self.format = u'\?if=paths {}|{}'.format(on or u'\u25cf', off or u'\u25a0') + self.on = getattr(self, 'icon_available', None) + self.off = getattr(self, 'icon_unavailable', None) + if self.format == DEFAULT_FORMAT and (self.on or self.off): + self.format = u'\?if=paths {}|{}'.format(self.on or u'\u25cf', self.off or u'\u25a0') new_format = u'\?color=paths [\?if=paths {}|{}]' - self.format = new_format.format(on or u'\u25cf', off or u'\u25a0') + self.format = new_format.format(self.on or u'\u25cf', self.off or u'\u25a0') msg = 'DEPRECATION: you are using old style configuration ' msg += 'parameters you should update to use the new format.' self.py3.log(msg) @@ -109,22 +109,27 @@ def post_config_hook(self): self.init = {'format_path': []} if self.py3.format_contains(self.format, 'format_path'): - self.init['format_path'] = self.py3.get_placeholders_list( - self.format_path - ) + self.init['format_path'] = self.py3.get_placeholders_list(self.format_path) def file_status(self): # init datas paths = sorted([files for path in self.path for files in glob(path)]) count_path = len(paths) format_path = None + icon = None + + # format icon + if self.py3.format_contains(self.format, 'icon'): + if count_path > 0: + icon = self.on + else: + icon = self.off # format paths if self.init['format_path']: new_data = [] format_path_separator = self.py3.safe_format( - self.format_path_separator - ) + self.format_path_separator) for pathname in paths: path = {} @@ -146,11 +151,13 @@ def file_status(self): self.py3.threshold_get_color(count_path, 'paths') return { - 'cached_until': self.py3.time_in(self.cache_timeout), + 'cached_until': + self.py3.time_in(self.cache_timeout), 'full_text': self.py3.safe_format( self.format, { 'paths': count_path, - 'format_path': format_path + 'format_path': format_path, + 'icon': icon } ) }