Python: World Clock


import time
import wx
import wx.gizmos as gizmos
from datetime import datetime
from pytz import timezone
import pytz

utc = pytz.utc
    
class LED_clock(wx.Frame):
    """
    Create nice LED clock showing the current time
    """
    def __init__(self, parent, id):
        pos = wx.DefaultPosition
        wx.Frame.__init__(self, parent, id, title='maya World Clock, Ver: 0.0.1', pos=pos, size=(200, 70))
        self.SetIcon(wx.Icon(r"clock.ico", wx.BITMAP_TYPE_ICO))
        size = wx.DefaultSize
        style = gizmos.LED_ALIGN_CENTER
        self.estLed = gizmos.LEDNumberCtrl(self, -1, pos, size, style)
        self.m_stESTTime = wx.StaticText( self, wx.ID_ANY, u"EST Time", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE|wx.STATIC_BORDER )
        self.m_stESTTime.SetBackgroundColour( wx.Colour( 255, 221, 187 ) )
        bSizer4 = wx.BoxSizer( wx.HORIZONTAL )
        bSizer5 = wx.BoxSizer( wx.VERTICAL )
        bSizer5.Add(self.m_stESTTime, 0, wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL|wx.ALL|wx.EXPAND, 0 
        bSizer5.Add(self.estLed, 1, wx.EXPAND, 5 )
        bSizer4.Add(bSizer5, 1, wx.EXPAND, 5 )
        self.m_stIndiaTime = wx.StaticText( self, wx.ID_ANY, u"IST Time", wx.DefaultPosition, wx.DefaultSize,  wx.ALIGN_CENTRE|wx.STATIC_BORDER )
        self.m_stIndiaTime.SetBackgroundColour( wx.Colour( 255, 221, 187 ) )
        self.indiaLed = gizmos.LEDNumberCtrl(self, -1, pos, size, style)
        bSizer1 = wx.BoxSizer( wx.VERTICAL )
        bSizer1.Add(self.m_stIndiaTime , 0, wx.EXPAND|wx.ALIGN_CENTER|wx.ALIGN_CENTRE_HORIZONTAL, 5 )
        bSizer1.Add(self.indiaLed, 1, wx.EXPAND, 5 )
        bSizer4.Add(bSizer1, 1, wx.EXPAND, 5 )
        self.SetSizer( bSizer4 )
        self.Layout()
        self.OnTimer(None)
        self.timer = wx.Timer(self, -1)
        self.timer.Start(1000)
        self.Bind(wx.EVT_TIMER, self.OnTimer)
        self.Centre()

    def GetIndiaTime(self):
        fmt = '%H %M %S'
        india = timezone('Asia/Kolkata') #('Asia/Kolkata')
        eastern = timezone('US/Eastern')
        loc_dt = eastern.localize(datetime.now())
        in_dt = loc_dt.astimezone(india)
        return (in_dt.strftime(fmt))

    def OnTimer(self, event):
        current = time.localtime(time.time())
        ts = time.strftime("%H %M %S", current)
        self.estLed.SetValue(ts)
        tst = self.GetIndiaTime()
        self.indiaLed.SetValue(tst)

if __name__ == '__main__':
    app = wx.App()
    frame = LED_clock(None, -1)
    frame.Show(True)
    app.SetTopWindow(frame)
    app.MainLoop()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s