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(1, 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 if hasattr(self
, 'coords'):
140 self
._doDrawHands
(dc
, True)
143 def OnTimerExpire(self
, event
):
144 size
= self
.GetClientSize()
145 dc
= wx
.BufferedDC(wx
.ClientDC(self
), size
)
146 self
._doDrawHands
(dc
, True)
149 def OnQuit(self
, event
):
154 def OnRightDown(self
, event
):
155 self
.x
= event
.GetX()
156 self
.y
= event
.GetY()
160 def OnRightClick(self
, event
):
161 # only do this part the first time so the events are only bound once
162 if not hasattr(self
, "popupID1"):
163 self
.popupID1
= wx
.NewId()
164 self
.popupID2
= wx
.NewId()
165 self
.Bind(wx
.EVT_MENU
, self
.OnPopupOne
, id=self
.popupID1
)
166 self
.Bind(wx
.EVT_MENU
, self
.OnPopupTwo
, id=self
.popupID2
)
171 sm
.Append(self
.popupID1
, "Customize...")
172 sm
.Append(self
.popupID2
, "About...")
174 # If there already a setup window open, we must not appear...
175 if not self
.prefs_open
:
176 # Popup the menu. If an item is selected then its handler
177 # will be called before PopupMenu returns.
178 self
.PopupMenu(sm
, (self
.x
,self
.y
))
182 def OnPopupOne(self
, event
):
184 frame
= ACCustomizationFrame(self
, -1, "AnalogClock Preferences")
188 def OnPopupTwo(self
, event
):
189 dlg
= wx
.MessageDialog(self
, "AnalogClockWindow\n\nby Several folks on wxPython-users\nwith enhancements from E. A. Tacão",
190 'About', wx
.OK | wx
.ICON_INFORMATION
)
195 def OnSize(self
, event
):
196 # The faceBitmap init is done here, to make sure the buffer is always
197 # the same size as the Window
198 size
= self
.GetClientSize()
199 if size
.x
< 1 or size
.y
< 1:
202 self
.faceBitmap
= wx
.EmptyBitmap(size
.width
, size
.height
)
204 # Update drawing coordinates...
206 if not hasattr(self
,"dim"):
210 self
.scale
= min([float(new_dim
[x
]) / self
.dim
[x
],
211 float(new_dim
[y
]) / self
.dim
[y
]])
213 self
.centerX
= self
.faceBitmap
.GetWidth() / 2
214 self
.centerY
= self
.faceBitmap
.GetHeight() / 2
216 self
.shadowDistance
= 2 * self
.scale
218 self
.radius_watch
= min(self
.centerX
, self
.centerY
)
224 def _doDrawHands(self
, drawDC
, force
=0):
225 currentTime
= list(time
.localtime(time
.time())[3:6])
227 if not (self
.handsStyle
& SHOW_SECONDS_HAND
):
230 if not (force
or currentTime
!= self
.currentTime
):
232 self
.currentTime
= currentTime
233 hour
, minutes
, seconds
= currentTime
235 # Start by drawing the face bitmap
236 drawDC
.DrawBitmap(self
.faceBitmap
, 0,0)
239 # NOTE: All this hand drawing code below should be refactored into a helper function.
242 # Draw hours hand shadow
243 mStep
= 6 * self
.clockStep
247 angle
= angle
+ round(minutes
/(mStep
*2)) * mStep
249 x
,y
,f
= self
._getCoords
("hand_hours", angle
)
251 if f
and self
.clockStyle
& SHOW_SHADOWS
:
252 drawDC
.SetPen(wx
.Pen(self
.shadowPenColour
,
253 int(self
.handHoursThickness
* self
.scale
),
255 drawDC
.DrawLine(self
.centerX
+ self
.shadowDistance
,
256 self
.centerY
+ self
.shadowDistance
,
257 x
+ self
.shadowDistance
,
258 y
+ self
.shadowDistance
)
260 # Draw minutes hand shadow
262 x
,y
,f
= self
._getCoords
("hand_minutes", angle
)
264 if f
and self
.clockStyle
& SHOW_SHADOWS
:
265 drawDC
.SetPen(wx
.Pen(self
.shadowPenColour
,
266 int(self
.handMinutesThickness
* self
.scale
),
268 drawDC
.DrawLine(self
.centerX
+ self
.shadowDistance
,
269 self
.centerY
+ self
.shadowDistance
,
270 x
+ self
.shadowDistance
,
271 y
+ self
.shadowDistance
)
273 # Draw seconds hand shadow if required
276 x
,y
,f
= self
._getCoords
("hand_seconds", angle
)
278 if f
and self
.clockStyle
& SHOW_SHADOWS
:
279 drawDC
.SetPen(wx
.Pen(self
.shadowPenColour
,
280 int(self
.handSecondsThickness
* self
.scale
),
282 drawDC
.DrawLine(self
.centerX
+ self
.shadowDistance
,
283 self
.centerY
+ self
.shadowDistance
,
284 x
+ self
.shadowDistance
,
285 y
+ self
.shadowDistance
)
292 angle
= angle
+ round(minutes
/(mStep
*2)) * mStep
294 x
,y
,f
= self
._getCoords
("hand_hours", angle
)
297 drawDC
.SetPen(wx
.Pen(self
.handHoursColour
,
298 int(self
.handHoursThickness
* self
.scale
),
300 drawDC
.DrawLine(self
.centerX
, self
.centerY
, x
, y
)
304 x
,y
,f
= self
._getCoords
("hand_minutes", angle
)
307 drawDC
.SetPen(wx
.Pen(self
.handMinutesColour
,
308 int(self
.handMinutesThickness
* self
.scale
),
310 drawDC
.DrawLine(self
.centerX
, self
.centerY
, x
, y
)
312 # Draw seconds hand if required
315 x
,y
,f
= self
._getCoords
("hand_seconds", angle
)
317 drawDC
.SetPen(wx
.Pen(self
.handSecondsColour
,
318 int(self
.handSecondsThickness
* self
.scale
),
320 drawDC
.DrawLine(self
.centerX
, self
.centerY
, x
, y
)
324 def _doDrawFace(self
):
325 backgroundBrush
= wx
.Brush(self
.GetBackgroundColour(), wx
.SOLID
)
326 drawDC
= wx
.MemoryDC()
327 drawDC
.SelectObject(self
.faceBitmap
)
328 drawDC
.SetBackground(backgroundBrush
)
331 self
.handHoursLength
= 0.65 * (self
.radius_watch
- self
._getMarkMaxSize
("ticks_hours", drawDC
))
332 self
.handMinutesLength
= 0.85 * (self
.radius_watch
- self
._getMarkMaxSize
("ticks_hours", drawDC
))
333 self
.handSecondsLength
= 0.85 * (self
.radius_watch
- self
._getMarkMaxSize
("ticks_hours", drawDC
))
335 self
.radius_ticks_hours
= self
.radius_watch
- self
.shadowDistance
- self
._getMarkMaxSize
("ticks_hours", drawDC
)
336 self
.radius_ticks_minutes
= self
.radius_ticks_hours
341 self
._drawWatch
(drawDC
)
343 # Draw the marks for hours and minutes...
345 mStep
= 6 * self
.clockStep
347 if self
.clockStyle
& SHOW_SHADOWS
:
348 for i
in range(0, circle
, mStep
):
349 for t
in self
.coords
.keys():
350 if t
.find("ticks") > -1:
351 x
,y
,f
= self
._getCoords
(t
, i
)
353 self
._doDrawTickMark
(i
, drawDC
, t
,
354 x
+ self
.shadowDistance
,
355 y
+ self
.shadowDistance
,
358 for i
in range(0, circle
, mStep
):
359 for t
in self
.coords
.keys():
360 if t
.find("ticks") > -1:
361 x
,y
,f
= self
._getCoords
(t
, i
)
363 self
._doDrawTickMark
(i
, drawDC
, t
, x
, y
)
367 def _doDrawTickMark(self
, angle
, drawDC
, tipo
, x
, y
, is_a_shadow
=None):
368 opts
= {"ticks_hours": [self
.tickMarkHoursPen
, self
.tickMarkHoursBrush
, self
.markSizeHour
, self
.tickMarkHoursStyle
],
369 "ticks_quarters": [self
.tickMarkHoursPen
, self
.tickMarkHoursBrush
, self
.markSizeHour
, self
.tickMarkHoursStyle
],
370 "ticks_minutes": [self
.tickMarkMinutesPen
, self
.tickMarkMinutesBrush
, self
.markSizeMin
, self
.tickMarkMinutesStyle
]}
372 pen
, brush
, size
, style
= opts
[tipo
];
373 size
= size
* self
.scale
376 drawDC
.SetPen(wx
.Pen(self
.shadowPenColour
, 1, wx
.SOLID
))
377 drawDC
.SetBrush(wx
.Brush(self
.shadowBrushColour
, wx
.SOLID
))
378 drawDC
.SetTextForeground(self
.shadowBrushColour
)
381 drawDC
.SetBrush(brush
)
382 drawDC
.SetTextForeground(brush
.GetColour())
384 if style
& TICKS_CIRCLE
:
385 x
, y
= self
._center
2corner
(x
, y
, tipo
)
386 drawDC
.DrawEllipse(x
, y
, size
, size
)
388 elif style
& TICKS_SQUARE
:
389 x
, y
= self
._center
2corner
(x
, y
, tipo
)
390 drawDC
.DrawRectangle(x
, y
, size
, size
)
392 elif (style
& TICKS_DECIMAL
) or (style
& TICKS_ROMAN
):
393 self
._draw
_rotate
_text
(drawDC
, x
, y
, tipo
, angle
)
395 elif style
& TICKS_POLY
:
396 self
._draw
_rotate
_polygon
(drawDC
, x
, y
, tipo
, angle
)
399 def _draw_rotate_text(self
, drawDC
, x
, y
, tipo
, angle
):
400 text
= self
._build
_text
(angle
, tipo
)
401 lX
, lY
= self
._center
2corner
(x
, y
, tipo
, drawDC
)
405 if self
.clockStyle
& ROTATE_TICKS
:
406 radiansPerDegree
= math
.pi
/ 180
408 ((math
.cos((angle
) * radiansPerDegree
)*lX
) +
409 (math
.sin((angle
) * radiansPerDegree
)*lY
)))
411 ((math
.cos((angle
) * radiansPerDegree
)*lY
) -
412 (math
.sin((angle
) * radiansPerDegree
)*lX
)))
413 drawDC
.DrawRotatedText(text
, x
,y
, angle
)
418 drawDC
.DrawText(text
, x
, y
)
421 def _draw_rotate_polygon(self
, drawDC
, x
, y
, tipo
, angle
):
422 if tipo
=="ticks_quarters":
425 # Add to empty list to prevent system-wide hard freezes under XP...
426 points
= {"ticks_hours":self.tickShapeHours+[], "ticks_minutes":self.tickShapeMinutes+[]}
[tipo
]
427 size
= self
.scale
* {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}
[tipo
]
429 maxX
= max(map(lambda x
:x
[0],points
))
430 minX
= min(map(lambda x
:x
[0],points
))
431 maxY
= max(map(lambda x
:x
[0],points
))
432 minY
= min(map(lambda x
:x
[0],points
))
434 maxB
= abs(max(maxX
, maxY
));
437 orgX
= (maxX
- minX
) / 2.
438 orgY
= (maxY
- minY
) / 2.
440 radiansPerDegree
= math
.pi
/ 180
444 for z
in range(0, len(points
)):
448 if self
.clockStyle
& ROTATE_TICKS
:
449 m
,t
= self
._rect
2pol
(x
,y
)
451 x
,y
= self
._pol
2rect
(m
,t
)
454 points
[z
] = [int(x
), int(y
)]
456 drawDC
.DrawPolygon(points
)
459 def _pol2rect(self
, r
, w
, deg
=1): # radian if deg=0; degree if deg=1
461 w
= math
.pi
* w
/ 180.0
462 return r
* math
.cos(w
), r
* math
.sin(w
)
465 def _rect2pol(self
, x
, y
, deg
=1): # radian if deg=0; degree if deg=1
467 return math
.hypot(x
, y
), 180.0 * math
.atan2(y
, x
) / math
.pi
469 return math
.hypot(x
, y
), math
.atan2(y
, x
)
472 def _center2corner(self
, x
, y
, tipo
, drawDC
=None):
473 if tipo
== "ticks_quarters":
476 style
= {"ticks_hours":self.tickMarkHoursStyle, "ticks_minutes":self.tickMarkMinutesStyle}
[tipo
]
477 size
= self
.scale
* {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}
[tipo
]
479 if style
& TICKS_DECIMAL
or style
& TICKS_ROMAN
:
480 font
= {"ticks_hours":self.tickMarkHoursFont, "ticks_minutes":self.tickMarkMinutesFont}
[tipo
]
481 font
.SetPointSize(int(size
));
483 lX
= drawDC
.GetCharWidth() / 2.
484 lY
= drawDC
.GetCharHeight() / 2.
488 size
= self
.scale
* {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}
[tipo
]
489 x
=x
-size
/2.;y
=y
-size
/2.
493 def _build_text(self
, angle
, tipo
):
494 if tipo
== "ticks_quarters":
499 divider
= {"ticks_hours":30,"ticks_minutes":6}
[tipo
]
502 style
= {"ticks_hours":self.tickMarkHoursStyle," ticks_minutes":self.tickMarkMinutesStyle}
[tipo
]
503 if style
& TICKS_ROMAN
:
504 text
=["I","II","III","IV","V","VI","VII","VIII","IX","X", \
505 "XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX", \
506 "XXI","XXII","XXIII","XXIV","XXV","XXVI","XXVII","XXVIII","XXIX","XXX", \
507 "XXXI","XXXII","XXXIII","XXXIV","XXXV","XXXVI","XXXVII","XXXVIII","XXXIX","XL", \
508 "XLI","XLII","XLIII","XLIV","XLV","XLVI","XLVII","XLVIII","XLIX","L", \
509 "LI","LII","LIII","LIV","LV","LVI","LVII","LVIII","LIX","LX"][a
-1]
516 def _getMarkMaxSize(self
, tipo
, drawDC
=None):
517 if tipo
== "ticks_quarters":
520 style
= {"ticks_hours":self.tickMarkHoursStyle, "ticks_minutes":self.tickMarkMinutesStyle}
[tipo
]
521 size
= self
.scale
* {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}
[tipo
]
523 if style
& TICKS_DECIMAL
or style
& TICKS_ROMAN
:
524 lX
= 2 * drawDC
.GetCharWidth()
525 lY
= drawDC
.GetCharHeight()
526 size
= math
.sqrt(lX
**2 + lY
**2) * self
.scale
528 size
=math
.sqrt(2) * size
533 def _drawWatch(self
, drawDC
):
535 if self
.watchPen
or self
.watchBrush
:
537 drawDC
.SetPen(self
.watchPen
)
539 drawDC
.SetBrush(self
.watchBrush
)
541 drawDC
.SetBrush(wx
.Brush(self
.GetBackgroundColour(), wx
.SOLID
))
542 drawDC
.DrawCircle(self
.centerX
, self
.centerY
, self
.radius_watch
)
545 def _calcSteps(self
):
546 # Calcule todos os pontos para:
548 # - marcas de minutos
549 # - ponteiro de horas
550 # - ponteiro de minutos
551 # - ponteiro de segundos
554 mStep
= 6 * self
.clockStep
# Step in degrees...
556 vq
= 90 * (self
.clockStyle
& SHOW_QUARTERS_TICKS
) / SHOW_QUARTERS_TICKS
557 vh
= 30 * (self
.clockStyle
& SHOW_HOURS_TICKS
) / SHOW_HOURS_TICKS
558 vm
= 1 * (self
.clockStyle
& SHOW_MINUTES_TICKS
) / SHOW_MINUTES_TICKS
560 coords
= {"ticks_quarters": [self.radius_ticks_hours, 60,vq,{}
],
561 "ticks_hours": [self
.radius_ticks_hours
, 60,vh
,{}],
562 "ticks_minutes": [self
.radius_ticks_minutes
,60,vm
,{}],
563 "hand_hours": [self
.handHoursLength
, 60,1, {}],
564 "hand_minutes": [self
.handMinutesLength
, 60,1, {}],
565 "hand_seconds": [self
.handSecondsLength
, 60,1, {}]}
567 radiansPerDegree
= math
.pi
/ 180
569 for t
in coords
.keys():
570 for i
in range(0, circle
+mStep
, mStep
):
571 radius
= coords
[t
][0]
572 if t
== "ticks_minutes":
573 radius
= radius
- self
.offM
574 step_angle
= 360. / coords
[t
][1]
576 x
= self
.centerX
+ radius
* math
.sin(i
* radiansPerDegree
)
577 y
= self
.centerY
+ radius
* math
.cos(i
* radiansPerDegree
)
578 f
= (pre
and (i
/step_angle
== int(i
/step_angle
)) and (float(i
)/pre
== int(i
/pre
)))
579 coords
[t
][3][i
] = [x
,y
,f
]
581 if not self
.clockStyle
& OVERLAP_TICKS
:
582 for i
in range(0, circle
+ mStep
, mStep
):
583 f
=coords
["ticks_minutes"][3][i
][2]
585 (coords
["ticks_hours"][3].get(i
,[0,0,0])[2] or coords
["ticks_quarters"][3].get(i
,[0,0,0])[2]):
587 coords
["ticks_minutes"][3][i
][2]=f
592 def _getCoords(self
, tipo
, angle
):
593 # Returns coords and 'use flag' based on current angle...
594 k
= 360 - (angle
+ 180)
597 return self
.coords
[tipo
][3][k
]
600 # -----------------------------------------------------
602 def SetTickShapes(self
, tsh
, tsm
=None):
604 tsh, tsm: [[x0,y0], [x1,y1], ... [xn,yn]]
606 Sets lists of lists of points to be used as polygon shapes
607 when using the TICKS_POLY style. If tsm is ommitted,
608 we'll use tsh for both shapes.
614 self
.tickShapeHours
= tsh
615 self
.tickShapeMinutes
= tsm
618 def SetHandWeights(self
, h
=None, m
=None, s
=None):
622 Sets thickness of hands.
626 self
.handHoursThickness
= h
628 self
.handMinutesThickness
= m
630 self
.handSecondsThickness
= s
633 def SetHandColours(self
, h
=None, m
=None, s
=None):
637 Sets colours of hands. If m and s are ommitted,
641 if h
and not m
and not s
:
646 self
.handHoursColour
= h
648 self
.handMinutesColour
= m
650 self
.handSecondsColour
= s
653 def SetTickColours(self
, h
=None, m
=None):
657 Sets colours of ticks. If m is ommitted,
658 we'll use h for both.
665 self
.tickMarkHoursPen
= wx
.Pen(h
, 1, wx
.SOLID
)
666 self
.tickMarkHoursBrush
= wx
.Brush(h
, wx
.SOLID
)
669 self
.tickMarkMinutesPen
= wx
.Pen(m
, 1, wx
.SOLID
)
670 self
.tickMarkMinutesBrush
= wx
.Brush(m
, wx
.SOLID
)
673 def SetTickSizes(self
, h
=None, m
=None):
677 Sizes for tick marks.
681 self
.markSizeHour
= h
686 def SetTickFonts(self
, h
=None, m
=None):
690 Fonts for tick marks when using TICKS_DECIMAL or TICKS_ROMAN style.
691 If m is ommitted, we'll use h for both.
698 self
.tickMarkHoursFont
= h
699 self
.tickMarkHoursFont
.SetPointSize(self
.markSizeHour
)
701 self
.tickMarkMinutesFont
= m
702 self
.tickMarkMinutesFont
.SetPointSize(self
.markSizeMin
)
705 def SetMinutesOffset(self
, o
):
709 Sets the distance between tick marks for hours and minutes.
714 def SetShadowColour(self
, s
):
716 s = wx.Colour or (r,g,b) tuple.
718 Sets the colour to be used to draw shadows.
721 self
.shadowPenColour
= self
.shadowBrushColour
= s
724 def SetWatchPenBrush(self
, p
=None, b
=None):
726 p = wx.Pen; b = wx.Brush
728 Set the pen and brush for the watch.
737 def SetClockStyle(self
, style
):
739 Set the clock style, acording to these options:
741 ==================== ================================
742 SHOW_QUARTERS_TICKS Show marks for hours 3, 6, 9, 12
743 SHOW_HOURS_TICKS Show marks for all hours
744 SHOW_MINUTES_TICKS Show marks for minutes
746 SHOW_HOURS_HAND Show hours hand
747 SHOW_MINUTES_HAND Show minutes hand
748 SHOW_SECONDS_HAND Show seconds hand
750 SHOW_SHADOWS Show hands and marks shadows
752 ROTATE_TICKS Align tick marks to watch
753 OVERLAP_TICKS Draw tick marks for minutes even
754 when they match the hours marks.
755 ==================== ================================
758 self
.clockStyle
= style
761 def SetTickStyles(self
, h
=None, m
=None):
763 Set the ticks styles, acording to the options below.
765 ================= =====================================
766 TICKS_NONE Don't show tick marks.
767 TICKS_SQUARE Use squares as tick marks.
768 TICKS_CIRCLE Use circles as tick marks.
769 TICKS_POLY Use a polygon as tick marks. The
770 polygon must be passed using
771 SetTickShapes, otherwise the default
772 polygon will be used.
773 TICKS_DECIMAL Use decimal numbers.
774 TICKS_ROMAN Use Roman numbers.
775 ================= =====================================
779 self
.tickMarkHoursStyle
= h
781 self
.tickMarkMinutesStyle
= m
783 # -----------------------------------------------------
786 if __name__
== "__main__":
787 print wx
.VERSION_STRING
790 frame
= wx
.Frame(None, -1, "AnalogClockWindow", size
=(375,375))
792 clock
= AnalogClockWindow(frame
)
794 # Settings below are used by default...
795 #clock.SetClockStyle(SHOW_HOURS_TICKS|SHOW_MINUTES_TICKS|SHOW_SHADOWS|ROTATE_TICKS)
796 #clock.SetTickStyles(TICKS_POLY, TICKS_CIRCLE)
798 frame
.Centre(wx
.BOTH
)
800 self
.SetTopWindow(frame
)