Merge pull request #57 from radek-sprta/master

Use local time representation
This commit is contained in:
Gobinath 2017-02-07 10:17:10 -05:00 committed by GitHub
commit 812914c3a7
10 changed files with 104 additions and 118 deletions

View File

@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import gi
import locale
import logging
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
@ -27,116 +28,119 @@ from gi.repository import AppIndicator3 as appindicator
active = True
APPINDICATOR_ID = 'safeeyes'
class TrayIcon:
def __init__(self, language, on_show_settings, on_show_about, on_enable, on_disable, on_quite):
logging.info("Initialize the tray icon")
self.on_show_settings = on_show_settings
self.on_show_about = on_show_about
self.on_quite = on_quite
self.on_enable = on_enable
self.on_disable = on_disable
self.language = language
self.dateTime = None
# Construct the tray icon
self.indicator = appindicator.Indicator.new(APPINDICATOR_ID, "safeeyes_enabled", appindicator.IndicatorCategory.APPLICATION_STATUS)
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
def __init__(self, language, on_show_settings, on_show_about, on_enable, on_disable, on_quite):
logging.info("Initialize the tray icon")
self.on_show_settings = on_show_settings
self.on_show_about = on_show_about
self.on_quite = on_quite
self.on_enable = on_enable
self.on_disable = on_disable
self.language = language
self.dateTime = None
# Construct the context menu
self.menu = Gtk.Menu()
# Construct the tray icon
self.indicator = appindicator.Indicator.new(
APPINDICATOR_ID, "safeeyes_enabled", appindicator.IndicatorCategory.APPLICATION_STATUS)
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
# Next break info menu item
self.item_info = Gtk.ImageMenuItem()
img_timer = Gtk.Image()
img_timer.set_from_icon_name("safeeyes_timer", 16)
self.item_info.set_image(img_timer)
# Construct the context menu
self.menu = Gtk.Menu()
self.item_separator = Gtk.SeparatorMenuItem()
# Next break info menu item
self.item_info = Gtk.ImageMenuItem()
img_timer = Gtk.Image()
img_timer.set_from_icon_name("safeeyes_timer", 16)
self.item_info.set_image(img_timer)
# Enable menu item with check box
self.item_enable = Gtk.CheckMenuItem()
self.item_enable.set_active(True)
self.item_enable.connect('activate', self.on_toogle_enable)
self.item_separator = Gtk.SeparatorMenuItem()
# Settings menu item
self.item_settings = Gtk.MenuItem()
self.item_settings.connect('activate', self.show_settings)
# Enable menu item with check box
self.item_enable = Gtk.CheckMenuItem()
self.item_enable.set_active(True)
self.item_enable.connect('activate', self.on_toogle_enable)
# About menu item
self.item_about = Gtk.MenuItem()
self.item_about.connect('activate', self.show_about)
# Settings menu item
self.item_settings = Gtk.MenuItem()
self.item_settings.connect('activate', self.show_settings)
# Quit menu item
self.item_quit = Gtk.MenuItem()
self.item_quit.connect('activate', self.quit_safe_eyes)
# About menu item
self.item_about = Gtk.MenuItem()
self.item_about.connect('activate', self.show_about)
self.set_labels(language)
# Quit menu item
self.item_quit = Gtk.MenuItem()
self.item_quit.connect('activate', self.quit_safe_eyes)
# Append all menu items and show the menu
self.menu.append(self.item_info)
self.menu.append(self.item_separator)
self.menu.append(self.item_enable)
self.menu.append(self.item_settings)
self.menu.append(self.item_about)
self.menu.append(self.item_quit)
self.menu.show_all()
self.set_labels(language)
self.indicator.set_menu(self.menu)
# Append all menu items and show the menu
self.menu.append(self.item_info)
self.menu.append(self.item_separator)
self.menu.append(self.item_enable)
self.menu.append(self.item_settings)
self.menu.append(self.item_about)
self.menu.append(self.item_quit)
self.menu.show_all()
def set_labels(self, language):
self.language = language
active = self.item_enable.get_active()
if active:
if self.dateTime:
self.set_next_break_info(self.dateTime)
else:
self.item_info.set_label(self.language['messages']['safe_eyes_is_disabled'])
self.item_enable.set_label(self.language['ui_controls']['enable'])
self.item_settings.set_label(self.language['ui_controls']['settings'])
self.item_about.set_label(self.language['ui_controls']['about'])
self.item_quit.set_label(self.language['ui_controls']['quit'])
self.indicator.set_menu(self.menu)
def show_icon(self):
GLib.idle_add(lambda: self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE))
def set_labels(self, language):
self.language = language
active = self.item_enable.get_active()
if active:
if self.dateTime:
self.set_next_break_info(self.dateTime)
else:
self.item_info.set_label(self.language['messages'][
'safe_eyes_is_disabled'])
self.item_enable.set_label(self.language['ui_controls']['enable'])
self.item_settings.set_label(self.language['ui_controls']['settings'])
self.item_about.set_label(self.language['ui_controls']['about'])
self.item_quit.set_label(self.language['ui_controls']['quit'])
def hide_icon(self):
GLib.idle_add(lambda: self.indicator.set_status(appindicator.IndicatorStatus.PASSIVE))
def show_icon(self):
GLib.idle_add(lambda: self.indicator.set_status(
appindicator.IndicatorStatus.ACTIVE))
def quit_safe_eyes(self, *args):
self.on_quite()
def hide_icon(self):
GLib.idle_add(lambda: self.indicator.set_status(
appindicator.IndicatorStatus.PASSIVE))
def show_settings(self, *args):
self.on_show_settings()
def quit_safe_eyes(self, *args):
self.on_quite()
def show_about(self, *args):
self.on_show_about()
def show_settings(self, *args):
self.on_show_settings()
def next_break_time(self, dateTime):
logging.info("Update next break information")
self.dateTime = dateTime
self.set_next_break_info(self.dateTime)
def show_about(self, *args):
self.on_show_about()
def set_next_break_info(self, dateTime):
formatted_time = dateTime.strftime("%l:%M")
if dateTime.hour == 12:
message = self.language['messages']['next_break_at_noon'].format(formatted_time)
elif dateTime.hour < 12:
message = self.language['messages']['next_break_at_am'].format(formatted_time)
else:
message = self.language['messages']['next_break_at_pm'].format(formatted_time)
def next_break_time(self, dateTime):
logging.info("Update next break information")
self.dateTime = dateTime
self.set_next_break_info(self.dateTime)
GLib.idle_add(lambda: self.item_info.set_label(message))
def set_next_break_info(self, dateTime):
formatted_time = dateTime.strftime(locale.nl_langinfo(locale.T_FMT))
message = self.language['messages'][
'next_break_at'].format(formatted_time)
def on_toogle_enable(self, *args):
active = self.item_enable.get_active()
if active:
logging.info("Enable Safe Eyes")
self.indicator.set_icon("safeeyes_enabled")
self.item_info.set_sensitive(True)
self.on_enable()
else:
logging.info("Disable Safe Eyes")
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()
GLib.idle_add(lambda: self.item_info.set_label(message))
def on_toogle_enable(self, *args):
active = self.item_enable.get_active()
if active:
logging.info("Enable Safe Eyes")
self.indicator.set_icon("safeeyes_enabled")
self.item_info.set_sensitive(True)
self.on_enable()
else:
logging.info("Disable Safe Eyes")
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

