1 # -*- coding: iso-8859-1 -*-
2 #----------------------------------------------------------------------
3 # Name: wx.lib.analogclock
4 # Purpose: A simple analog clock window
6 # Author: several folks on wxPython-users
8 # Created: 16-April-2003
10 # Copyright: (c) 2003 by Total Control Software
11 # Licence: wxWindows license
12 #----------------------------------------------------------------------
13 # 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net)
15 # o Updated for wx namespace
16 # o Tested with updated demo and with builtin test.
18 # 15-February-2004 - E. A. Tacao
31 from analogclockopts
import ACCustomizationFrame
35 SHOW_QUARTERS_TICKS
= 1
37 SHOW_MINUTES_TICKS
= 4
40 SHOW_MINUTES_HAND
= 32
41 SHOW_SECONDS_HAND
= 64
45 # self.tickMarkHoursStyle and self.tickMarkMinutesStyle:
54 class AnalogClockWindow(wx
.PyWindow
):
55 """An analog clock window"""
57 def __init__(self
, parent
, ID
=-1, pos
=wx
.DefaultPosition
, size
=wx
.DefaultSize
,
58 style
=0, name
="clock"):
60 # Initialize the wxWindow...
61 wx
.PyWindow
.__init
__(self
, parent
, ID
, pos
, size
, style
, name
)
63 # Initialize some variables and defaults...
65 self
.prefs_open
= False
67 self
.tickShapeHours
= self
.tickShapeMinutes
= [[0,0],
71 self
.handHoursThickness
= 5
72 self
.handHoursColour
= (0, 0, 0)
74 self
.handMinutesThickness
= 3
75 self
.handMinutesColour
= (0, 0, 0)
77 self
.handSecondsThickness
= 1
78 self
.handSecondsColour
= (0, 0, 0)
80 self
.tickMarkHoursPen
= wx
.Pen((0, 0, 0), 1, wx
.SOLID
)
81 self
.tickMarkHoursBrush
= wx
.Brush((0, 0, 0), wx
.SOLID
)
82 self
.markSizeHour
= 10
83 self
.tickMarkHoursFont
= wx
.Font(0, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
)
84 self
.tickMarkHoursFont
.SetPointSize(self
.markSizeHour
)
86 self
.tickMarkMinutesPen
= wx
.Pen((0, 0, 0), 1, wx
.SOLID
)
87 self
.tickMarkMinutesBrush
= wx
.Brush((0, 0, 0), wx
.SOLID
)
89 self
.tickMarkMinutesFont
= wx
.Font(self
.markSizeMin
, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
)
93 self
.shadowPenColour
= self
.shadowBrushColour
= (128,128,128)
96 self
.watchBrush
= None
98 self
.clockStyle
= SHOW_HOURS_TICKS | SHOW_MINUTES_TICKS | SHOW_SHADOWS | ROTATE_TICKS
99 self
.handsStyle
= SHOW_SECONDS_HAND
101 self
.tickMarkHoursStyle
= TICKS_POLY
102 self
.tickMarkMinutesStyle
= TICKS_CIRCLE
104 self
.currentTime
=None
106 size
= wx
.Size(*size
)
107 bestSize
= self
.GetBestSize()
108 size
.x
= max(size
.x
, bestSize
.x
)
109 size
.y
= max(size
.y
, bestSize
.y
)
112 # Make an initial bitmap for the face, it will be updated and
113 # painted at the first EVT_SIZE event.
115 self
.faceBitmap
= wx
.EmptyBitmap(max(W
,1), max(H
,1))
117 # Set event handlers...
118 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
119 self
.Bind(wx
.EVT_ERASE_BACKGROUND
, lambda x
: None)
120 self
.Bind(wx
.EVT_SIZE
, self
.OnSize
)
121 self
.Bind(wx
.EVT_TIMER
, self
.OnTimerExpire
)
122 self
.Bind(wx
.EVT_WINDOW_DESTROY
, self
.OnQuit
)
123 self
.Bind(wx
.EVT_RIGHT_DOWN
, self
.OnRightDown
)
124 self
.Bind(wx
.EVT_RIGHT_UP
, self
.OnRightClick
)
126 # Initialize the timer that drives the update of the clock
127 # face. Update every half second to ensure that there is at
128 # least one true update during each realtime second.
129 self
.timer
= wx
.Timer(self
)
130 self
.timer
.Start(500)
133 def DoGetBestSize(self
):
134 return wx
.Size(25,25)
137 def OnPaint(self
, event
):
138 dc
= wx
.BufferedPaintDC(self
)
139 self
._doDrawHands
(dc
, True)
142 def OnTimerExpire(self
, event
):
143 size
= self
.GetClientSize()
144 dc
= wx
.BufferedDC(wx
.ClientDC(self
), size
)
145 self
._doDrawHands
(dc
, True)
148 def OnQuit(self
, event
):
153 def OnRightDown(self
, event
):
154 self
.x
= event
.GetX()
155 self
.y
= event
.GetY()
159 def OnRightClick(self
, event
):
160 # only do this part the first time so the events are only bound once
161 if not hasattr(self
, "popupID1"):
162 self
.popupID1
= wx
.NewId()
163 self
.popupID2
= wx
.NewId()
164 self
.Bind(wx
.EVT_MENU
, self
.OnPopupOne
, id=self
.popupID1
)
165 self
.Bind(wx
.EVT_MENU
, self
.OnPopupTwo
, id=self
.popupID2
)
170 sm
.Append(self
.popupID1
, "Customize...")
171 sm
.Append(self
.popupID2
, "About...")
173 # If there already a setup window open, we must not appear...
174 if not self
.prefs_open
:
175 # Popup the menu. If an item is selected then its handler
176 # will be called before PopupMenu returns.
177 self
.PopupMenu(sm
, (self
.x
,self
.y
))
181 def OnPopupOne(self
, event
):
183 frame
= ACCustomizationFrame(self
, -1, "AnalogClock Preferences")
187 def OnPopupTwo(self
, event
):
188 dlg
= wx
.MessageDialog(self
, "AnalogClockWindow\n\nby Several folks on wxPython-users\nwith enhancements from E. A. Tacão",
189 'About', wx
.OK | wx
.ICON_INFORMATION
)
194 def OnSize(self
, event
):
195 # The faceBitmap init is done here, to make sure the buffer is always
196 # the same size as the Window
197 size
= self
.GetClientSize()
198 if size
.x
< 1 or size
.y
< 1:
201 self
.faceBitmap
= wx
.EmptyBitmap(size
.width
, size
.height
)
203 # Update drawing coordinates...
205 if not hasattr(self
,"dim"):
209 self
.scale
= min([float(new_dim
[x
]) / self
.dim
[x
],
210 float(new_dim
[y
]) / self
.dim
[y
]])
212 self
.centerX
= self
.faceBitmap
.GetWidth() / 2
213 self
.centerY
= self
.faceBitmap
.GetHeight() / 2
215 self
.shadowDistance
= 2 * self
.scale
217 self
.radius_watch
= min(self
.centerX
, self
.centerY
)
223 def _doDrawHands(self
, drawDC
, force
=0):
224 currentTime
= list(time
.localtime(time
.time())[3:6])
226 if not (self
.handsStyle
& SHOW_SECONDS_HAND
):
229 if not (force
or currentTime
!= self
.currentTime
):
231 self
.currentTime
= currentTime
232 hour
, minutes
, seconds
= currentTime
234 # Start by drawing the face bitmap
235 drawDC
.DrawBitmap(self
.faceBitmap
, 0,0)
238 # NOTE: All this hand drawing code below should be refactored into a helper function.
241 # Draw hours hand shadow
242 mStep
= 6 * self
.clockStep
246 angle
= angle
+ round(minutes
/(mStep
*2)) * mStep
248 x
,y
,f
= self
._getCoords
("hand_hours", angle
)
250 if f
and self
.clockStyle
& SHOW_SHADOWS
:
251 drawDC
.SetPen(wx
.Pen(self
.shadowPenColour
,
252 int(self
.handHoursThickness
* self
.scale
),
254 drawDC
.DrawLine(self
.centerX
+ self
.shadowDistance
,
255 self
.centerY
+ self
.shadowDistance
,
256 x
+ self
.shadowDistance
,
257 y
+ self
.shadowDistance
)
259 # Draw minutes hand shadow
261 x
,y
,f
= self
._getCoords
("hand_minutes", angle
)
263 if f
and self
.clockStyle
& SHOW_SHADOWS
:
264 drawDC
.SetPen(wx
.Pen(self
.shadowPenColour
,
265 int(self
.handMinutesThickness
* self
.scale
),
267 drawDC
.DrawLine(self
.centerX
+ self
.shadowDistance
,
268 self
.centerY
+ self
.shadowDistance
,
269 x
+ self
.shadowDistance
,
270 y
+ self
.shadowDistance
)
272 # Draw seconds hand shadow if required
275 x
,y
,f
= self
._getCoords
("hand_seconds", angle
)
277 if f
and self
.clockStyle
& SHOW_SHADOWS
:
278 drawDC
.SetPen(wx
.Pen(self
.shadowPenColour
,
279 int(self
.handSecondsThickness
* self
.scale
),
281 drawDC
.DrawLine(self
.centerX
+ self
.shadowDistance
,
282 self
.centerY
+ self
.shadowDistance
,
283 x
+ self
.shadowDistance
,
284 y
+ self
.shadowDistance
)
291 angle
= angle
+ round(minutes
/(mStep
*2)) * mStep
293 x
,y
,f
= self
._getCoords
("hand_hours", angle
)
296 drawDC
.SetPen(wx
.Pen(self
.handHoursColour
,
297 int(self
.handHoursThickness
* self
.scale
),
299 drawDC
.DrawLine(self
.centerX
, self
.centerY
, x
, y
)
303 x
,y
,f
= self
._getCoords
("hand_minutes", angle
)
306 drawDC
.SetPen(wx
.Pen(self
.handMinutesColour
,
307 int(self
.handMinutesThickness
* self
.scale
),
309 drawDC
.DrawLine(self
.centerX
, self
.centerY
, x
, y
)
311 # Draw seconds hand if required
314 x
,y
,f
= self
._getCoords
("hand_seconds", angle
)
316 drawDC
.SetPen(wx
.Pen(self
.handSecondsColour
,
317 int(self
.handSecondsThickness
* self
.scale
),
319 drawDC
.DrawLine(self
.centerX
, self
.centerY
, x
, y
)
323 def _doDrawFace(self
):
324 backgroundBrush
= wx
.Brush(self
.GetBackgroundColour(), wx
.SOLID
)
325 drawDC
= wx
.MemoryDC()
326 drawDC
.SelectObject(self
.faceBitmap
)
327 drawDC
.SetBackground(backgroundBrush
)
330 self
.handHoursLength
= 0.65 * (self
.radius_watch
- self
._getMarkMaxSize
("ticks_hours", drawDC
))
331 self
.handMinutesLength
= 0.85 * (self
.radius_watch
- self
._getMarkMaxSize
("ticks_hours", drawDC
))
332 self
.handSecondsLength
= 0.85 * (self
.radius_watch
- self
._getMarkMaxSize
("ticks_hours", drawDC
))
334 self
.radius_ticks_hours
= self
.radius_watch
- self
.shadowDistance
- self
._getMarkMaxSize
("ticks_hours", drawDC
)
335 self
.radius_ticks_minutes
= self
.radius_ticks_hours
340 self
._drawWatch
(drawDC
)
342 # Draw the marks for hours and minutes...
344 mStep
= 6 * self
.clockStep
346 if self
.clockStyle
& SHOW_SHADOWS
:
347 for i
in range(0, circle
, mStep
):
348 for t
in self
.coords
.keys():
349 if t
.find("ticks") > -1:
350 x
,y
,f
= self
._getCoords
(t
, i
)
352 self
._doDrawTickMark
(i
, drawDC
, t
,
353 x
+ self
.shadowDistance
,
354 y
+ self
.shadowDistance
,
357 for i
in range(0, circle
, mStep
):
358 for t
in self
.coords
.keys():
359 if t
.find("ticks") > -1:
360 x
,y
,f
= self
._getCoords
(t
, i
)
362 self
._doDrawTickMark
(i
, drawDC
, t
, x
, y
)
366 def _doDrawTickMark(self
, angle
, drawDC
, tipo
, x
, y
, is_a_shadow
=None):
367 opts
= {"ticks_hours": [self
.tickMarkHoursPen
, self
.tickMarkHoursBrush
, self
.markSizeHour
, self
.tickMarkHoursStyle
],
368 "ticks_quarters": [self
.tickMarkHoursPen
, self
.tickMarkHoursBrush
, self
.markSizeHour
, self
.tickMarkHoursStyle
],
369 "ticks_minutes": [self
.tickMarkMinutesPen
, self
.tickMarkMinutesBrush
, self
.markSizeMin
, self
.tickMarkMinutesStyle
]}
371 pen
, brush
, size
, style
= opts
[tipo
];
372 size
= size
* self
.scale
375 drawDC
.SetPen(wx
.Pen(self
.shadowPenColour
, 1, wx
.SOLID
))
376 drawDC
.SetBrush(wx
.Brush(self
.shadowBrushColour
, wx
.SOLID
))
377 drawDC
.SetTextForeground(self
.shadowBrushColour
)
380 drawDC
.SetBrush(brush
)
381 drawDC
.SetTextForeground(brush
.GetColour())
383 if style
& TICKS_CIRCLE
:
384 x
, y
= self
._center
2corner
(x
, y
, tipo
)
385 drawDC
.DrawEllipse(x
, y
, size
, size
)
387 elif style
& TICKS_SQUARE
:
388 x
, y
= self
._center
2corner
(x
, y
, tipo
)
389 drawDC
.DrawRectangle(x
, y
, size
, size
)
391 elif (style
& TICKS_DECIMAL
) or (style
& TICKS_ROMAN
):
392 self
._draw
_rotate
_text
(drawDC
, x
, y
, tipo
, angle
)
394 elif style
& TICKS_POLY
:
395 self
._draw
_rotate
_polygon
(drawDC
, x
, y
, tipo
, angle
)
398 def _draw_rotate_text(self
, drawDC
, x
, y
, tipo
, angle
):
399 text
= self
._build
_text
(angle
, tipo
)
400 lX
, lY
= self
._center
2corner
(x
, y
, tipo
, drawDC
)
404 if self
.clockStyle
& ROTATE_TICKS
:
405 radiansPerDegree
= math
.pi
/ 180
407 ((math
.cos((angle
) * radiansPerDegree
)*lX
) +
408 (math
.sin((angle
) * radiansPerDegree
)*lY
)))
410 ((math
.cos((angle
) * radiansPerDegree
)*lY
) -
411 (math
.sin((angle
) * radiansPerDegree
)*lX
)))
412 drawDC
.DrawRotatedText(text
, x
,y
, angle
)
417 drawDC
.DrawText(text
, x
, y
)
420 def _draw_rotate_polygon(self
, drawDC
, x
, y
, tipo
, angle
):
421 if tipo
=="ticks_quarters":
424 # Add to empty list to prevent system-wide hard freezes under XP...
425 points
= {"ticks_hours":self.tickShapeHours+[], "ticks_minutes":self.tickShapeMinutes+[]}
[tipo
]
426 size
= self
.scale
* {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}
[tipo
]
428 maxX
= max(map(lambda x
:x
[0],points
))
429 minX
= min(map(lambda x
:x
[0],points
))
430 maxY
= max(map(lambda x
:x
[0],points
))
431 minY
= min(map(lambda x
:x
[0],points
))
433 maxB
= abs(max(maxX
, maxY
));
436 orgX
= (maxX
- minX
) / 2.
437 orgY
= (maxY
- minY
) / 2.
439 radiansPerDegree
= math
.pi
/ 180
443 for z
in range(0, len(points
)):
447 if self
.clockStyle
& ROTATE_TICKS
:
448 m
,t
= self
._rect
2pol
(x
,y
)
450 x
,y
= self
._pol
2rect
(m
,t
)
453 points
[z
] = [int(x
), int(y
)]
455 drawDC
.DrawPolygon(points
)
458 def _pol2rect(self
, r
, w
, deg
=1): # radian if deg=0; degree if deg=1
460 w
= math
.pi
* w
/ 180.0
461 return r
* math
.cos(w
), r
* math
.sin(w
)
464 def _rect2pol(self
, x
, y
, deg
=1): # radian if deg=0; degree if deg=1
466 return math
.hypot(x
, y
), 180.0 * math
.atan2(y
, x
) / math
.pi
468 return math
.hypot(x
, y
), math
.atan2(y
, x
)
471 def _center2corner(self
, x
, y
, tipo
, drawDC
=None):
472 if tipo
== "ticks_quarters":
475 style
= {"ticks_hours":self.tickMarkHoursStyle, "ticks_minutes":self.tickMarkMinutesStyle}
[tipo
]
476 size
= self
.scale
* {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}
[tipo
]
478 if style
& TICKS_DECIMAL
or style
& TICKS_ROMAN
:
479 font
= {"ticks_hours":self.tickMarkHoursFont, "ticks_minutes":self.tickMarkMinutesFont}
[tipo
]
480 font
.SetPointSize(int(size
));
482 lX
= drawDC
.GetCharWidth() / 2.
483 lY
= drawDC
.GetCharHeight() / 2.
487 size
= self
.scale
* {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}
[tipo
]
488 x
=x
-size
/2.;y
=y
-size
/2.
492 def _build_text(self
, angle
, tipo
):
493 if tipo
== "ticks_quarters":
498 divider
= {"ticks_hours":30,"ticks_minutes":6}
[tipo
]
501 style
= {"ticks_hours":self.tickMarkHoursStyle," ticks_minutes":self.tickMarkMinutesStyle}
[tipo
]
502 if style
& TICKS_ROMAN
:
503 text
=["I","II","III","IV","V","VI","VII","VIII","IX","X", \
504 "XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX", \
505 "XXI","XXII","XXIII","XXIV","XXV","XXVI","XXVII","XXVIII","XXIX","XXX", \
506 "XXXI","XXXII","XXXIII","XXXIV","XXXV","XXXVI","XXXVII","XXXVIII","XXXIX","XL", \
507 "XLI","XLII","XLIII","XLIV","XLV","XLVI","XLVII","XLVIII","XLIX","L", \
508 "LI","LII","LIII","LIV","LV","LVI","LVII","LVIII","LIX","LX"][a
-1]
515 def _getMarkMaxSize(self
, tipo
, drawDC
=None):
516 if tipo
== "ticks_quarters":
519 style
= {"ticks_hours":self.tickMarkHoursStyle, "ticks_minutes":self.tickMarkMinutesStyle}
[tipo
]
520 size
= self
.scale
* {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}
[tipo
]
522 if style
& TICKS_DECIMAL
or style
& TICKS_ROMAN
:
523 lX
= 2 * drawDC
.GetCharWidth()
524 lY
= drawDC
.GetCharHeight()
525 size
= math
.sqrt(lX
**2 + lY
**2) * self
.scale
527 size
=math
.sqrt(2) * size
532 def _drawWatch(self
, drawDC
):
534 if self
.watchPen
or self
.watchBrush
:
536 drawDC
.SetPen(self
.watchPen
)
538 drawDC
.SetBrush(self
.watchBrush
)
540 drawDC
.SetBrush(wx
.Brush(self
.GetBackgroundColour(), wx
.SOLID
))
541 drawDC
.DrawCircle(self
.centerX
, self
.centerY
, self
.radius_watch
)
544 def _calcSteps(self
):
545 # Calcule todos os pontos para:
547 # - marcas de minutos
548 # - ponteiro de horas
549 # - ponteiro de minutos
550 # - ponteiro de segundos
553 mStep
= 6 * self
.clockStep
# Step in degrees...
555 vq
= 90 * (self
.clockStyle
& SHOW_QUARTERS_TICKS
) / SHOW_QUARTERS_TICKS
556 vh
= 30 * (self
.clockStyle
& SHOW_HOURS_TICKS
) / SHOW_HOURS_TICKS
557 vm
= 1 * (self
.clockStyle
& SHOW_MINUTES_TICKS
) / SHOW_MINUTES_TICKS
559 coords
= {"ticks_quarters": [self.radius_ticks_hours, 60,vq,{}
],
560 "ticks_hours": [self
.radius_ticks_hours
, 60,vh
,{}],
561 "ticks_minutes": [self
.radius_ticks_minutes
,60,vm
,{}],
562 "hand_hours": [self
.handHoursLength
, 60,1, {}],
563 "hand_minutes": [self
.handMinutesLength
, 60,1, {}],
564 "hand_seconds": [self
.handSecondsLength
, 60,1, {}]}
566 radiansPerDegree
= math
.pi
/ 180
568 for t
in coords
.keys():
569 for i
in range(0, circle
+mStep
, mStep
):
570 radius
= coords
[t
][0]
571 if t
== "ticks_minutes":
572 radius
= radius
- self
.offM
573 step_angle
= 360. / coords
[t
][1]
575 x
= self
.centerX
+ radius
* math
.sin(i
* radiansPerDegree
)
576 y
= self
.centerY
+ radius
* math
.cos(i
* radiansPerDegree
)
577 f
= (pre
and (i
/step_angle
== int(i
/step_angle
)) and (float(i
)/pre
== int(i
/pre
)))
578 coords
[t
][3][i
] = [x
,y
,f
]
580 if not self
.clockStyle
& OVERLAP_TICKS
:
581 for i
in range(0, circle
+ mStep
, mStep
):
582 f
=coords
["ticks_minutes"][3][i
][2]
584 (coords
["ticks_hours"][3].get(i
,[0,0,0])[2] or coords
["ticks_quarters"][3].get(i
,[0,0,0])[2]):
586 coords
["ticks_minutes"][3][i
][2]=f
591 def _getCoords(self
, tipo
, angle
):
592 # Returns coords and 'use flag' based on current angle...
593 k
= 360 - (angle
+ 180)
596 return self
.coords
[tipo
][3][k
]
599 # -----------------------------------------------------
601 def SetTickShapes(self
, tsh
, tsm
=None):
603 tsh, tsm: [[x0,y0], [x1,y1], ... [xn,yn]]
605 Sets lists of lists of points to be used as polygon shapes
606 when using the TICKS_POLY style. If tsm is ommitted,
607 we'll use tsh for both shapes.
613 self
.tickShapeHours
= tsh
614 self
.tickShapeMinutes
= tsm
617 def SetHandWeights(self
, h
=None, m
=None, s
=None):
621 Sets thickness of hands.
625 self
.handHoursThickness
= h
627 self
.handMinutesThickness
= m
629 self
.handSecondsThickness
= s
632 def SetHandColours(self
, h
=None, m
=None, s
=None):
636 Sets colours of hands. If m and s are ommitted,
640 if h
and not m
and not s
:
645 self
.handHoursColour
= h
647 self
.handMinutesColour
= m
649 self
.handSecondsColour
= s
652 def SetTickColours(self
, h
=None, m
=None):
656 Sets colours of ticks. If m is ommitted,
657 we'll use h for both.
664 self
.tickMarkHoursPen
= wx
.Pen(h
, 1, wx
.SOLID
)
665 self
.tickMarkHoursBrush
= wx
.Brush(h
, wx
.SOLID
)
668 self
.tickMarkMinutesPen
= wx
.Pen(m
, 1, wx
.SOLID
)
669 self
.tickMarkMinutesBrush
= wx
.Brush(m
, wx
.SOLID
)
672 def SetTickSizes(self
, h
=None, m
=None):
676 Sizes for tick marks.
680 self
.markSizeHour
= h
685 def SetTickFonts(self
, h
=None, m
=None):
689 Fonts for tick marks when using TICKS_DECIMAL or TICKS_ROMAN style.
690 If m is ommitted, we'll use h for both.
697 self
.tickMarkHoursFont
= h
698 self
.tickMarkHoursFont
.SetPointSize(self
.markSizeHour
)
700 self
.tickMarkMinutesFont
= m
701 self
.tickMarkMinutesFont
.SetPointSize(self
.markSizeMin
)
704 def SetMinutesOffset(self
, o
):
708 Sets the distance between tick marks for hours and minutes.
713 def SetShadowColour(self
, s
):
715 s = wx.Colour or (r,g,b) tuple.
717 Sets the colour to be used to draw shadows.
720 self
.shadowPenColour
= self
.shadowBrushColour
= s
723 def SetWatchPenBrush(self
, p
=None, b
=None):
725 p = wx.Pen; b = wx.Brush
727 Set the pen and brush for the watch.
736 def SetClockStyle(self
, style
):
738 Set the clock style, acording to the options:
740 SHOW_QUARTERS_TICKS - Show marks for hours 3, 6, 9, 12
741 SHOW_HOURS_TICKS - Show marks for all hours
742 SHOW_MINUTES_TICKS - Show marks for minutes
744 SHOW_HOURS_HAND - Show hours hand
745 SHOW_MINUTES_HAND - Show minutes hand
746 SHOW_SECONDS_HAND - Show seconds hand
748 SHOW_SHADOWS - Show hands and marks shadows
750 ROTATE_TICKS - Align tick marks to watch
751 OVERLAP_TICKS - Draw tick marks for minutes even
752 when they match the hours marks.
755 self
.clockStyle
= style
758 def SetTickStyles(self
, h
=None, m
=None):
760 Set the ticks styles, acording to the options below.
762 TICKS_NONE = Don't show tick marks.
763 TICKS_SQUARE = Use squares as tick marks.
764 TICKS_CIRCLE = Use circles as tick marks.
765 TICKS_POLY = Use a polygon as tick marks. The polygon
766 must be passed using SetTickShapes,
767 otherwise the default polygon will be used.
768 TICKS_DECIMAL = Use decimal numbers.
769 TICKS_ROMAN = Use Roman numbers.
773 self
.tickMarkHoursStyle
= h
775 self
.tickMarkMinutesStyle
= m
777 # -----------------------------------------------------
780 if __name__
== "__main__":
781 print wx
.VERSION_STRING
784 frame
= wx
.Frame(None, -1, "AnalogClockWindow", size
=(375,375))
786 clock
= AnalogClockWindow(frame
)
788 # Settings below are used by default...
789 #clock.SetClockStyle(SHOW_HOURS_TICKS|SHOW_MINUTES_TICKS|SHOW_SHADOWS|ROTATE_TICKS)
790 #clock.SetTickStyles(TICKS_POLY, TICKS_CIRCLE)
792 frame
.Centre(wx
.BOTH
)
794 self
.SetTopWindow(frame
)