+ circle = 360
+ mStep = 6 * self.clockStep
+
+ if self.clockStyle & SHOW_SHADOWS:
+ for i in range(0, circle, mStep):
+ for t in self.coords.keys():
+ if t.find("ticks") > -1:
+ x,y,f = self._getCoords(t, i)
+ if f:
+ self._doDrawTickMark(i, drawDC, t,
+ x + self.shadowDistance,
+ y + self.shadowDistance,
+ True)
+
+ for i in range(0, circle, mStep):
+ for t in self.coords.keys():
+ if t.find("ticks") > -1:
+ x,y,f = self._getCoords(t, i)
+ if f:
+ self._doDrawTickMark(i, drawDC, t, x, y)
+
+
+
+ def _doDrawTickMark(self, angle, drawDC, tipo, x, y, is_a_shadow=None):
+ opts = {"ticks_hours": [self.tickMarkHoursPen, self.tickMarkHoursBrush, self.markSizeHour, self.tickMarkHoursStyle],
+ "ticks_quarters": [self.tickMarkHoursPen, self.tickMarkHoursBrush, self.markSizeHour, self.tickMarkHoursStyle],
+ "ticks_minutes": [self.tickMarkMinutesPen, self.tickMarkMinutesBrush, self.markSizeMin, self.tickMarkMinutesStyle]}
+
+ pen, brush, size, style = opts[tipo];
+ size = size * self.scale
+
+ if is_a_shadow:
+ drawDC.SetPen(wx.Pen(self.shadowPenColour, 1, wx.SOLID))
+ drawDC.SetBrush(wx.Brush(self.shadowBrushColour, wx.SOLID))
+ drawDC.SetTextForeground(self.shadowBrushColour)
+ else:
+ drawDC.SetPen(pen)
+ drawDC.SetBrush(brush)
+ drawDC.SetTextForeground(brush.GetColour())
+
+ if style & TICKS_CIRCLE:
+ x, y = self._center2corner(x, y, tipo)
+ drawDC.DrawEllipse((x, y), (int(size), int(size)))
+
+ elif style & TICKS_SQUARE:
+ x, y = self._center2corner(x, y, tipo)
+ drawDC.DrawRectangle((x, y), (int(size), int(size)))
+
+ elif (style & TICKS_DECIMAL) or (style & TICKS_ROMAN):
+ self._draw_rotate_text(drawDC, x, y, tipo, angle)
+
+ elif style & TICKS_POLY:
+ self._draw_rotate_polygon(drawDC, x, y, tipo, angle)
+
+
+ def _draw_rotate_text(self, drawDC, x, y, tipo, angle):
+ text = self._build_text(angle, tipo)
+ lX, lY = self._center2corner(x, y, tipo, drawDC)
+ lX = lX * len(text)
+ angle = 360 - angle
+
+ if self.clockStyle & ROTATE_TICKS:
+ radiansPerDegree = math.pi / 180
+ x = int(x -
+ ((math.cos((angle) * radiansPerDegree)*lX) +
+ (math.sin((angle) * radiansPerDegree)*lY)))
+ y = int(y -
+ ((math.cos((angle) * radiansPerDegree)*lY) -
+ (math.sin((angle) * radiansPerDegree)*lX)))
+ drawDC.DrawRotatedText(text, (x,y), angle)
+
+ else:
+ x = x - lX
+ y = y - lY
+ drawDC.DrawText(text, (x, y))
+
+
+ def _draw_rotate_polygon(self, drawDC, x, y, tipo, angle):
+ if tipo=="ticks_quarters":
+ tipo="ticks_hours"
+
+ # Add to empty list to prevent system-wide hard freezes under XP...
+ points = {"ticks_hours":self.tickShapeHours+[], "ticks_minutes":self.tickShapeMinutes+[]}[tipo]
+ size = self.scale * {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}[tipo]
+
+ maxX = max(map(lambda x:x[0],points))
+ minX = min(map(lambda x:x[0],points))
+ maxY = max(map(lambda x:x[0],points))
+ minY = min(map(lambda x:x[0],points))
+
+ maxB = abs(max(maxX, maxY));
+ f = size / maxB
+
+ orgX = (maxX - minX) / 2.
+ orgY = (maxY - minY) / 2.
+
+ radiansPerDegree = math.pi / 180
+ scaledX = x
+ scaledY = y
+
+ for z in range(0, len(points)):
+ x,y = points[z]
+ x = x * f - orgX * f
+ y = y * f - orgY * f
+ if self.clockStyle & ROTATE_TICKS:
+ m,t = self._rect2pol(x,y)
+ t = t + angle
+ x,y = self._pol2rect(m,t)
+ x = x + scaledX
+ y = y + scaledY
+ points[z] = [int(x), int(y)]
+
+ drawDC.DrawPolygon(points)
+
+
+ def _pol2rect(self, r, w, deg=1): # radian if deg=0; degree if deg=1
+ if deg:
+ w = math.pi * w / 180.0
+ return r * math.cos(w), r * math.sin(w)
+
+
+ def _rect2pol(self, x, y, deg=1): # radian if deg=0; degree if deg=1
+ if deg:
+ return math.hypot(x, y), 180.0 * math.atan2(y, x) / math.pi
+ else:
+ return math.hypot(x, y), math.atan2(y, x)
+
+
+ def _center2corner(self, x, y, tipo, drawDC=None):
+ if tipo == "ticks_quarters":
+ tipo = "ticks_hours"
+
+ style = {"ticks_hours":self.tickMarkHoursStyle, "ticks_minutes":self.tickMarkMinutesStyle}[tipo]
+ size = self.scale * {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}[tipo]
+
+ if style & TICKS_DECIMAL or style & TICKS_ROMAN:
+ font = {"ticks_hours":self.tickMarkHoursFont, "ticks_minutes":self.tickMarkMinutesFont}[tipo]
+ font.SetPointSize(int(size));
+ drawDC.SetFont(font)
+ lX = drawDC.GetCharWidth() / 2.
+ lY = drawDC.GetCharHeight() / 2.
+ x = lX
+ y = lY
+ else:
+ size = self.scale * {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}[tipo]
+ x=x-size/2.;y=y-size/2.
+ return x, y
+
+
+ def _build_text(self, angle, tipo):
+ if tipo == "ticks_quarters":
+ tipo = "ticks_hours"
+ a = angle
+ if a <= 0:
+ a = a + 360
+ divider = {"ticks_hours":30,"ticks_minutes":6}[tipo]
+ a = int(a / divider)
+
+ style = {"ticks_hours":self.tickMarkHoursStyle," ticks_minutes":self.tickMarkMinutesStyle}[tipo]
+ if style & TICKS_ROMAN:
+ text=["I","II","III","IV","V","VI","VII","VIII","IX","X", \
+ "XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX", \
+ "XXI","XXII","XXIII","XXIV","XXV","XXVI","XXVII","XXVIII","XXIX","XXX", \
+ "XXXI","XXXII","XXXIII","XXXIV","XXXV","XXXVI","XXXVII","XXXVIII","XXXIX","XL", \
+ "XLI","XLII","XLIII","XLIV","XLV","XLVI","XLVII","XLVIII","XLIX","L", \
+ "LI","LII","LIII","LIV","LV","LVI","LVII","LVIII","LIX","LX"][a-1]
+ else:
+ text = "%s" % a
+
+ return text
+
+
+ def _getMarkMaxSize(self, tipo, drawDC=None):
+ if tipo == "ticks_quarters":
+ tipo = "ticks_hours"
+
+ style = {"ticks_hours":self.tickMarkHoursStyle, "ticks_minutes":self.tickMarkMinutesStyle}[tipo]
+ size = self.scale * {"ticks_hours":self.markSizeHour, "ticks_minutes":self.markSizeMin}[tipo]
+
+ if style & TICKS_DECIMAL or style & TICKS_ROMAN:
+ lX = 2 * drawDC.GetCharWidth()
+ lY = drawDC.GetCharHeight()
+ size = math.sqrt(lX**2 + lY**2) * self.scale
+ else:
+ size=math.sqrt(2) * size
+
+ return size
+
+
+ def _drawWatch(self, drawDC):
+ # Draw the watch...
+ if self.watchPen or self.watchBrush:
+ if self.watchPen:
+ drawDC.SetPen(self.watchPen)
+ if self.watchBrush:
+ drawDC.SetBrush(self.watchBrush)
+ else:
+ drawDC.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
+ drawDC.DrawCircle((self.centerX, self.centerY), self.radius_watch)
+
+
+ def _calcSteps(self):
+ # Calcule todos os pontos para:
+ # - marcas de horas
+ # - marcas de minutos
+ # - ponteiro de horas
+ # - ponteiro de minutos
+ # - ponteiro de segundos
+
+ circle = 360
+ mStep = 6 * self.clockStep # Step in degrees...
+
+ vq = 90 * (self.clockStyle & SHOW_QUARTERS_TICKS) / SHOW_QUARTERS_TICKS
+ vh = 30 * (self.clockStyle & SHOW_HOURS_TICKS) / SHOW_HOURS_TICKS
+ vm = 1 * (self.clockStyle & SHOW_MINUTES_TICKS) / SHOW_MINUTES_TICKS
+
+ coords = {"ticks_quarters": [self.radius_ticks_hours, 60,vq,{}],
+ "ticks_hours": [self.radius_ticks_hours, 60,vh,{}],
+ "ticks_minutes": [self.radius_ticks_minutes,60,vm,{}],
+ "hand_hours": [self.handHoursLength, 60,1, {}],
+ "hand_minutes": [self.handMinutesLength, 60,1, {}],
+ "hand_seconds": [self.handSecondsLength, 60,1, {}]}
+
+ radiansPerDegree = math.pi / 180