Browse Source

Show the time remaining in the title

master
Raphael Roberts 6 years ago
parent
commit
b7a4320db4
  1. 8
      ctabus/__main__.py
  2. 6
      ctabus/ui/util.py

8
ctabus/__main__.py

@ -15,6 +15,7 @@ import lazy_import
from ctabus import __version__
from ctabus.internal.config import log_dir, recent_list, CHICAGO_TZ
from ctabus.ui.util import space_two
notification_module = lazy_import.lazy_module("ctabus.ui.notification")
toast_module = lazy_import.lazy_module("ctabus.ui.toast")
@ -112,9 +113,10 @@ def show(
before = date_parse(bustime["prdtm"])
arrival = before.replace(tzinfo=CHICAGO_TZ)
if arrival > now:
delta: datetime.timedelta = arrival - now
format_dict = {
"stop_id": bustime["stpid"],
"delta": pprint_delta(arrival - now),
"delta": pprint_delta(delta),
"t": arrival.strftime("%H:%M:%S"),
"route": bustime["rt"],
"direction": bustime["rtdir"],
@ -124,7 +126,9 @@ def show(
text_to_show = text_config.format(**format_dict)
if do_gui and enable_notifications:
notification_module.nm.setup_exiter(EXIT)
notification_module.nm.set_title("{route} - {end}".format(**format_dict))
mins = "{} min".format(delta.total_seconds() // 60)
bus_route = "{route} - {end}".format(**format_dict)
notification_module.nm.set_title(space_two(bus_route, mins, 42))
notification_module.nm.say(notification_config.format(**format_dict))
if do_gui and enable_toast:

6
ctabus/ui/util.py

@ -12,3 +12,9 @@ def numb_sort(text):
(See Toothy's implementation in the comments)
"""
return [atoi(c) for c in re.split(r"(\d+)", text)]
def space_two(item_1, item_2, total_len):
string_1, string_2 = map(str, (item_1, item_2))
n_spaces = max(1, total_len - sum(map(len, (string_1, string_2))))
return "{}{}{}".format(string_1, " " * n_spaces, string_2)
Loading…
Cancel
Save