From fdadd3f143c59755e15b8ec11fa9a2b798d65697 Mon Sep 17 00:00:00 2001 From: Matthias Pronk Date: Fri, 22 Feb 2013 13:59:28 +0100 Subject: [PATCH] clock added --- i3pystatus/__main__.py.dist | 5 +++++ i3pystatus/clock.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 i3pystatus/clock.py diff --git a/i3pystatus/__main__.py.dist b/i3pystatus/__main__.py.dist index 9c262c0..1888afe 100755 --- a/i3pystatus/__main__.py.dist +++ b/i3pystatus/__main__.py.dist @@ -70,5 +70,10 @@ battery = batterychecker.BatteryChecker() status.register(battery) +# the clock +clock = clock.Clock() +status.register(clock) + + # start the handler status.run() diff --git a/i3pystatus/clock.py b/i3pystatus/clock.py new file mode 100644 index 0000000..13a3263 --- /dev/null +++ b/i3pystatus/clock.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os, locale, datetime + +from i3pystatus import IntervalModule + +class Clock(IntervalModule): + """ + This class shows a clock + """ + + def __init__(self, format_string=None): + lang = os.environ.get('LANG', None) + if lang: + locale.setlocale(locale.LC_ALL, lang) + if not format_string: + lang = locale.getlocale()[0] + if lang == 'en_US': + # MDY format - United States of America + format_string = "%a %b %-d %X" + else: + # DMY format - almost all other countries + format_string = "%a %-d %b %X" + self.format_string = format_string + + def run(self): + full_text = datetime.datetime.now().strftime(self.format_string) + self.output = { + "full_text": full_text, + "name": "pyclock", + "urgent": False, + "color": "#ffffff" + }