# -*- coding: utf8 -*-

# Copyright (c) 2006, Jonathan R. Woodworth
# Distributed under the BSD license. See LICENSE for details.


import wx, datetime


class ClientClock(wx.StaticText):
	"""
	Provides a simple Wx clock for use with the SotSW chatclient.
	
	"""

	def __init__(self, topWindow, currentDateTime):
		self.time = currentDateTime
		wx.StaticText.__init__(self, topWindow, 
			label = self.time.strftime("%I:%M %p %A\n%m/%d/%Y"), 
			style = wx.ALIGN_CENTER, size = (125, 40))
		
	def set(self, newTime):
		"""
		Takes a datetime or timedelta. If datetime, sets current time to the 
		datetime. If timedelta, adds the timedelta to the current datetime and 
		uses that.
		
		"""
		if isinstance(newTime, datetime.datetime):
			self.time = newTime
		
		elif isinstance(newTime, datetime.timedelta):
			self.time = self.time + newTime
			
		else:
			raise TypeError
		
		self._updateClock()
			
	def _updateClock(self):
		"""
		Updates clock text. Has no knowledge of time formats.
		
		"""
		self.SetLabel(self.time.strftime("%I:%M %p %A\n%m/%d/%Y"))