aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--DEPENDENCIES1
-rw-r--r--Makefile4
-rw-r--r--TODO1
-rw-r--r--dist/archlinux/stable/PKGBUILD3
-rw-r--r--examples/plugins/tzclock33
-rw-r--r--src/plugins/tzclock.py102
6 files changed, 140 insertions, 4 deletions
diff --git a/DEPENDENCIES b/DEPENDENCIES
index fb51285..7b43bbb 100644
--- a/DEPENDENCIES
+++ b/DEPENDENCIES
@@ -12,6 +12,7 @@ OPTIONAL RUNTIME DEPENDENCIES:
wget: for Internet services
python-pyalsaaudio: for ALSA volume control
hdparm: for hdparm support
+ python-pytz: for timezone support
BUILD DEPENDENCIES:
diff --git a/Makefile b/Makefile
index b16197c..2422e4f 100644
--- a/Makefile
+++ b/Makefile
@@ -32,12 +32,12 @@ PLUGINS = chase clock cpuinfo cpuonline cpu df discstats ipaddress \
kmsg leapsec linereader loadavg lunar mem moc network \
pacman snmp snmp6 softirqs solar uname uptime users \
vmstat weather xdisplay xkb alsa dentrystate inodestate \
- files hdparm
+ files hdparm tzclock
PLUGIN_EXAMPLES = chase clock cpu cpuinfo cpuonline df discstats \
ipaddress kmsg loadavg lunar mem moc network \
pacman uname uptime users xdisplay xkb alsa \
- dentrystate inodestate files
+ dentrystate inodestate files tzclock
EXAMPLES = mixed moderate test xmonad
diff --git a/TODO b/TODO
index 47f74c1..fcf72c9 100644
--- a/TODO
+++ b/TODO
@@ -25,7 +25,6 @@ List of plugins to implement:
e-mail
Identify active and visible windows
Calendars: holidays, birthdays, name days, events
- Clock plugin with timezone support
Summer time / standard time announcement (should support double
summer time and similar)
natural disaster reports
diff --git a/dist/archlinux/stable/PKGBUILD b/dist/archlinux/stable/PKGBUILD
index 7ca3060..bd1b1d6 100644
--- a/dist/archlinux/stable/PKGBUILD
+++ b/dist/archlinux/stable/PKGBUILD
@@ -11,7 +11,8 @@ depends=(python3 argparser python3-xlib xorg-xrandr)
optdepends=("linux: most of the monitors require Linux's procfs or sysfs"
"wget: for Internet services"
"python-pyalsaaudio: for ALSA volume control"
- "hdparm: hdparm: for hdparm support")
+ "hdparm: hdparm: for hdparm support"
+ "python-pytz: for timezone support")
makedepends=(make coreutils sed zip)
source=($url/archive/$pkgver.tar.gz)
sha256sums=(af97eafabdffb593d6ea3ee87fd2bb70d5b105201314d20ed9abb1741a7b29b7)
diff --git a/examples/plugins/tzclock b/examples/plugins/tzclock
new file mode 100644
index 0000000..e4d4911
--- /dev/null
+++ b/examples/plugins/tzclock
@@ -0,0 +1,33 @@
+# -*- python -*-
+
+# A xpybar configuration example testing the features of plugins.tzclock
+
+from plugins.tzclock import TZClock
+
+
+OUTPUT, HEIGHT, YPOS, TOP = 0, 12, 24, True
+
+
+pacific = TZClock(timezone = 'US/Pacific', format = '%T %Z')
+central = TZClock(timezone = 'US/Central', format = '%T %Z')
+utc = TZClock(timezone = 'UTC', format = '%T %Z', sync_to = TZClock.SECONDS)
+sthlm = TZClock(timezone = 'Europe/Stockholm', format = '%T %Z')
+kalinin = TZClock(timezone = 'Europe/Kaliningrad', format = '%T %Z')
+tokyo = TZClock(timezone = 'Asia/Tokyo', format = '%T %Z')
+
+
+timezones = [pacific, central, utc, sthlm, kalinin, tokyo]
+
+
+start_ = start
+def start():
+ start_()
+ async(lambda : utc.continuous_sync(lambda : bar.invalidate()))
+
+
+def redraw():
+ time = TZClock.posix_time()
+ text = ' │ '.join([tz.from_posix_time(time) for tz in timezones])
+ bar.clear()
+ bar.draw_coloured_text(0, 10, 0, 2, text)
+
diff --git a/src/plugins/tzclock.py b/src/plugins/tzclock.py
new file mode 100644
index 0000000..07599f7
--- /dev/null
+++ b/src/plugins/tzclock.py
@@ -0,0 +1,102 @@
+# -*- python -*-
+'''
+xpybar – xmobar replacement written in python
+Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+'''
+
+from datetime import datetime
+from pytz import timezone as tz
+import time
+
+
+class TZClock:
+ '''
+ Date and time information retrieval with timezone support
+ '''
+
+
+ SECONDS = 1
+ '''
+ :float Synchronisation value for syncing to seconds
+ '''
+
+ MINUTES = 60
+ '''
+ :float Synchronisation value for syncing to minutes
+ '''
+
+
+ def __init__(self, timezone, format = '%Y-(%m)%b-%d %T, %a w%V, %Z', sync_to = 1):
+ '''
+ Constructor
+
+ @param timezone:str The timezone
+ @param format:str The format as in the `date` command
+ @param sync_to:float The time parameter to sync to, the number of seconds between the reads
+ '''
+ self.utc = tz('UTC')
+ self.timezone = tz(timezone)
+ self.format = format
+ self.sync_to = sync_to
+
+
+ def read(self):
+ '''
+ Reads the clock
+
+ @return :str The time and date in the format specified at construction
+ '''
+ return self.from_posix_time(TZClock.posix_time())
+
+
+ def from_posix_time(self, time):
+ '''
+ Converts POSIX time into human readable time with the selected timezone
+
+ @param time:float The POSIX time
+ @return :str The time and date in the format specified at construction
+ '''
+ return datetime.fromtimestamp(time, tz = self.utc).astimezone(self.timezone).strftime(self.format)
+
+
+ def sync(self):
+ '''
+ Wait for the clock to reach the next synchronisation time point
+ '''
+ time.sleep(self.sync_to - (time.time() % self.sync_to))
+
+
+ def continuous_sync(self, function):
+ '''
+ Wait for the clock to reach the next synchronisation time point
+ and the call a function and start over, i.e. sync in a loop forever
+
+ @param function:()→void The function to call
+ '''
+ while True:
+ time.sleep(self.sync_to - (time.time() % self.sync_to))
+ function()
+
+
+ @staticmethod
+ def posix_time():
+ '''
+ Returns the current POSIX time
+
+ @return :float The current POSIX time
+ '''
+ return time.time()
+