clock added

This commit is contained in:
Matthias Pronk 2013-02-22 13:59:28 +01:00
parent c72363092d
commit fdadd3f143
2 changed files with 39 additions and 0 deletions

View File

@ -70,5 +70,10 @@ battery = batterychecker.BatteryChecker()
status.register(battery)
# the clock
clock = clock.Clock()
status.register(clock)
# start the handler
status.run()

34
i3pystatus/clock.py Normal file
View File

@ -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"
}