Add information about next break to tray menu

This commit is contained in:
Gobinath 2016-11-04 15:57:47 +05:30
parent de47d8e638
commit 223d4b029c
6 changed files with 39 additions and 9 deletions

View File

@ -19,11 +19,11 @@
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk, Gio, GLib, GdkX11
import time, threading, sys, subprocess
import time, datetime,threading, sys, subprocess
class SafeEyesCore:
def __init__(self, show_notification, start_break, end_break, on_countdown):
def __init__(self, show_notification, start_break, end_break, on_countdown, update_next_break_info):
# Initialize the variables
self.break_count = 0
self.long_break_message_index = -1
@ -33,6 +33,7 @@ class SafeEyesCore:
self.start_break = start_break
self.end_break = end_break
self.on_countdown = on_countdown
self.update_next_break_info = update_next_break_info
self.notification_condition = threading.Condition()
self.break_condition = threading.Condition()
@ -55,6 +56,9 @@ class SafeEyesCore:
if not self.active:
return
next_break_time = datetime.datetime.now() + datetime.timedelta(minutes=self.break_interval)
self.update_next_break_info(next_break_time)
# Wait for the pre break warning period
self.notification_condition.acquire()
self.notification_condition.wait(self.break_interval * 60) # In minutes

View File

@ -32,6 +32,7 @@ class TrayIcon:
self.on_quite = on_quite
self.on_enable = on_enable
self.on_disable = on_disable
self.language = language
# Construct the tray icon
self.indicator = appindicator.Indicator.new(APPINDICATOR_ID, "safeeyes_enabled", appindicator.IndicatorCategory.APPLICATION_STATUS)
@ -40,16 +41,26 @@ class TrayIcon:
# Construct the context menu
self.menu = Gtk.Menu()
self.item_enable = Gtk.CheckMenuItem(language['ui_controls']['enable'])
self.item_info = Gtk.ImageMenuItem('Next break at 10.30 AM')
img_timer = Gtk.Image()
img_timer.set_from_icon_name("safeeyes_timer", 16)
self.item_info.set_image(img_timer)
self.item_separator = Gtk.SeparatorMenuItem()
self.item_enable = Gtk.CheckMenuItem(self.language['ui_controls']['enable'])
self.item_enable.set_active(True)
self.item_enable.connect('activate', self.on_toogle_enable)
item_settings = Gtk.MenuItem(language['ui_controls']['settings'])
item_settings = Gtk.MenuItem(self.language['ui_controls']['settings'])
item_settings.connect('activate', self.show_settings)
item_quit = Gtk.MenuItem(language['ui_controls']['quit'])
item_quit = Gtk.MenuItem(self.language['ui_controls']['quit'])
item_quit.connect('activate', self.quit_safe_eyes)
self.menu.append(self.item_info)
self.menu.append(self.item_separator)
self.menu.append(self.item_enable)
self.menu.append(item_settings)
self.menu.append(item_quit)
@ -69,11 +80,23 @@ class TrayIcon:
def show_settings(self, *args):
self.on_show_settings()
def next_break_time(self, dateTime):
timeStr = dateTime.strftime("%l:%M")
if dateTime.hour < 12:
message = self.language['messages']['next_break_at_am'].format(timeStr)
else:
message = self.language['messages']['next_break_at_pm'].format(timeStr)
GLib.idle_add(lambda: self.item_info.set_label(message))
def on_toogle_enable(self, *args):
active = self.item_enable.get_active()
if active:
self.indicator.set_icon("safeeyes_enabled")
self.item_info.set_sensitive(True)
self.on_enable()
else:
self.indicator.set_icon("safeeyes_disabled")
self.item_info.set_label(self.language['messages']['safe_eyes_is_disabled'])
self.item_info.set_sensitive(False)
self.on_disable()

View File

@ -18,7 +18,10 @@
]
},
"messages": {
"ready_for_a_break": "Ready for a break in {} seconds"
"ready_for_a_break": "Ready for a break in {} seconds",
"safe_eyes_is_disabled": "Safe Eyes is disabled",
"next_break_at_am": "Next break at {} AM",
"next_break_at_pm": "Next break at {} PM"
},
"ui_controls": {
"skip": "Skip",

View File

@ -108,8 +108,8 @@ def save_settings(config):
json.dump(config, config_file, indent=4, sort_keys=True)
# Restart the core and intialize the components
core.initialize(config)
break_screen.initialize(config)
core.initialize(config, language)
break_screen.initialize(config, language)
def enable_safeeyes():
is_active = True
@ -171,7 +171,7 @@ def main():
tray_icon = TrayIcon(language, show_settings, enable_safeeyes, disable_safeeyes, on_quite)
break_screen = BreakScreen(on_skipped, break_screen_glade, style_sheet_path)
break_screen.initialize(config, language)
core = SafeEyesCore(show_notification, show_alert, close_alert, on_countdown)
core = SafeEyesCore(show_notification, show_alert, close_alert, on_countdown, tray_icon.next_break_time)
core.initialize(config, language)
core.start()
notification = Notification(language)

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B