@ -21,9 +21,7 @@
"messages": {
"ready_for_a_break": "Připravte se na přestávku za {} sekund",
"safe_eyes_is_disabled": "Safe Eyes je zakázáno",
"next_break_at_noon": "Příští přestávka v {}",
"next_break_at_am": "Příští přestávka v {} dopoledne",
"next_break_at_pm": "Příští přestávka v {} odpoledne"
"next_break_at": "Příští přestávka v {}"
},
"ui_controls": {
"skip": "Přeskočit",

View File

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

View File

@ -21,9 +21,7 @@
"messages": {
"ready_for_a_break": "Listo para una pausa en {} segundos",
"safe_eyes_is_disabled": "Safe Eyes está desactivado",
"next_break_at_noon": "Próxima pausa a las {}",
"next_break_at_am": "Próxima pausa a las {} de la mañana",
"next_break_at_pm": "Próxima pausa a las {} de la tarde/noche"
"next_break_at": "Próxima pausa a las {}"
},
"ui_controls": {
"skip": "Cancelar",

View File

@ -20,9 +20,7 @@
"messages": {
"ready_for_a_break": "Prêt pour une pause dans {} secondes",
"safe_eyes_is_disabled": "Safe Eyes est désactivé",
"next_break_at_noon": "Prochaine pause à {}",
"next_break_at_am": "Prochaine pause à {} AM",
"next_break_at_pm": "Prochaine pause à {} PM"
"next_break_at": "Prochaine pause à {}"
},
"ui_controls": {
"skip": "Annuler",

View File

@ -19,9 +19,7 @@
"messages": {
"ready_for_a_break": "Tervezett szünet {} másodperc múlva!",
"safe_eyes_is_disabled": "Safe Eyes kikapcsolva",
"next_break_at_noon": "A következő szünet {}",
"next_break_at_am": "A következő szünet de. {}",
"next_break_at_pm": "A következő szünet du. {}"
"next_break_at": "A következő szünet {}"
},
"ui_controls": {
"skip": "Átugrás",

View File

@ -21,9 +21,7 @@
"messages": {
"ready_for_a_break": "Pronto para uma pausa em {} segundos",
"safe_eyes_is_disabled": "Safe Eyes está desabilitado",
"next_break_at_noon": "Próxima pausa em {}",
"next_break_at_am": "Próxima pausa em {} AM",
"next_break_at_pm": "Próxima pausa em {} PM"
"next_break_at": "Próxima pausa em {}"
},
"ui_controls": {
"skip": "Pular",

View File

@ -21,9 +21,7 @@
"messages": {
"ready_for_a_break": "Приготовьтесь к перерыву через {} секунд",
"safe_eyes_is_disabled": "Safe Eyes отключен",
"next_break_at_noon": "Следующий перерыв в {}",
"next_break_at_am": "Следующий перерыв в {} утра",
"next_break_at_pm": "Следующий перерыв в {} вечера"
"next_break_at": "Следующий перерыв в {}"
},
"ui_controls": {
"skip": "Пропустить",

View File

@ -20,9 +20,7 @@
"messages": {
"ready_for_a_break": "Priprav sa na prestávku o {} sekúnd",
"safe_eyes_is_disabled": "Safe Eyes sú zablokované",
"next_break_at_noon": "Ďalšia prestávka o {}",
"next_break_at_am": "Ďalšia prestávka o {} doobeda",
"next_break_at_pm": "Ďalšia prestávka o {} poobede"
"next_break_at": "Ďalšia prestávka o {}"
},
"ui_controls": {
"skip": "Preskočiť",

View File

@ -21,9 +21,7 @@
"messages": {
"ready_for_a_break": "{} விநாடிகளில் இடைவேளைக்கு தயாராகுங்கள்",
"safe_eyes_is_disabled": "Safe Eyes நிறுத்தி வைக்கப்பட்டுள்ளது",
"next_break_at_noon": "அடுத்த இடைவேளை {}",
"next_break_at_am": "அடுத்த இடைவேளை {} முற்பகல்",
"next_break_at_pm": "அடுத்த இடைவேள {} பிற்பகல்"
"next_break_at": "அடுத்த இடைவேளை {}"
},
"ui_controls": {
"cancel": "ரத்து",