group: calculate remaining times to cycle more accurately
@@ -119,6 +119,7 @@ class Py3status:
if not self.items:
raise Exception(STRING_ERROR)
+ self.first_run = True
self.active = 0
self.cycle_time = time() + self.cycle
self.cycle_timeout = self.cycle
@@ -188,45 +189,52 @@ class Py3status:
return current
def _change_active(self, delta):
- # we want to ignore any empty outputs
- # to prevent endless cycling we limit ourselves to only going through
- # the outputs once.
+ # we want to skip empty outputs. to prevent endless cycling,
+ # we limit ourselves to only going through the outputs once.
self.active = (self.active + delta) % len(self.items)
if not self._get_output() and self.last_active != self.active:
self._change_active(delta)
self.last_active = self.active
- def group(self):
- update_time = None
- self.cycle = 0
-
+ def _get_output_and_time(self):
# get an output. again if empty (twice).
for x in range(3):
output = self._get_output()
if output:
+ update_time = None
break
+ elif not self.first_run:
self._change_active(1)
else:
update_time = MAX_NO_CONTENT_WAIT
+ return output, update_time
+
+ def group(self):
+ output, update_time = self._get_output_and_time()
+
# check for urgents
urgent = output and output[0].get("urgent")
self.urgent_history[self.active] = urgent
mod_urgent = any(self.urgent_history.values())
# keep cycling if defined and no urgent
- if self.cycle_timeout and not urgent:
- self.cycle = self.cycle_timeout
- if time() >= self.cycle_time:
+ self.cycle = 0
+ if self.first_run:
+ self.first_run = False
+ update_time = 1
+ elif self.cycle_timeout and not urgent:
+ current_time = time()
+ if current_time >= self.cycle_time - 0.1:
self._change_active(1)
- self.cycle_time = time() + self.cycle
+ output, update_time = self._get_output_and_time()
+ self.cycle = self.cycle_timeout
+ self.cycle_time = current_time + self.cycle
+ else:
+ self.cycle = self.cycle_time - current_time
# time
- update_time = update_time or self.cycle or None
- if update_time is not None:
- cached_until = self.py3.time_in(self.cycle)
- else:
- cached_until = self.py3.CACHE_FOREVER
+ cached_until = update_time or self.cycle or self.py3.CACHE_FOREVER
if self.open:
format_control = self.format_button_open
@@ -239,7 +247,7 @@ class Py3status:
button = {"full_text": format_control, "index": "button"}
response = {
- "cached_until": cached_until,
+ "cached_until": self.py3.time_in(cached_until),
"full_text": self.py3.safe_format(
current_format,
{
