From 7b70f50b9bd896792de5aebf7a69af4826117bd3 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Wed, 18 Mar 2015 17:17:58 +0000 Subject: Pomodoro module: display time as a progress bar --- py3status/modules/pomodoro.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 1a167b9..bbfae1e 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -6,6 +6,10 @@ Pomodoro countdown on i3bar originally written by @Fandekasp (Adrien Lemaire) from subprocess import call from time import time +# PROGRESS_BAR_ITEMS = u"▁▃▄▅▆▇█" +PROGRESS_BAR_ITEMS = u"▏▎▍▌▋▊▉" +N_PROGRESS_BARS = 5 + class Py3status: @@ -15,10 +19,11 @@ class Py3status: timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 - def __init__(self): + def __init__(self, display_bar=True): self.__setup('stop') self.alert = False self.run = False + self.display_bar = display_bar def on_click(self, i3s_output_list, i3s_config, event): """ @@ -42,9 +47,27 @@ class Py3status: """ Return the response full_text string """ - return { - 'full_text': '{} ({})'.format(self.prefix, self.timer) - } + if self.display_bar and self.status in ('start', 'pause'): + bar = u'' + items_cnt = len(PROGRESS_BAR_ITEMS) + bar = u'' + bar_val = float(self.timer) / self.time_window * N_PROGRESS_BARS + while bar_val > 0: + selector = int(bar_val * items_cnt) + selector = min(selector, items_cnt - 1) + bar += PROGRESS_BAR_ITEMS[selector] + bar_val -= 1 + + bar = bar.ljust(N_PROGRESS_BARS).encode('utf_8') + else: + bar = self.timer + + if self.run: + text = '{} [{}]'.format(self.prefix, bar) + else: + text = '{} ({})'.format(self.prefix, bar) + + return dict(full_text=text) def __setup(self, status): """ @@ -55,20 +78,24 @@ class Py3status: self.prefix = 'Pomodoro' self.status = 'stop' self.timer = self.timer_pomodoro + self.time_window = self.timer self.breaks = 1 elif status == 'start': self.prefix = 'Pomodoro' self.timer = self.timer_pomodoro + self.time_window = self.timer elif status == 'pause': self.prefix = 'Break #%d' % self.breaks if self.breaks > self.max_breaks: self.timer = self.timer_long_break + self.time_window = self.timer self.breaks = 1 else: self.breaks += 1 self.timer = self.timer_break + self.time_window = self.timer def __decrement(self): """ -- cgit v1.3 From c54b3a3d92c25bd5ee28e2d344a9efca86677063 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Wed, 18 Mar 2015 18:34:36 +0000 Subject: Pomodoro module: make progress bar configurable --- py3status/modules/pomodoro.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index bbfae1e..af42f08 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -8,22 +8,31 @@ from time import time # PROGRESS_BAR_ITEMS = u"▁▃▄▅▆▇█" PROGRESS_BAR_ITEMS = u"▏▎▍▌▋▊▉" -N_PROGRESS_BARS = 5 class Py3status: + """ + Configuration parameters: + - max_breaks: maximum number of breaks + - timer_break: normal break time (seconds) + - timer_long_break: long break time (seconds) + - timer_pomodoro: pomodoro time (seconds) + - display_bar: display time in bars when True, otherwise in seconds + - num_progress_bars: number of progress bars + """ # available configuration parameters max_breaks = 4 timer_break = 5 * 60 timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 + display_bar = True + num_progress_bars = 5 - def __init__(self, display_bar=True): + def __init__(self): self.__setup('stop') self.alert = False self.run = False - self.display_bar = display_bar def on_click(self, i3s_output_list, i3s_config, event): """ @@ -51,14 +60,14 @@ class Py3status: bar = u'' items_cnt = len(PROGRESS_BAR_ITEMS) bar = u'' - bar_val = float(self.timer) / self.time_window * N_PROGRESS_BARS + bar_val = float(self.timer) / self.time_window * self.num_progress_bars while bar_val > 0: selector = int(bar_val * items_cnt) selector = min(selector, items_cnt - 1) bar += PROGRESS_BAR_ITEMS[selector] bar_val -= 1 - bar = bar.ljust(N_PROGRESS_BARS).encode('utf_8') + bar = bar.ljust(self.num_progress_bars).encode('utf_8') else: bar = self.timer -- cgit v1.3 From 786470a09ee1d7736c41dcd89db632657f9f87c7 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Thu, 19 Mar 2015 10:18:03 +0000 Subject: Pomodoro module: disable progress bar by default --- py3status/modules/pomodoro.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index af42f08..07e3087 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -26,7 +26,7 @@ class Py3status: timer_break = 5 * 60 timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 - display_bar = True + display_bar = False num_progress_bars = 5 def __init__(self): -- cgit v1.3 From 78f09107102d36f3592a3e69409a2b58101e8704 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Thu, 19 Mar 2015 10:20:46 +0000 Subject: Pomodoro module: sort configuration parameters --- py3status/modules/pomodoro.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 07e3087..3041c56 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -13,21 +13,21 @@ PROGRESS_BAR_ITEMS = u"▏▎▍▌▋▊▉" class Py3status: """ Configuration parameters: + - display_bar: display time in bars when True, otherwise in seconds - max_breaks: maximum number of breaks + - num_progress_bars: number of progress bars - timer_break: normal break time (seconds) - timer_long_break: long break time (seconds) - timer_pomodoro: pomodoro time (seconds) - - display_bar: display time in bars when True, otherwise in seconds - - num_progress_bars: number of progress bars """ # available configuration parameters + display_bar = False max_breaks = 4 + num_progress_bars = 5 timer_break = 5 * 60 timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 - display_bar = False - num_progress_bars = 5 def __init__(self): self.__setup('stop') -- cgit v1.3 From f8f7069e42061107ac5f3a2619d47bfedff96e55 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Thu, 19 Mar 2015 11:15:16 +0000 Subject: Pomodoro module: add sound support --- py3status/modules/pomodoro.py | 45 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 3041c56..63068b5 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -4,8 +4,15 @@ Pomodoro countdown on i3bar originally written by @Fandekasp (Adrien Lemaire) """ from subprocess import call +from syslog import syslog, LOG_INFO from time import time +try: + from pygame import mixer + mixer.init() +except ImportError: + mixer = None + # PROGRESS_BAR_ITEMS = u"▁▃▄▅▆▇█" PROGRESS_BAR_ITEMS = u"▏▎▍▌▋▊▉" @@ -16,15 +23,21 @@ class Py3status: - display_bar: display time in bars when True, otherwise in seconds - max_breaks: maximum number of breaks - num_progress_bars: number of progress bars - - timer_break: normal break time (seconds) - - timer_long_break: long break time (seconds) - - timer_pomodoro: pomodoro time (seconds) + - sound_break_end: break end sound (file path) + - sound_pomodoro_end: pomodoro end sound (file path) + - sound_pomodoro_start: pomodoro start sound (file path) + - timer_break: normal break time (seconds) (requires pygame) + - timer_long_break: long break time (seconds) (requires pygame) + - timer_pomodoro: pomodoro time (seconds) (requires pygame) """ # available configuration parameters display_bar = False max_breaks = 4 num_progress_bars = 5 + sound_break_end = None + sound_pomodoro_end = None + sound_pomodoro_start = None timer_break = 5 * 60 timer_long_break = 15 * 60 timer_pomodoro = 25 * 60 @@ -41,6 +54,7 @@ class Py3status: if event['button'] == 1: if self.status == 'stop': self.status = 'start' + self.__play_sound(self.sound_pomodoro_start) self.run = True elif event['button'] == 2: @@ -60,7 +74,8 @@ class Py3status: bar = u'' items_cnt = len(PROGRESS_BAR_ITEMS) bar = u'' - bar_val = float(self.timer) / self.time_window * self.num_progress_bars + bar_val = float(self.timer) / self.time_window * \ + self.num_progress_bars while bar_val > 0: selector = int(bar_val * items_cnt) selector = min(selector, items_cnt - 1) @@ -118,9 +133,12 @@ class Py3status: if self.status == 'start': self.__setup('pause') self.status = 'pause' + self.__play_sound(self.sound_pomodoro_end) + elif self.status == 'pause': self.__setup('start') self.status = 'start' + self.__play_sound(self.sound_break_end) def __i3_nagbar(self, level='warning'): """ @@ -158,6 +176,25 @@ class Py3status: response['cached_until'] = time() return response + def __play_sound(self, sound_fname): + """Play sound if required + """ + if not sound_fname: + return + + if not mixer: + syslog(LOG_INFO, "pomodoro module: the pygame library is required" + " to play sounds") + return + + try: + mixer.music.load(sound_fname) + except Exception as e: + return + + mixer.music.play() + + if __name__ == "__main__": """ Test this module by calling it directly. -- cgit v1.3 From 20c07b755976807b68d3940dbe7b4e487f2e5c69 Mon Sep 17 00:00:00 2001 From: rixx Date: Thu, 19 Mar 2015 14:49:22 +0100 Subject: replaced 'pause' by 'break' 'break' was already used for notifications and this way 'pause' can be used when a running Pomodoro needs to be paused (to be resumed later) --- py3status/modules/pomodoro.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 1a167b9..9b8fb63 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -34,7 +34,7 @@ class Py3status: self.run = False elif event['button'] == 3: - self.__setup('pause') + self.__setup('break') self.run = False @property @@ -61,7 +61,7 @@ class Py3status: self.prefix = 'Pomodoro' self.timer = self.timer_pomodoro - elif status == 'pause': + elif status == 'break': self.prefix = 'Break #%d' % self.breaks if self.breaks > self.max_breaks: self.timer = self.timer_long_break @@ -80,9 +80,9 @@ class Py3status: self.run = False self.__i3_nagbar() if self.status == 'start': - self.__setup('pause') - self.status = 'pause' - elif self.status == 'pause': + self.__setup('break') + self.status = 'break' + elif self.status == 'break': self.__setup('start') self.status = 'start' @@ -114,7 +114,7 @@ class Py3status: if self.status == 'start': response['color'] = i3s_config['color_good'] - elif self.status == 'pause': + elif self.status == 'break': response['color'] = i3s_config['color_degraded'] else: response['color'] = i3s_config['color_bad'] -- cgit v1.3 From c2e23c442f9df310d94ff9b44835096a43257001 Mon Sep 17 00:00:00 2001 From: rixx Date: Thu, 19 Mar 2015 15:15:42 +0100 Subject: A second right-click stops the ongoing break In case a break is too long for you --- py3status/modules/pomodoro.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index 9b8fb63..db2a60d 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -34,7 +34,10 @@ class Py3status: self.run = False elif event['button'] == 3: - self.__setup('break') + if self.status == 'break': + self.__setup('start') + else: + self.__setup('break') self.run = False @property -- cgit v1.3 From 64a78c990dd072ba3d70e182c4f16e55c9e9ef3b Mon Sep 17 00:00:00 2001 From: rixx Date: Thu, 19 Mar 2015 15:22:53 +0100 Subject: Left click can now pause and resume a Pomodoro --- py3status/modules/pomodoro.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index db2a60d..bf86e96 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -27,7 +27,21 @@ class Py3status: if event['button'] == 1: if self.status == 'stop': self.status = 'start' - self.run = True + self.run = True + + elif self.status == 'break': + self.run = True + + elif self.status == 'start': + if self.run: + self.status = 'pause' + self.run = False + else: + self.run = True + + elif self.status == 'pause': + self.status = 'start' + self.run = True elif event['button'] == 2: self.__setup('stop') -- cgit v1.3 From 74c855d59f8aacc0b67261d2e5b7ac7402877360 Mon Sep 17 00:00:00 2001 From: rixx Date: Thu, 19 Mar 2015 15:25:02 +0100 Subject: added click-documentation --- py3status/modules/pomodoro.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/py3status/modules/pomodoro.py b/py3status/modules/pomodoro.py index bf86e96..7fcecba 100644 --- a/py3status/modules/pomodoro.py +++ b/py3status/modules/pomodoro.py @@ -22,7 +22,12 @@ class Py3status: def on_click(self, i3s_output_list, i3s_config, event): """ - Handles click events + Handles click events: + - left click starts an inactive counter and pauses a running + Pomodoro + - middle click resets everything + - right click starts (and ends, if needed) a break + """ if event['button'] == 1: if self.status == 'stop': -- cgit v1.3 From 7e7155b993413f462cc7a4970d84e77cb6d8dd8b Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Fri, 20 Mar 2015 12:28:53 +0100 Subject: new xrandr module to handle your screens layout from your bar --- py3status/modules/xrandr.py | 387 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 py3status/modules/xrandr.py diff --git a/py3status/modules/xrandr.py b/py3status/modules/xrandr.py new file mode 100644 index 0000000..2d3e757 --- /dev/null +++ b/py3status/modules/xrandr.py @@ -0,0 +1,387 @@ +# -*- coding: utf-8 -*- +""" +This modules allows you to handle your screens outputs directly from your bar! + - Detect and propose every possible screen combinations + - Switch between combinations using click events and mouse scroll + - Activate the screen or screen combination on a single click + - It will detect any newly connected or removed screen automatically + +For convenience, this module also proposes some added features: + - Dynamic parameters for POSITION and WORKSPACES assignment (see below) + - Automatic fallback to a given screen or screen combination when no more + screen is available (handy for laptops) + - Automatically apply this screen combination on start: no need for xorg! + - Automatically move workspaces to screens when they are available + +Example config: + xrandr { + force_on_start = "eDP1+DP1" + DP1_pos = "left-of eDP1" + VGA_workspaces = "7" + } + +@author ultrabug +""" +import shlex + +from collections import deque +from collections import OrderedDict +from itertools import combinations +from subprocess import call, Popen, PIPE +from syslog import syslog, LOG_INFO +from time import sleep, time + + +class Py3status: + """ + Configuration parameters: + - cache_timeout: how often to (re)detect the outputs + - fallback: when the current output layout is not available anymore, + fallback to this layout if available. This is very handy if you + have a laptop and switched to an external screen for presentation + and want to automatically fallback to your laptop screen when you + disconnect the external screen. + - force_on_start: switch to the given combination mode if available + when the module starts (saves you from having to configure xorg) + - format_clone: string used to display a 'clone' combination + - format_extend: string used to display a 'extend' combination + + Dynamic configuration parameters: + - _pos: apply the given position to the OUTPUT + Example: DP1_pos = "-2560x0" + Example: DP1_pos = "left-of LVDS1" + Example: DP1_pos = "right-of eDP1" + + - _workspaces: comma separated list of workspaces to move to + the given OUTPUT when it is activated + Example: DP1_workspaces = "1,2,3" + """ + # available configuration parameters + cache_timeout = 10 + fallback = True + fixed_width = True + force_on_start = None + format_clone = '=' + format_extend = '+' + + def __init__(self): + """ + """ + self.active_comb = None + self.active_layout = None + self.active_mode = 'extend' + self.displayed = None + self.max_width = 0 + + def _get_layout(self): + """ + Get the current outputs layout from xrandr and try to detect the + currently active layout as best as we can on start. + """ + connected = list() + active_layout = list() + disconnected = list() + layout = OrderedDict( + { + 'connected': OrderedDict(), + 'disconnected': OrderedDict() + } + ) + + current = Popen(['xrandr', '--current'], stdout=PIPE) + for line in current.stdout.readlines(): + try: + # python3 + line = line.decode() + except: + pass + try: + s = line.split(' ') + if s[1] == 'connected': + output, state = s[0], s[1] + if s[2][0] == '(': + mode, infos = None, ' '.join(s[2:]).strip('\n') + else: + mode, infos = s[2], ' '.join(s[3:]).strip('\n') + active_layout.append(output) + connected.append(output) + elif s[1] == 'disconnected': + output, state = s[0], s[1] + mode, infos = None, ' '.join(s[2:]).strip('\n') + disconnected.append(output) + else: + continue + except Exception as err: + syslog(LOG_INFO, 'xrandr error="{}"'.format(err)) + else: + layout[state][output] = { + 'infos': infos, + 'mode': mode, + 'state': state + } + + # initialize the active layout + if self.active_layout is None: + self.active_comb = tuple(active_layout) + self.active_layout = self._get_string_and_set_width( + tuple(active_layout), + self.active_mode + ) + + return layout + + def _set_available_combinations(self): + """ + Generate all connected outputs combinations and + set the max display width while iterating. + """ + available_combinations = set() + combinations_map = {} + + self.max_width = 0 + for output in range(len(self.layout['connected'])+1): + for comb in combinations(self.layout['connected'], output): + if comb: + for mode in ['clone', 'extend']: + string = self._get_string_and_set_width(comb, mode) + if len(comb) == 1: + combinations_map[string] = (comb, None) + else: + combinations_map[string] = (comb, mode) + available_combinations.add(string) + self.available_combinations = deque(available_combinations) + self.combinations_map = combinations_map + + def _get_string_and_set_width(self, combination, mode): + """ + Construct the string to be displayed and record the max width. + """ + show = '{}'.format(self._separator(mode)).join(combination) + show = show.rstrip('{}'.format(self._separator(mode))) + self.max_width = max([self.max_width, len(show)]) + return show + + def _choose_what_to_display(self, force_refresh=False): + """ + Choose what combination to display on the bar. + + By default we try to display the active layout on the first run, else + we display the last selected combination. + """ + for _ in range(len(self.available_combinations)): + if ( + self.displayed is None and + self.available_combinations[0] == self.active_layout + ): + self.displayed = self.available_combinations[0] + break + else: + if self.displayed == self.available_combinations[0]: + break + else: + self.available_combinations.rotate(1) + else: + if force_refresh: + self.displayed = self.available_combinations[0] + else: + syslog( + LOG_INFO, + 'xrandr error="displayed combination is not available"' + ) + + def _center(self, s): + """ + Center the given string on the detected max width. + """ + fmt = '{:^%d}' % self.max_width + return fmt.format(s) + + def _apply(self, force=False): + """ + Call xrandr and apply the selected (displayed) combination mode. + """ + if self.displayed == self.active_layout and not force: + # no change, do nothing + return + + combination, mode = self.combinations_map.get( + self.displayed, (None, None) + ) + if combination is None and mode is None: + # displayed combination cannot be activated, ignore + return + + cmd = 'xrandr' + outputs = list(self.layout['connected'].keys()) + outputs += list(self.layout['disconnected'].keys()) + previous_output = None + for output in outputs: + cmd += ' --output {}'.format(output) + # + if output in combination: + pos = getattr(self, '{}_pos'.format(output), '0x0') + # + if mode == 'clone' and previous_output is not None: + cmd += ' --auto --same-as {}'.format(previous_output) + else: + if 'left-of' in pos: + cmd += ' --auto --{} --rotate normal'.format(pos) + elif 'right-of' in pos: + cmd += ' --auto --{} --rotate normal'.format(pos) + else: + cmd += ' --auto --pos {} --rotate normal'.format(pos) + previous_output = output + else: + cmd += ' --off' + # + code = call(shlex.split(cmd)) + if code == 0: + self.active_comb = combination + self.active_layout = self.displayed + self.active_mode = mode + syslog(LOG_INFO, 'command "{}" exit code {}'.format(cmd, code)) + + # move workspaces to outputs as configured + self._apply_workspaces(combination, mode) + + def _apply_workspaces(self, combination, mode): + """ + Allows user to force move a comma separated list of workspaces to the + given output when it's activated. + + Example: + - DP1_workspaces = "1,2,3" + """ + if len(combination) > 1 and mode == 'extend': + sleep(3) + for output in combination: + workspaces = getattr( + self, '{}_workspaces'.format(output), '').split(',') + for workspace in workspaces: + if not workspace: + continue + # switch to workspace + cmd = 'i3-msg workspace "{}"'.format(workspace) + call(shlex.split(cmd), stdout=PIPE, stderr=PIPE) + # move it to output + cmd = 'i3-msg move workspace to output "{}"'.format(output) + call(shlex.split(cmd), stdout=PIPE, stderr=PIPE) + # log this + syslog( + LOG_INFO, + 'moved workspace {} to output {}'.format( + workspace, output) + ) + + def _refresh_py3status(self): + """ + Send a SIGUSR1 signal to py3status to force a bar refresh. + """ + call(shlex.split('killall -s USR1 py3status')) + + def _fallback_to_available_output(self): + """ + Fallback to the first available output when the active layout + was composed of only one output. + + This allows us to avoid cases where you get stuck with a black sreen + on your laptop by switching back to the integrated screen + automatically ! + """ + if len(self.active_comb) == 1: + self._choose_what_to_display(force_refresh=True) + self._apply() + self._refresh_py3status() + + def _force_force_on_start(self): + """ + Force the user configured mode on start. + """ + if self.force_on_start in self.available_combinations: + self.displayed = self.force_on_start + self.force_on_start = None + self._choose_what_to_display(force_refresh=True) + self._apply(force=True) + self._refresh_py3status() + + def _separator(self, mode): + """ + Return the separator for the given mode. + """ + if mode == 'extend': + return self.format_extend + if mode == 'clone': + return self.format_clone + + def _switch_selection(self, direction): + self.available_combinations.rotate(direction) + self.displayed = self.available_combinations[0] + + def on_click(self, i3s_output_list, i3s_config, event): + """ + Click events + - left click & scroll up/down: switch between modes + - right click: apply selected mode + - middle click: force refresh of available modes + """ + button = event['button'] + if button == 4: + self._switch_selection(-1) + if button in [1, 5]: + self._switch_selection(1) + if button == 2: + self._choose_what_to_display(force_refresh=True) + if button == 3: + self._apply() + + def xrandr(self, i3s_output_list, i3s_config): + """ + This is the main py3status method, it will orchestrate what's being + displayed on the bar. + """ + self.layout = self._get_layout() + self._set_available_combinations() + self._choose_what_to_display() + + if self.fixed_width is True: + full_text = self._center(self.displayed) + else: + full_text = self.displayed + + response = { + 'cached_until': time() + self.cache_timeout, + 'full_text': full_text + } + + # coloration + if self.displayed == self.active_layout: + response['color'] = i3s_config['color_good'] + elif self.displayed not in self.available_combinations: + response['color'] = i3s_config['color_bad'] + + # force default layout setup + if self.force_on_start is not None: + sleep(1) + self._force_force_on_start() + + # fallback detection + if self.active_layout not in self.available_combinations: + response['color'] = i3s_config['color_degraded'] + if self.fallback is True: + self._fallback_to_available_output() + + return response + +if __name__ == "__main__": + """ + Test this module by calling it directly. + """ + x = Py3status() + config = { + 'color_bad': '#FF0000', + 'color_degraded': '#FFFF00', + 'color_good': '#00FF00' + } + while True: + print(x.xrandr([], config)) + sleep(1) -- cgit v1.3 From 820e0731ba350a84a67140aa60bc07556d0af105 Mon Sep 17 00:00:00 2001 From: Ultrabug Date: Fri, 20 Mar 2015 17:08:35 +0100 Subject: imap module restore original new_mail_color to color_good --- py3status/modules/imap.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/py3status/modules/imap.py b/py3status/modules/imap.py index 757d9fd..ff53f02 100644 --- a/py3status/modules/imap.py +++ b/py3status/modules/imap.py @@ -1,7 +1,7 @@ # -*- coding: utf8 -*- """ Module displaying the number of unread messages -on an IMAP inbox (configurable, may also be a +on an IMAP inbox (configurable, may also be a comma-separated list of IMAP folders). @author obb @@ -33,7 +33,7 @@ class Py3status: } if not self.new_mail_color: - self.new_mail_color = i3s_config['color_bad'] + self.new_mail_color = i3s_config['color_good'] if mail_count == 'N/A': response['color'] = '' @@ -56,7 +56,7 @@ class Py3status: directories = self.mailbox.split(',') connection = imaplib.IMAP4_SSL(self.imap_server, self.port) connection.login(self.user, self.password) - + for directory in directories: connection.select(directory) unseen_response = connection.search(None, self.criterion) -- cgit v1.3