]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/analogclock/helpers.py
no need to use a throw-away bitmap, just use th eone built-in to the
[wxWidgets.git] / wxPython / wx / lib / analogclock / helpers.py
1 # AnalogClock's base classes
2 # E. A. Tacao <e.a.tacao |at| estadao.com.br>
3 # http://j.domaindlx.com/elements28/wxpython/
4 # 15 Fev 2006, 22:00 GMT-03:00
5 # Distributed under the wxWidgets license.
6
7 from time import strftime, localtime
8 import math
9 import wx
10
11 from styles import *
12
13 #----------------------------------------------------------------------
14
15 _targets = [HOUR, MINUTE, SECOND]
16
17 #----------------------------------------------------------------------
18
19 class Element:
20 """Base class for face, hands and tick marks."""
21
22 def __init__(self, idx=0, pos=None, size=None, offset=0, clocksize=None,
23 scale=1, rotate=False, kind=""):
24
25 self.idx = idx
26 self.pos = pos
27 self.size = size
28 self.offset = offset
29 self.clocksize = clocksize
30 self.scale = scale
31 self.rotate = rotate
32 self.kind = kind
33
34 self.text = None
35 self.angfac = [6, 30][self.kind == "hours"]
36
37
38 def _pol2rect(self, m, t):
39 return m * math.cos(math.radians(t)), m * math.sin(math.radians(t))
40
41
42 def _rect2pol(self, x, y):
43 return math.hypot(x, y), math.degrees(math.atan2(y, x))
44
45
46 def DrawRotated(self, dc, offset=0):
47 pass
48
49
50 def DrawStraight(self, dc, offset=0):
51 pass
52
53
54 def Draw(self, dc, offset=0):
55 if self.rotate:
56 self.DrawRotated(dc, offset)
57 else:
58 self.DrawStraight(dc, offset)
59
60
61 def RecalcCoords(self, clocksize, centre, scale):
62 pass
63
64
65 def GetSize(self):
66 return self.size
67
68
69 def GetOffset(self):
70 return self.offset
71
72
73 def GetIsRotated(self, rotate):
74 return self.rotate
75
76
77 def GetMaxSize(self, scale=1):
78 return self.size * scale
79
80
81 def GetScale(self):
82 return self.scale
83
84
85 def SetIsRotated(self, rotate):
86 self.rotate = rotate
87
88
89 def GetMaxSize(self, scale=1):
90 return self.size * scale
91
92
93 def GetPolygon(self):
94 return self.polygon
95
96
97 def SetPosition(self, pos):
98 self.pos = pos
99
100
101 def SetSize(self, size):
102 self.size = size
103
104
105 def SetOffset(self, offset):
106 self.offset = offset
107
108
109 def SetClockSize(self, clocksize):
110 self.clocksize = clocksize
111
112
113 def SetScale(self, scale):
114 self.scale = scale
115
116
117 def SetIsRotated(self, rotate):
118 self.rotate = rotate
119
120
121 def SetPolygon(self, polygon):
122 self.polygon = polygon
123
124 #----------------------------------------------------------------------
125
126 class ElementWithDyer(Element):
127 """Base class for clock face and hands."""
128
129 def __init__(self, **kwargs):
130 self.dyer = kwargs.pop("dyer", Dyer())
131 Element.__init__(self, **kwargs)
132
133
134 def GetFillColour(self):
135 return self.dyer.GetFillColour()
136
137
138 def GetBorderColour(self):
139 return self.dyer.GetBorderColour()
140
141
142 def GetBorderWidth(self):
143 return self.dyer.GetBorderWidth()
144
145
146 def GetShadowColour(self):
147 return self.dyer.GetShadowColour()
148
149
150 def SetFillColour(self, colour):
151 self.dyer.SetFillColour(colour)
152
153
154 def SetBorderColour(self, colour):
155 self.dyer.SetBorderColour(colour)
156
157
158 def SetBorderWidth(self, width):
159 self.dyer.SetBorderWidth(width)
160
161
162 def SetShadowColour(self, colour):
163 self.dyer.SetShadowColour(colour)
164
165 #----------------------------------------------------------------------
166
167 class Face(ElementWithDyer):
168 """Holds info about the clock face."""
169
170 def __init__(self, **kwargs):
171 ElementWithDyer.__init__(self, **kwargs)
172
173
174 def Draw(self, dc):
175 self.dyer.Select(dc)
176 dc.DrawCircle(self.pos.x, self.pos.y, self.radius)
177
178
179 def RecalcCoords(self, clocksize, centre, scale):
180 self.radius = min(clocksize.Get()) / 2. - self.dyer.width / 2.
181 self.pos = centre
182
183 #----------------------------------------------------------------------
184
185 class Hand(ElementWithDyer):
186 """Holds info about a clock hand."""
187
188 def __init__(self, **kwargs):
189 self.lenfac = kwargs.pop("lenfac")
190 ElementWithDyer.__init__(self, **kwargs)
191
192 self.SetPolygon([[-1, 0], [0, -1], [1, 0], [0, 4]])
193
194
195 def Draw(self, dc, end, offset=0):
196 radius, centre, r = end
197 angle = math.degrees(r)
198 polygon = self.polygon[:]
199 vscale = radius / max([y for x, y in polygon])
200
201 for i, (x, y) in enumerate(polygon):
202 x *= self.scale * self.size
203 y *= vscale * self.lenfac
204 m, t = self._rect2pol(x, y)
205 polygon[i] = self._pol2rect(m, t - angle)
206
207 dc.DrawPolygon(polygon, centre.x + offset, centre.y + offset)
208
209
210 def RecalcCoords(self, clocksize, centre, scale):
211 self.pos = centre
212 self.scale = scale
213
214 #----------------------------------------------------------------------
215
216 class TickSquare(Element):
217 """Holds info about a tick mark."""
218
219 def __init__(self, **kwargs):
220 Element.__init__(self, **kwargs)
221
222
223 def Draw(self, dc, offset=0):
224 width = height = self.size * self.scale
225 x = self.pos.x - width / 2.
226 y = self.pos.y - height / 2.
227
228 dc.DrawRectangle(x + offset, y + offset, width, height)
229
230 #----------------------------------------------------------------------
231
232 class TickCircle(Element):
233 """Holds info about a tick mark."""
234
235 def __init__(self, **kwargs):
236 Element.__init__(self, **kwargs)
237
238
239 def Draw(self, dc, offset=0):
240 radius = self.size * self.scale / 2.
241 x = self.pos.x
242 y = self.pos.y
243
244 dc.DrawCircle(x + offset, y + offset, radius)
245
246 #----------------------------------------------------------------------
247
248 class TickPoly(Element):
249 """Holds info about a tick mark."""
250
251 def __init__(self, **kwargs):
252 Element.__init__(self, **kwargs)
253
254 self.SetPolygon([[0, 1], [1, 0], [2, 1], [1, 5]])
255
256
257 def _calcPolygon(self):
258 width = max([x for x, y in self.polygon])
259 height = max([y for x, y in self.polygon])
260 tscale = self.size / max(width, height) * self.scale
261 polygon = [(x * tscale, y * tscale) for x, y in self.polygon]
262
263 width = max([x for x, y in polygon])
264 height = max([y for x, y in polygon])
265
266 return polygon, width, height
267
268
269 def DrawStraight(self, dc, offset=0):
270 polygon, width, height = self._calcPolygon()
271
272 x = self.pos.x - width / 2.
273 y = self.pos.y - height / 2.
274
275 dc.DrawPolygon(polygon, x + offset, y + offset)
276
277
278 def DrawRotated(self, dc, offset=0):
279 polygon, width, height = self._calcPolygon()
280
281 angle = 360 - self.angfac * (self.idx + 1)
282 r = math.radians(angle)
283
284 for i in range(len(polygon)):
285 m, t = self._rect2pol(*polygon[i])
286 t -= angle
287 polygon[i] = self._pol2rect(m, t)
288
289 x = self.pos.x - math.cos(r) * width / 2. - math.sin(r) * height / 2.
290 y = self.pos.y - math.cos(r) * height / 2. + math.sin(r) * width / 2.
291
292 dc.DrawPolygon(polygon, x + offset, y + offset)
293
294 #----------------------------------------------------------------------
295
296 class TickDecimal(Element):
297 """Holds info about a tick mark."""
298
299 def __init__(self, **kwargs):
300 Element.__init__(self, **kwargs)
301
302 self.text = "%s" % (self.idx + 1)
303
304
305 def DrawStraight(self, dc, offset=0):
306 width, height = dc.GetTextExtent(self.text)
307
308 x = self.pos.x - width / 2.
309 y = self.pos.y - height / 2.
310
311 dc.DrawText(self.text, x + offset, y + offset)
312
313
314 def DrawRotated(self, dc, offset=0):
315 width, height = dc.GetTextExtent(self.text)
316
317 angle = 360 - self.angfac * (self.idx + 1)
318 r = math.radians(angle)
319
320 x = self.pos.x - math.cos(r) * width / 2. - math.sin(r) * height / 2.
321 y = self.pos.y - math.cos(r) * height / 2. + math.sin(r) * width / 2.
322
323 dc.DrawRotatedText(self.text, x + offset, y + offset, angle)
324
325
326 #----------------------------------------------------------------------
327
328 class TickRoman(TickDecimal):
329 """Holds info about a tick mark."""
330
331 def __init__(self, **kwargs):
332 TickDecimal.__init__(self, **kwargs)
333
334 self.text = ["I","II","III","IV","V", \
335 "VI","VII","VIII","IX","X", \
336 "XI","XII","XIII","XIV","XV", \
337 "XVI","XVII","XVIII","XIX","XX", \
338 "XXI","XXII","XXIII","XXIV","XXV", \
339 "XXVI","XXVII","XXVIII","XXIX","XXX", \
340 "XXXI","XXXII","XXXIII","XXXIV","XXXV", \
341 "XXXVI","XXXVII","XXXVIII","XXXIX","XL", \
342 "XLI","XLII","XLIII","XLIV","XLV", \
343 "XLVI","XLVII","XLVIII","XLIX","L", \
344 "LI","LII","LIII","LIV","LV", \
345 "LVI","LVII","LVIII","LIX","LX"][self.idx]
346
347 #----------------------------------------------------------------------
348
349 class TickBinary(TickDecimal):
350 """Holds info about a tick mark."""
351
352 def __init__(self, **kwargs):
353 TickDecimal.__init__(self, **kwargs)
354
355 def d2b(n, b=""):
356 while n > 0:
357 b = str(n % 2) + b; n = n >> 1
358 return b.zfill(4)
359
360 self.text = d2b(self.idx + 1)
361
362 #----------------------------------------------------------------------
363
364 class TickHex(TickDecimal):
365 """Holds info about a tick mark."""
366
367 def __init__(self, **kwargs):
368 TickDecimal.__init__(self, **kwargs)
369
370 self.text = hex(self.idx + 1)[2:].upper()
371
372 #----------------------------------------------------------------------
373
374 class TickNone(Element):
375 """Holds info about a tick mark."""
376
377 def __init__(self, **kwargs):
378 Element.__init__(self, **kwargs)
379
380
381 def Draw(self, dc, offset=0):
382 pass
383
384 #----------------------------------------------------------------------
385
386 class Dyer:
387 """Stores info about colours and borders of clock Elements."""
388
389 def __init__(self, border=None, width=0, fill=None, shadow=None):
390 """
391 self.border (wx.Colour) border colour
392 self.width (int) border width
393 self.fill (wx.Colour) fill colour
394 self.shadow (wx.Colour) shadow colour
395 """
396
397 self.border = border or \
398 wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
399 self.fill = fill or \
400 wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT)
401 self.shadow = shadow or \
402 wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DSHADOW)
403 self.width = width
404
405
406 def Select(self, dc, shadow=False):
407 """Selects the current settings into the dc."""
408
409 if not shadow:
410 dc.SetPen(wx.Pen(self.border, self.width, wx.SOLID))
411 dc.SetBrush(wx.Brush(self.fill, wx.SOLID))
412 dc.SetTextForeground(self.fill)
413 else:
414 dc.SetPen(wx.Pen(self.shadow, self.width, wx.SOLID))
415 dc.SetBrush(wx.Brush(self.shadow, wx.SOLID))
416 dc.SetTextForeground(self.shadow)
417
418
419 def GetFillColour(self):
420 return self.fill
421
422
423 def GetBorderColour(self):
424 return self.border
425
426
427 def GetBorderWidth(self):
428 return self.width
429
430
431 def GetShadowColour(self):
432 return self.shadow
433
434
435 def SetFillColour(self, colour):
436 self.fill = colour
437
438
439 def SetBorderColour(self, colour):
440 self.border = colour
441
442
443 def SetBorderWidth(self, width):
444 self.width = width
445
446
447 def SetShadowColour(self, colour):
448 self.shadow = colour
449
450 #----------------------------------------------------------------------
451
452 class HandSet:
453 """Manages the set of hands."""
454
455 def __init__(self, parent, h, m, s):
456 self.parent = parent
457
458 self.hands = [h, m, s]
459 self.radius = 1
460 self.centre = wx.Point(1, 1)
461
462
463 def _draw(self, dc, shadow=False):
464 ends = [int(x) for x in strftime("%I %M %S", localtime()).split()]
465
466 flags = [self.parent.clockStyle & flag \
467 for flag in self.parent.allHandStyles]
468
469 a_hand = self.hands[0]
470
471 if shadow:
472 offset = self.parent.shadowOffset * a_hand.GetScale()
473 else:
474 offset = 0
475
476 for i, hand in enumerate(self.hands):
477 # Is this hand supposed to be drawn?
478 if flags[i]:
479 idx = ends[i]
480 # Is this the hours hand?
481 if i == 0:
482 idx = idx * 5 + ends[1] / 12 - 1
483 # else prevent exceptions on leap seconds
484 elif idx <= 0 or idx > 60:
485 idx = 59
486 # and adjust idx offset for minutes and non-leap seconds
487 else:
488 idx = idx - 1
489 angle = math.radians(180 - 6 * (idx + 1))
490
491 hand.dyer.Select(dc, shadow)
492 hand.Draw(dc, (self.radius, self.centre, angle), offset)
493
494
495 def Draw(self, dc):
496 if self.parent.clockStyle & SHOW_SHADOWS:
497 self._draw(dc, True)
498 self._draw(dc)
499
500
501 def RecalcCoords(self, clocksize, centre, scale):
502 self.centre = centre
503 [hand.RecalcCoords(clocksize, centre, scale) for hand in self.hands]
504
505
506 def SetMaxRadius(self, radius):
507 self.radius = radius
508
509
510 def GetSize(self, target):
511 r = []
512 for i, hand in enumerate(self.hands):
513 if _targets[i] & target:
514 r.append(hand.GetSize())
515 return tuple(r)
516
517
518 def GetFillColour(self, target):
519 r = []
520 for i, hand in enumerate(self.hands):
521 if _targets[i] & target:
522 r.append(hand.GetFillColour())
523 return tuple(r)
524
525
526 def GetBorderColour(self, target):
527 r = []
528 for i, hand in enumerate(self.hands):
529 if _targets[i] & target:
530 r.append(hand.GetBorderColour())
531 return tuple(r)
532
533
534 def GetBorderWidth(self, target):
535 r = []
536 for i, hand in enumerate(self.hands):
537 if _targets[i] & target:
538 r.append(hand.GetBorderWidth())
539 return tuple(r)
540
541
542 def GetShadowColour(self):
543 r = []
544 for i, hand in enumerate(self.hands):
545 if _targets[i] & target:
546 r.append(hand.GetShadowColour())
547 return tuple(r)
548
549
550 def SetSize(self, size, target):
551 for i, hand in enumerate(self.hands):
552 if _targets[i] & target:
553 hand.SetSize(size)
554
555
556 def SetFillColour(self, colour, target):
557 for i, hand in enumerate(self.hands):
558 if _targets[i] & target:
559 hand.SetFillColour(colour)
560
561
562 def SetBorderColour(self, colour, target):
563 for i, hand in enumerate(self.hands):
564 if _targets[i] & target:
565 hand.SetBorderColour(colour)
566
567
568 def SetBorderWidth(self, width, target):
569 for i, hand in enumerate(self.hands):
570 if _targets[i] & target:
571 hand.SetBorderWidth(width)
572
573
574 def SetShadowColour(self, colour):
575 for i, hand in enumerate(self.hands):
576 hand.SetShadowColour(colour)
577
578 #----------------------------------------------------------------------
579
580 class TickSet:
581 """Manages a set of tick marks."""
582
583 def __init__(self, parent, **kwargs):
584 self.parent = parent
585 self.dyer = Dyer()
586 self.noe = {"minutes": 60, "hours": 12}[kwargs["kind"]]
587 self.font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
588
589 style = kwargs.pop("style")
590 self.kwargs = kwargs
591 self.SetStyle(style)
592
593
594 def _draw(self, dc, shadow=False):
595 dc.SetFont(self.font)
596
597 a_tick = self.ticks[0]
598
599 if shadow:
600 offset = self.parent.shadowOffset * a_tick.GetScale()
601 else:
602 offset = 0
603
604 clockStyle = self.parent.clockStyle
605
606 for idx, tick in self.ticks.items():
607 draw = False
608
609 # Are we a set of hours?
610 if self.noe == 12:
611 # Should we show all hours ticks?
612 if clockStyle & SHOW_HOURS_TICKS:
613 draw = True
614 # Or is this tick a quarter and should we show only quarters?
615 elif clockStyle & SHOW_QUARTERS_TICKS and not (idx + 1) % 3.:
616 draw = True
617 # Are we a set of minutes and minutes should be shown?
618 elif self.noe == 60 and clockStyle & SHOW_MINUTES_TICKS:
619 # If this tick occupies the same position of an hour/quarter
620 # tick, should we still draw it anyway?
621 if clockStyle & OVERLAP_TICKS:
622 draw = True
623 # Right, sir. I promise I won't overlap any tick.
624 else:
625 # Ensure that this tick won't overlap an hour tick.
626 if clockStyle & SHOW_HOURS_TICKS:
627 if (idx + 1) % 5.:
628 draw = True
629 # Ensure that this tick won't overlap a quarter tick.
630 elif clockStyle & SHOW_QUARTERS_TICKS:
631 if (idx + 1) % 15.:
632 draw = True
633 # We're not drawing quarters nor hours, so we can draw all
634 # minutes ticks.
635 else:
636 draw = True
637
638 if draw:
639 tick.Draw(dc, offset)
640
641
642 def Draw(self, dc):
643 if self.parent.clockStyle & SHOW_SHADOWS:
644 self.dyer.Select(dc, True)
645 self._draw(dc, True)
646 self.dyer.Select(dc)
647 self._draw(dc)
648
649
650 def RecalcCoords(self, clocksize, centre, scale):
651 a_tick = self.ticks[0]
652
653 size = a_tick.GetMaxSize(scale)
654 maxsize = size
655
656 # Try to find a 'good' max size for text-based ticks.
657 if a_tick.text is not None:
658 self.font.SetPointSize(size)
659 dc = wx.MemoryDC()
660 dc.SelectObject(wx.EmptyBitmap(*clocksize.Get()))
661 dc.SetFont(self.font)
662 maxsize = size
663 for tick in self.ticks.values():
664 maxsize = max(*(dc.GetTextExtent(tick.text) + (maxsize,)))
665
666 radius = self.radius = min(clocksize.Get()) / 2. - \
667 self.dyer.width / 2. - \
668 maxsize / 2. - \
669 a_tick.GetOffset() * scale - \
670 self.parent.shadowOffset * scale
671
672 # If we are a set of hours, the number of elements of this tickset is
673 # 12 and ticks are separated by a distance of 30 degrees;
674 # if we are a set of minutes, the number of elements of this tickset is
675 # 60 and ticks are separated by a distance of 6 degrees.
676 angfac = [6, 30][self.noe == 12]
677
678 for i, tick in self.ticks.items():
679 tick.SetClockSize(clocksize)
680 tick.SetScale(scale)
681
682 deg = 180 - angfac * (i + 1)
683 angle = math.radians(deg)
684
685 x = centre.x + radius * math.sin(angle)
686 y = centre.y + radius * math.cos(angle)
687
688 tick.SetPosition(wx.Point(x, y))
689
690
691 def GetSize(self):
692 return self.kwargs["size"]
693
694
695 def GetFillColour(self):
696 return self.dyer.GetFillColour()
697
698
699 def GetBorderColour(self):
700 return self.dyer.GetBorderColour()
701
702
703 def GetBorderWidth(self):
704 return self.dyer.GetBorderWidth()
705
706
707 def GetPolygon(self):
708 a_tick = self.ticks.values()[0]
709 return a_tick.GetPolygon()
710
711
712 def GetFont(self):
713 return self.font
714
715
716 def GetOffset(self):
717 a_tick = self.ticks[0]
718 return a_tick.GetOffset()
719
720
721 def GetShadowColour(self):
722 return self.dyer.GetShadowColour()
723
724
725 def GetIsRotated(self):
726 a_tick = self.ticks[0]
727 return a_tick.GetIsRotated()
728
729
730 def GetStyle(self):
731 return self.style
732
733
734 def SetSize(self, size):
735 self.kwargs["size"] = size
736 [tick.SetSize(size) for tick in self.ticks.values()]
737
738
739 def SetFillColour(self, colour):
740 self.dyer.SetFillColour(colour)
741
742
743 def SetBorderColour(self, colour):
744 self.dyer.SetBorderColour(colour)
745
746
747 def SetBorderWidth(self, width):
748 self.dyer.SetBorderWidth(width)
749
750
751 def SetPolygon(self, polygon):
752 [tick.SetPolygon(polygon) for tick in self.ticks.values()]
753
754
755 def SetFont(self, font):
756 self.font = font
757
758
759 def SetOffset(self, offset):
760 self.kwargs["offset"] = offset
761 [tick.SetOffset(offset) for tick in self.ticks.values()]
762
763
764 def SetShadowColour(self, colour):
765 self.dyer.SetShadowColour(colour)
766
767
768 def SetIsRotated(self, rotate):
769 self.kwargs["rotate"] = rotate
770 [tick.SetIsRotated(rotate) for tick in self.ticks.values()]
771
772
773 def SetStyle(self, style):
774 self.style = style
775 tickclass = allTickStyles[style]
776 self.kwargs["rotate"] = self.parent.clockStyle & ROTATE_TICKS
777
778 self.ticks = {}
779 for i in range(self.noe):
780 self.kwargs["idx"] = i
781 self.ticks[i] = tickclass(**self.kwargs)
782
783 #----------------------------------------------------------------------
784
785 class Box:
786 """Gathers info about the clock face and tick sets."""
787
788 def __init__(self, parent, Face, TicksM, TicksH):
789 self.parent = parent
790 self.Face = Face
791 self.TicksH = TicksH
792 self.TicksM = TicksM
793
794
795 def GetNiceRadiusForHands(self, centre):
796 a_tick = self.TicksM.ticks[0]
797 scale = a_tick.GetScale()
798 bw = max(self.TicksH.dyer.width / 2. * scale,
799 self.TicksM.dyer.width / 2. * scale)
800
801 mgt = self.TicksM.ticks[59]
802 my = mgt.pos.y + mgt.GetMaxSize(scale) + bw
803
804 hgt = self.TicksH.ticks[11]
805 hy = hgt.pos.y + hgt.GetMaxSize(scale) + bw
806
807 niceradius = centre.y - max(my, hy)
808 return niceradius
809
810
811 def Draw(self, dc):
812 [getattr(self, attr).Draw(dc) \
813 for attr in ["Face", "TicksM", "TicksH"]]
814
815
816 def RecalcCoords(self, size, centre, scale):
817 [getattr(self, attr).RecalcCoords(size, centre, scale) \
818 for attr in ["Face", "TicksH", "TicksM"]]
819
820
821 def GetTickSize(self, target):
822 r = []
823 for i, attr in enumerate(["TicksH", "TicksM"]):
824 if _targets[i] & target:
825 tick = getattr(self, attr)
826 r.append(tick.GetSize())
827 return tuple(r)
828
829
830 def GetTickFillColour(self, target):
831 r = []
832 for i, attr in enumerate(["TicksH", "TicksM"]):
833 if _targets[i] & target:
834 tick = getattr(self, attr)
835 r.append(tick.GetFillColour())
836 return tuple(r)
837
838
839 def GetTickBorderColour(self, target):
840 r = []
841 for i, attr in enumerate(["TicksH", "TicksM"]):
842 if _targets[i] & target:
843 tick = getattr(self, attr)
844 r.append(tick.GetBorderColour())
845 return tuple(r)
846
847
848 def GetTickBorderWidth(self, target):
849 r = []
850 for i, attr in enumerate(["TicksH", "TicksM"]):
851 if _targets[i] & target:
852 tick = getattr(self, attr)
853 r.append(tick.GetBorderWidth())
854 return tuple(r)
855
856
857 def GetTickPolygon(self, target):
858 r = []
859 for i, attr in enumerate(["TicksH", "TicksM"]):
860 if _targets[i] & target:
861 tick = getattr(self, attr)
862 r.append(tick.GetPolygon())
863 return tuple(r)
864
865
866 def GetTickFont(self, target):
867 r = []
868 for i, attr in enumerate(["TicksH", "TicksM"]):
869 if _targets[i] & target:
870 tick = getattr(self, attr)
871 r.append(tick.GetFont())
872 return tuple(r)
873
874
875 def GetIsRotated(self):
876 a_tickset = self.TicksH
877 return a_tickset.GetIsRotated()
878
879
880 def GetTickOffset(self, target):
881 r = []
882 for i, attr in enumerate(["TicksH", "TicksM"]):
883 if _targets[i] & target:
884 tick = getattr(self, attr)
885 r.append(tick.GetOffset())
886 return tuple(r)
887
888
889 def GetShadowColour(self):
890 a_tickset = self.TicksH
891 return a_tickset.GetShadowColour()
892
893
894 def GetTickStyle(self, target):
895 r = []
896 for i, attr in enumerate(["TicksH", "TicksM"]):
897 if _targets[i] & target:
898 tick = getattr(self, attr)
899 r.append(tick.GetStyle())
900 return tuple(r)
901
902
903 def SetTickSize(self, size, target):
904 for i, attr in enumerate(["TicksH", "TicksM"]):
905 if _targets[i] & target:
906 tick = getattr(self, attr)
907 tick.SetSize(size)
908
909
910 def SetTickFillColour(self, colour, target):
911 for i, attr in enumerate(["TicksH", "TicksM"]):
912 if _targets[i] & target:
913 tick = getattr(self, attr)
914 tick.SetFillColour(colour)
915
916
917 def SetTickBorderColour(self, colour, target):
918 for i, attr in enumerate(["TicksH", "TicksM"]):
919 if _targets[i] & target:
920 tick = getattr(self, attr)
921 tick.SetBorderColour(colour)
922
923
924 def SetTickBorderWidth(self, width, target):
925 for i, attr in enumerate(["TicksH", "TicksM"]):
926 if _targets[i] & target:
927 tick = getattr(self, attr)
928 tick.SetBorderWidth(width)
929
930
931 def SetTickPolygon(self, polygon, target):
932 for i, attr in enumerate(["TicksH", "TicksM"]):
933 if _targets[i] & target:
934 tick = getattr(self, attr)
935 tick.SetPolygon(polygon)
936
937
938 def SetTickFont(self, font, target):
939 fs = font.GetNativeFontInfoDesc()
940 for i, attr in enumerate(["TicksH", "TicksM"]):
941 if _targets[i] & target:
942 tick = getattr(self, attr)
943 tick.SetFont(wx.FontFromNativeInfoString(fs))
944
945
946 def SetIsRotated(self, rotate):
947 [getattr(self, attr).SetIsRotated(rotate) \
948 for attr in ["TicksH", "TicksM"]]
949
950
951 def SetTickOffset(self, offset, target):
952 for i, attr in enumerate(["TicksH", "TicksM"]):
953 if _targets[i] & target:
954 tick = getattr(self, attr)
955 tick.SetOffset(offset)
956
957
958 def SetShadowColour(self, colour):
959 for attr in ["TicksH", "TicksM"]:
960 tick = getattr(self, attr)
961 tick.SetShadowColour(colour)
962
963
964 def SetTickStyle(self, style, target):
965 for i, attr in enumerate(["TicksH", "TicksM"]):
966 if _targets[i] & target:
967 tick = getattr(self, attr)
968 tick.SetStyle(style)
969
970 #----------------------------------------------------------------------
971
972 # Relationship between styles and ticks class names.
973 allTickStyles = {TICKS_BINARY: TickBinary,
974 TICKS_CIRCLE: TickCircle,
975 TICKS_DECIMAL: TickDecimal,
976 TICKS_HEX: TickHex,
977 TICKS_NONE: TickNone,
978 TICKS_POLY: TickPoly,
979 TICKS_ROMAN: TickRoman,
980 TICKS_SQUARE: TickSquare}
981
982
983 #
984 ##
985 ### eof