Do you know what a Word Clock is? Well, it's basically a clock which gives you the time using words instead of numbers.
The first time I saw one...I knew I wanted to have one, but then I think to myself..."Hey! I'm a programmer...why buy one when I can build one?" Also...I realized that most of the Word Clocks doesn't give you the exact time as you can see in the picture...so I decided to fix that -:)
Next step was to decided which programming language to use...I needed a nice graphical interface so ABAP and R we're out of the question...web version wasn't what I was looking for, so PHP was discarded as well...so my next guess was a language I really like and didn't want to forgot so easily -;) So I choose Python and wxPython to make it work -:) Of course...I'm far from being a Python expert, so I'm sure my code could be a little shorter -:P
#Blag's Word Clock
#Alvaro "Blag" Tejada Galindo
#17/01/2012
import wx
import time
import datetime
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, title="Blag's Word Clock")
self.SetTopWindow(self.frame)
self.frame.Show()
return True
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="",
pos=wx.DefaultPosition, size=(330, 260),
style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER,
name="MyFrame"):
super(MyFrame, self).__init__(parent, id, title, pos,size, style, name)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.timer.Start(1000)
self.SetBackgroundColour("Black")
text_font = wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Arial')
self.label_it=wx.StaticText(self,1,"IT",wx.Point(10,10))
self.label_it.SetForegroundColour("yellow")
self.label_it.SetFont(text_font)
self.label_is=wx.StaticText(self,1,"IS",wx.Point(35,10))
self.label_is.SetForegroundColour("yellow")
self.label_is.SetFont(text_font)
self.label_half=wx.StaticText(self,1,"HALF",wx.Point(60,10))
self.label_half.SetForegroundColour("gray")
self.label_half.SetFont(text_font)
self.label_twenty=wx.StaticText(self,1,"TWENTY",wx.Point(120,10))
self.label_twenty.SetForegroundColour("gray")
self.label_twenty.SetFont(text_font)
self.label_quarter=wx.StaticText(self,1,"QUARTER",wx.Point(215,10))
self.label_quarter.SetForegroundColour("gray")
self.label_quarter.SetFont(text_font)
self.label_ten=wx.StaticText(self,1,"TEN",wx.Point(10,40))
self.label_ten.SetForegroundColour("gray")
self.label_ten.SetFont(text_font)
self.label_to=wx.StaticText(self,1,"TO",wx.Point(75,40))
self.label_to.SetForegroundColour("gray")
self.label_to.SetFont(text_font)
self.label_one=wx.StaticText(self,1,"ONE",wx.Point(120,40))
self.label_one.SetForegroundColour("gray")
self.label_one.SetFont(text_font)
self.label_two=wx.StaticText(self,1,"TWO",wx.Point(180,40))
self.label_two.SetForegroundColour("gray")
self.label_two.SetFont(text_font)
self.label_three=wx.StaticText(self,1,"THREE",wx.Point(245,40))
self.label_three.SetForegroundColour("gray")
self.label_three.SetFont(text_font)
self.label_four=wx.StaticText(self,1,"FOUR",wx.Point(10,70))
self.label_four.SetForegroundColour("gray")
self.label_four.SetFont(text_font)
self.label_five=wx.StaticText(self,1,"FIVE",wx.Point(75,70))
self.label_five.SetForegroundColour("gray")
self.label_five.SetFont(text_font)
self.label_six=wx.StaticText(self,1,"SIX",wx.Point(125,70))
self.label_six.SetForegroundColour("gray")
self.label_six.SetFont(text_font)
self.label_seven=wx.StaticText(self,1,"SEVEN",wx.Point(170,70))
self.label_seven.SetForegroundColour("gray")
self.label_seven.SetFont(text_font)
self.label_eight=wx.StaticText(self,1,"EIGHT",wx.Point(250,70))
self.label_eight.SetForegroundColour("gray")
self.label_eight.SetFont(text_font)
self.label_nine=wx.StaticText(self,1,"NINE",wx.Point(10,100))
self.label_nine.SetForegroundColour("gray")
self.label_nine.SetFont(text_font)
self.label_eleven=wx.StaticText(self,1,"ELEVEN",wx.Point(110,100))
self.label_eleven.SetForegroundColour("gray")
self.label_eleven.SetFont(text_font)
self.label_twelve=wx.StaticText(self,1,"TWELVE",wx.Point(230,100))
self.label_twelve.SetForegroundColour("gray")
self.label_twelve.SetFont(text_font)
self.label_minutes=wx.StaticText(self,1,"MINUTES",wx.Point(10,130))
self.label_minutes.SetForegroundColour("gray")
self.label_minutes.SetFont(text_font)
self.label_past=wx.StaticText(self,1,"PAST",wx.Point(115,130))
self.label_past.SetForegroundColour("gray")
self.label_past.SetFont(text_font)
self.label_to_x=wx.StaticText(self,1,"TO",wx.Point(180,130))
self.label_to_x.SetForegroundColour("gray")
self.label_to_x.SetFont(text_font)
self.label_one_x=wx.StaticText(self,1,"ONE",wx.Point(215,130))
self.label_one_x.SetForegroundColour("gray")
self.label_one_x.SetFont(text_font)
self.label_two_x=wx.StaticText(self,1,"TWO",wx.Point(265,130))
self.label_two_x.SetForegroundColour("gray")
self.label_two_x.SetFont(text_font)
self.label_three_x=wx.StaticText(self,1,"THREE",wx.Point(10,160))
self.label_three_x.SetForegroundColour("gray")
self.label_three_x.SetFont(text_font)
self.label_four_x=wx.StaticText(self,1,"FOUR",wx.Point(85,160))
self.label_four_x.SetForegroundColour("gray")
self.label_four_x.SetFont(text_font)
self.label_five_x=wx.StaticText(self,1,"FIVE",wx.Point(150,160))
self.label_five_x.SetForegroundColour("gray")
self.label_five_x.SetFont(text_font)
self.label_six_x=wx.StaticText(self,1,"SIX",wx.Point(205,160))
self.label_six_x.SetForegroundColour("gray")
self.label_six_x.SetFont(text_font)
self.label_seven_x=wx.StaticText(self,1,"SEVEN",wx.Point(245,160))
self.label_seven_x.SetForegroundColour("gray")
self.label_seven_x.SetFont(text_font)
self.label_eight_x=wx.StaticText(self,1,"EIGHT",wx.Point(10,190))
self.label_eight_x.SetForegroundColour("gray")
self.label_eight_x.SetFont(text_font)
self.label_nine_x=wx.StaticText(self,1,"NINE",wx.Point(95,190))
self.label_nine_x.SetForegroundColour("gray")
self.label_nine_x.SetFont(text_font)
self.label_ten_x=wx.StaticText(self,1,"TEN",wx.Point(165,190))
self.label_ten_x.SetForegroundColour("gray")
self.label_ten_x.SetFont(text_font)
self.label_eleven_x=wx.StaticText(self,1,"ELEVEN",wx.Point(235,190))
self.label_eleven_x.SetForegroundColour("gray")
self.label_eleven_x.SetFont(text_font)
self.label_twelve_x=wx.StaticText(self,1,"TWELVE",wx.Point(10,220))
self.label_twelve_x.SetForegroundColour("gray")
self.label_twelve_x.SetFont(text_font)
self.label_oclock=wx.StaticText(self,1,"O'CLOCK",wx.Point(125,220))
self.label_oclock.SetForegroundColour("gray")
self.label_oclock.SetFont(text_font)
self.label_am=wx.StaticText(self,1,"AM",wx.Point(235,220))
self.label_am.SetForegroundColour("gray")
self.label_am.SetFont(text_font)
self.label_pm=wx.StaticText(self,1,"PM",wx.Point(283,220))
self.label_pm.SetForegroundColour("gray")
self.label_pm.SetFont(text_font)
def reset_colours(self):
self.label_pm.SetForegroundColour("gray")
self.label_am.SetForegroundColour("gray")
self.label_oclock.SetForegroundColour("gray")
self.label_one.SetForegroundColour("gray")
self.label_two.SetForegroundColour("gray")
self.label_three.SetForegroundColour("gray")
self.label_four.SetForegroundColour("gray")
self.label_five.SetForegroundColour("gray")
self.label_six.SetForegroundColour("gray")
self.label_seven.SetForegroundColour("gray")
self.label_eight.SetForegroundColour("gray")
self.label_nine.SetForegroundColour("gray")
self.label_one_x.SetForegroundColour("gray")
self.label_two_x.SetForegroundColour("gray")
self.label_three_x.SetForegroundColour("gray")
self.label_four_x.SetForegroundColour("gray")
self.label_five_x.SetForegroundColour("gray")
self.label_six_x.SetForegroundColour("gray")
self.label_seven_x.SetForegroundColour("gray")
self.label_eight_x.SetForegroundColour("gray")
self.label_nine_x.SetForegroundColour("gray")
self.label_half.SetForegroundColour("gray")
self.label_twenty.SetForegroundColour("gray")
self.label_quarter.SetForegroundColour("gray")
self.label_ten.SetForegroundColour("gray")
self.label_ten_x.SetForegroundColour("gray")
self.label_eleven.SetForegroundColour("gray")
self.label_eleven_x.SetForegroundColour("gray")
self.label_twelve.SetForegroundColour("gray")
self.label_twelve_x.SetForegroundColour("gray")
def hours(self,hour):
if hour == 12:
self.label_twelve.SetForegroundColour("yellow")
elif hour == 11:
self.label_eleven.SetForegroundColour("yellow")
elif hour == 10:
self.label_ten.SetForegroundColour("yellow")
elif hour == 9:
self.label_nine.SetForegroundColour("yellow")
elif hour == 8:
self.label_eight.SetForegroundColour("yellow")
elif hour == 7:
self.label_seven.SetForegroundColour("yellow")
elif hour == 6:
self.label_six.SetForegroundColour("yellow")
elif hour == 5:
self.label_five.SetForegroundColour("yellow")
elif hour == 4:
self.label_four.SetForegroundColour("yellow")
elif hour == 3:
self.label_three.SetForegroundColour("yellow")
elif hour == 2:
self.label_two.SetForegroundColour("yellow")
elif hour == 1:
self.label_one.SetForegroundColour("yellow")
def minutes(self,reminder):
if reminder == 9:
self.label_nine.SetForegroundColour("yellow")
if reminder == 8:
self.label_eight.SetForegroundColour("yellow")
if reminder == 7:
self.label_seven.SetForegroundColour("yellow")
if reminder == 6:
self.label_six.SetForegroundColour("yellow")
if reminder == 5:
self.label_five.SetForegroundColour("yellow")
if reminder == 4:
self.label_four.SetForegroundColour("yellow")
if reminder == 3:
self.label_three.SetForegroundColour("yellow")
if reminder == 2:
self.label_two.SetForegroundColour("yellow")
if reminder == 1:
self.label_one.SetForegroundColour("yellow")
def update(self, event):
self.reset_colours()
now=datetime.datetime.now()
hour = now.hour
minute = now.minute
if hour >= 12 and minute != 0:
self.label_pm.SetForegroundColour("yellow")
hour = hour - 12
elif hour < 12 and minute != 0:
self.label_am.SetForegroundColour("yellow")
elif minute == 0:
self.label_oclock.SetForegroundColour("yellow")
if hour >= 12:
hour = hour - 12
self.hours(hour)
else:
self.hours(hour)
if minute >= 1 and minute <= 29:
self.label_minutes.SetForegroundColour("yellow")
self.label_past.SetForegroundColour("yellow")
if hour == 12:
self.label_twelve_x.SetForegroundColour("yellow")
elif hour == 11:
self.label_eleven_x.SetForegroundColour("yellow")
elif hour == 10:
self.label_ten_x.SetForegroundColour("yellow")
elif hour == 9:
self.label_nine_x.SetForegroundColour("yellow")
elif hour == 8:
self.label_eight_x.SetForegroundColour("yellow")
elif hour == 7:
self.label_seven_x.SetForegroundColour("yellow")
elif hour == 6:
self.label_six_x.SetForegroundColour("yellow")
elif hour == 5:
self.label_five_x.SetForegroundColour("yellow")
elif hour == 4:
self.label_four_x.SetForegroundColour("yellow")
elif hour == 3:
self.label_three_x.SetForegroundColour("yellow")
elif hour == 2:
self.label_two_x.SetForegroundColour("yellow")
elif hour == 1:
self.label_one_x.SetForegroundColour("yellow")
division = minute / 20
reminder = minute % 20
if division == 1 and reminder == 0:
self.label_twenty.SetForegroundColour("yellow")
elif division == 1 and reminder != 0:
self.label_twenty.SetForegroundColour("yellow")
self.minutes(reminder)
division = minute / 10
reminder = minute % 10
if division == 1 and reminder == 0:
self.label_ten.SetForegroundColour("yellow")
elif division == 1 and reminder != 0:
self.label_ten.SetForegroundColour("yellow")
if reminder == 9:
self.label_nine.SetForegroundColour("yellow")
if reminder == 8:
self.label_eight.SetForegroundColour("yellow")
if reminder == 7:
self.label_seven.SetForegroundColour("yellow")
if reminder == 6:
self.label_six.SetForegroundColour("yellow")
if reminder == 5:
self.label_ten.SetForegroundColour("gray")
self.label_quarter.SetForegroundColour("yellow")
if reminder == 4:
self.label_four.SetForegroundColour("yellow")
if reminder == 3:
self.label_three.SetForegroundColour("yellow")
if reminder == 2:
self.label_ten.SetForegroundColour("gray")
self.label_twelve.SetForegroundColour("yellow")
if reminder == 1:
self.label_ten.SetForegroundColour("gray")
self.label_eleven.SetForegroundColour("yellow")
elif division == 0 and reminder != 0:
if reminder == 9:
self.label_nine.SetForegroundColour("yellow")
if reminder == 8:
self.label_eight.SetForegroundColour("yellow")
if reminder == 7:
self.label_seven.SetForegroundColour("yellow")
if reminder == 6:
self.label_six.SetForegroundColour("yellow")
if reminder == 5:
self.label_five.SetForegroundColour("yellow")
if reminder == 4:
self.label_four.SetForegroundColour("yellow")
if reminder == 3:
self.label_three.SetForegroundColour("yellow")
if reminder == 2:
self.label_two.SetForegroundColour("yellow")
if reminder == 1:
self.label_one.SetForegroundColour("yellow")
elif minute == 30:
self.hours(hour)
self.label_half.SetForegroundColour("yellow")
self.label_past.SetForegroundColour("yellow")
elif minute >= 29 and minute <= 59:
self.label_minutes.SetForegroundColour("yellow")
minute = 60 - minute
self.label_to_x.SetForegroundColour("yellow")
hour = hour + 1
if hour == 12:
self.label_twelve_x.SetForegroundColour("yellow")
elif hour == 11:
self.label_eleven_x.SetForegroundColour("yellow")
elif hour == 10:
self.label_ten_x.SetForegroundColour("yellow")
elif hour == 9:
self.label_nine_x.SetForegroundColour("yellow")
elif hour == 8:
self.label_eight_x.SetForegroundColour("yellow")
elif hour == 7:
self.label_seven_x.SetForegroundColour("yellow")
elif hour == 6:
self.label_six_x.SetForegroundColour("yellow")
elif hour == 5:
self.label_five_x.SetForegroundColour("yellow")
elif hour == 4:
self.label_four_x.SetForegroundColour("yellow")
elif hour == 3:
self.label_three_x.SetForegroundColour("yellow")
elif hour == 2:
self.label_two_x.SetForegroundColour("yellow")
elif hour == 1:
self.label_one_x.SetForegroundColour("yellow")
division = minute / 20
reminder = minute % 20
if division == 1 and reminder == 0:
self.label_twenty.SetForegroundColour("yellow")
elif division == 1 and reminder != 0:
self.label_twenty.SetForegroundColour("yellow")
if reminder == 9:
self.label_nine.SetForegroundColour("yellow")
if reminder == 8:
self.label_eight.SetForegroundColour("yellow")
if reminder == 7:
self.label_seven.SetForegroundColour("yellow")
if reminder == 6:
self.label_six.SetForegroundColour("yellow")
if reminder == 5:
self.label_five.SetForegroundColour("yellow")
if reminder == 4:
self.label_four.SetForegroundColour("yellow")
if reminder == 3:
self.label_three.SetForegroundColour("yellow")
if reminder == 2:
self.label_two.SetForegroundColour("yellow")
if reminder == 1:
self.label_one.SetForegroundColour("yellow")
division = minute / 10
reminder = minute % 10
if division == 1 and reminder == 0:
self.label_ten.SetForegroundColour("yellow")
elif division == 1 and reminder != 0:
self.label_ten.SetForegroundColour("yellow")
if reminder == 9:
self.label_nine.SetForegroundColour("yellow")
if reminder == 8:
self.label_eight.SetForegroundColour("yellow")
if reminder == 7:
self.label_seven.SetForegroundColour("yellow")
if reminder == 6:
self.label_six.SetForegroundColour("yellow")
if reminder == 5:
self.label_ten.SetForegroundColour("gray")
self.label_quarter.SetForegroundColour("yellow")
if reminder == 4:
self.label_four.SetForegroundColour("yellow")
if reminder == 3:
self.label_three.SetForegroundColour("yellow")
if reminder == 2:
self.label_ten.SetForegroundColour("gray")
self.label_twelve.SetForegroundColour("yellow")
if reminder == 1:
self.label_ten.SetForegroundColour("gray")
self.label_eleven.SetForegroundColour("yellow")
elif division == 0 and reminder != 0:
self.minutes(reminder)
if __name__ == "__main__":
app = MyApp(False)
app.MainLoop()
Greetings,
Blag.
No hay comentarios:
Publicar un comentario