From 73c7e740578d00ed52b4b9d0b09b72cd9d46e247 Mon Sep 17 00:00:00 2001 From: Gobinath Date: Wed, 8 Feb 2017 21:39:27 -0500 Subject: [PATCH] Short format time using locale --- README.md | 6 +++--- safeeyes/debian/control | 2 +- safeeyes/safeeyes/Utility.py | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a47801c..8d0e933 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,11 @@ Manual installation is not tested in any systems. I will update this page as soo 1: Install the dependencies: - * Arch: `hicolor-icon-theme`, `libappindicator-gtk3`, `xorg-xprop`, `python2-xlib`, `python2-gobject`, `python2-dbus`, `xprintidle` and `mpg123` + * Arch: `hicolor-icon-theme`, `libappindicator-gtk3`, `xorg-xprop`, `python2-xlib`, `python2-gobject`, `python2-dbus`, `python2-babel`, `xprintidle` and `mpg123` - * Debian: `gir1.2-appindicator3-0.1`, `python-xlib`, `python-gobject`, `python-gi`, `python-dbus`, `gir1.2-notify-0.7`, `python-gtk2`, `xprintidle` and `mpg123` + * Debian: `gir1.2-appindicator3-0.1`, `python-xlib`, `python-gobject`, `python-gi`, `python-dbus`, `gir1.2-notify-0.7`, `python-gtk2`, `python-babel`, `xprintidle` and `mpg123` - * Fedora 24: `libappindicator-gtk3`, `python-xlib`, `python-gobject`, `xorg-x11-utils`, `python-dbus`, `xprintidle` and `mpg123` + * Fedora 24: `libappindicator-gtk3`, `python-xlib`, `python-gobject`, `xorg-x11-utils`, `python-dbus`, `python-babel`, `xprintidle` and `mpg123` 2: Download and extract [safeeyes.tar.gz](https://github.com/slgobinath/SafeEyes/releases/download/v1.1.4/safeeyes.tar.gz) into `/`: `sudo tar -xzvf safeeyes.tar.gz -C /` diff --git a/safeeyes/debian/control b/safeeyes/debian/control index faa1a45..f1bbf60 100644 --- a/safeeyes/debian/control +++ b/safeeyes/debian/control @@ -8,7 +8,7 @@ Homepage: https://github.com/slgobinath/SafeEyes/ Package: safeeyes Architecture: any -Depends: gir1.2-appindicator3-0.1, python (>= 2.7.0), python-xlib, python-gi, python-dbus, gir1.2-notify-0.7, python-gtk2, xprintidle, mpg123 +Depends: gir1.2-appindicator3-0.1, python (>= 2.7.0), python-xlib, python-gi, python-dbus, gir1.2-notify-0.7, python-gtk2, python-babel, xprintidle, mpg123 Description: Safe Eyes Safe Eyes is a simple tool to remind you to take periodic breaks for your eyes. This is essential for anyone spending more time on the computer to avoid eye strain and other physical problems. . diff --git a/safeeyes/safeeyes/Utility.py b/safeeyes/safeeyes/Utility.py index f8bed6b..f88a43d 100644 --- a/safeeyes/safeeyes/Utility.py +++ b/safeeyes/safeeyes/Utility.py @@ -19,7 +19,7 @@ import gi gi.require_version('Gdk', '3.0') from gi.repository import Gdk, GLib -import os, subprocess, threading, logging +import babel.dates, os, subprocess, threading, logging, locale """ Play the alert.mp3 @@ -45,8 +45,8 @@ def system_idle_time(): """ Execute the function in a separate thread. """ -def start_thread(target_function): - thread = threading.Thread(target=target_function) +def start_thread(target_function, args=None): + thread = threading.Thread(target=target_function, kwargs=args) thread.start() @@ -58,7 +58,7 @@ def execute_main_thread(target_function): """ - Check for full-screen applications + Check for full-screen applications. """ def is_full_screen_app_found(): logging.info("Searching for full-screen application") @@ -74,3 +74,13 @@ def is_full_screen_app_found(): else: if stdout: return 'FULLSCREEN' in stdout + + +""" + Format time based on the system time. +""" +def format_time(time): + system_locale = locale.setlocale(locale.LC_ALL, '') + if not system_locale: + system_locale = 'en_US.UTF-8' + return babel.dates.format_time(time, format='short', locale=system_locale)