Skip to content

Commit

Permalink
add seetings for menubar
Browse files Browse the repository at this point in the history
  • Loading branch information
esseti committed Aug 4, 2023
1 parent e5a468a commit d87bd5e
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions src/vince.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def __init__(self):
self.load_events()
self.build_menu()

@rumps.timer(60*5)
def timely_load_events(self, _):
self.load_events()


def load_events(self):
# gets all todays' event from calendar
try:
Expand Down Expand Up @@ -237,49 +242,53 @@ def _get_next_events(self):

@rumps.timer(1)
def update_bar_str(self, _):
if self.settings['show_menu_bar']:
# updates the bar
if self.menu_items:
current_datetime = datetime.now(pytz.utc)
current_events = self._get_current_events()
next_events = self._get_next_events()
title = ""
len_current_events = len(current_events)
i_current_events = 0
# first all the current, with time left
for event in current_events:
hours, minutes, seconds = self._time_left(
event['end'], current_datetime, True)
title += f" {str_truncate(event['summary'],20)}: {hours:02d}:{minutes:02d}:{seconds:02d} left"
i_current_events += 1
# separated with comma if more than one
if i_current_events < len_current_events:
title += ", "
if current_events != self.current_events:
if not current_events:
self.slack_meeting(None)
else:
event = sorted(current_events, key=lambda x: x["end"])[0]
self.slack_meeting(event)

self.current_events = current_events
# get the shortest one and update with taht data
len_next_events = len(next_events)
i_next_events = 0
# and upcoming with thime left before the start
if len_next_events:
title += " ["
for event in next_events:
hours, minutes = self._time_left(
event['start'], current_datetime)
title += f"{str_truncate(event['summary'],20)}: in {hours:02d}:{minutes:02d}"
i_next_events += 1
if i_next_events < len_next_events:
title += ", "
if len_next_events:
title += "]"
self.title = title
if self.menu_items:
current_datetime = datetime.now(pytz.utc)
current_events = self._get_current_events()
next_events = self._get_next_events()
title = ""
len_current_events = len(current_events)
i_current_events = 0
# first all the current, with time left
for event in current_events:
hours, minutes, seconds = self._time_left(
event['end'], current_datetime, True)
title += f" {str_truncate(event['summary'],20)}: {hours:02d}:{minutes:02d}:{seconds:02d} left"
i_current_events += 1
# separated with comma if more than one
if i_current_events < len_current_events:
title += ", "
if current_events != self.current_events:
if not current_events:
self.slack_meeting(None)
else:
event = sorted(current_events, key=lambda x: x["end"])[0]
self.slack_meeting(event)

self.current_events = current_events
# get the shortest one and update with taht data
len_next_events = len(next_events)
i_next_events = 0
# and upcoming with thime left before the start
if len_next_events:
title += " ["
for event in next_events:
hours, minutes = self._time_left(
event['start'], current_datetime)
title += f"{str_truncate(event['summary'],20)}: in {hours:02d}:{minutes:02d}"
i_next_events += 1
if i_next_events < len_next_events:
title += ", "
if len_next_events:
title += "]"
self.title = title
else:
self.title = f""
else:
self.title = f"-"
self.title = f""


def _str_event_menu_current(self, element):
# create the items in the menu. util function
Expand Down Expand Up @@ -427,6 +436,7 @@ def load_settings(self):
settings_path = os.path.join(data_dir, "settings.json")
default_settings = {
"link_opening_enabled": True,
"show_menu_bar": True,
"notification_enabled": True,
"notification_time_left":[5],
"slack_status_enabled": False,
Expand Down

0 comments on commit d87bd5e

Please sign in to comment.