MCPcopy Create free account
hub / github.com/ActiveState/code / clock

Class clock

recipes/Python/576830_analog_clock/recipe-576830.py:49–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47 return self.point(x1,y1),self.point(x2,y2)
48
49class clock:
50
51 def __init__(self,root,deltahours = 0):
52 self.world = [-1,-1,1,1]
53 self.bgcolor = '#000000'
54 self.circlecolor = '#808080'
55 self.timecolor = '#ffffff'
56 self.circlesize = 0.09
57 self._ALL = 'all'
58 self.pad = 25
59 self.root = root
60 WIDTH, HEIGHT = 400, 400
61 root.bind("<Escape>", lambda _ : root.destroy())
62 self.delta = timedelta(hours = deltahours)
63 self.canvas = Canvas(root,
64 width = WIDTH,
65 height = HEIGHT,
66 background = self.bgcolor)
67 viewport = (self.pad,self.pad,WIDTH-self.pad,HEIGHT-self.pad)
68 self.T = transformer(self.world,viewport)
69 self.root.title('Clock')
70 self.canvas.bind("<Configure>",self.configure())
71 self.canvas.pack(fill=BOTH, expand=YES)
72 self.poll()
73
74 def configure(self):
75 self.redraw()
76
77 def redraw(self):
78 sc = self.canvas
79 sc.delete(self._ALL)
80 width = sc.winfo_width()
81 height =sc.winfo_height()
82 sc.create_rectangle([[0,0],[width,height]],
83 fill = self.bgcolor, tag = self._ALL)
84 viewport = (self.pad,self.pad,width-self.pad,height-self.pad)
85 self.T = transformer(self.world,viewport)
86 self.paintgrafics()
87
88 def paintgrafics(self):
89 start = -pi/2
90 step = pi/6
91 for i in range(12):
92 angle = start+i*step
93 x, y = cos(angle),sin(angle)
94 self.paintcircle(x,y)
95 self.painthms()
96 self.paintcircle(0,0)
97
98 def painthms(self):
99 T = datetime.timetuple(datetime.utcnow()-self.delta)
100 x,x,x,h,m,s,x,x,x = T
101 self.root.title('%02i:%02i:%02i' %(h,m,s))
102 angle = -pi/2 + (pi/6)*h + (pi/6)*(m/60.0)
103 x, y = cos(angle)*.60,sin(angle)*.60
104 scl = self.canvas.create_line
105 scl(apply(self.T.twopoints,[0,0,x,y]), fill = self.timecolor,
106 tag =self._ALL, width = 6)

Callers 14

mainFunction · 0.70
__init__Method · 0.50
update_screenMethod · 0.50
waitMethod · 0.50
recipe-466330.pyFile · 0.50
__init__Method · 0.50
__call__Method · 0.50
readyMethod · 0.50
_posmax_benchmark1Function · 0.50
recipe-496907.pyFile · 0.50
recipe-438599.pyFile · 0.50
pytimeFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected