]>
Commit | Line | Data |
---|---|---|
1 | # -*- coding: iso-8859-1 -*- | |
2 | #---------------------------------------------------------------------- | |
3 | # Name: wx.lib.analogclock | |
4 | # Purpose: A simple analog clock window | |
5 | # | |
6 | # Author: several folks on wxPython-users | |
7 | # | |
8 | # Created: 16-April-2003 | |
9 | # RCS-ID: $Id$ | |
10 | # Copyright: (c) 2003 by Total Control Software | |
11 | # Licence: wxWindows license | |
12 | #---------------------------------------------------------------------- | |
13 | # 11/30/2003 - Jeff Grimmett (grimmtooth@softhome.net) | |
14 | # | |
15 | # o Updated for wx namespace | |
16 | # o Tested with updated demo and with builtin test. | |
17 | # | |
18 | # 15-February-2004 - E. A. Tacao | |
19 | # | |
20 | # o Many ehnacements | |
21 | # | |
22 | ||
23 | """ | |
24 | `AnalogClockWindow` is a simple analog clock class. | |
25 | """ | |
26 | ||
27 | import math | |
28 | import sys | |
29 | import string | |
30 | import time | |
31 | ||
32 | import wx | |
33 | ||
34 | from analogclockopts import ACCustomizationFrame | |
35 | ||
36 | ||
37 | # self.clockStyle: | |
38 | SHOW_QUARTERS_TICKS = 1 | |
39 | SHOW_HOURS_TICKS = 2 | |
40 | SHOW_MINUTES_TICKS = 4 | |
41 | ROTATE_TICKS = 8 | |
42 | SHOW_HOURS_HAND = 16 | |
43 | SHOW_MINUTES_HAND = 32 | |
44 | SHOW_SECONDS_HAND = 64 | |
45 | SHOW_SHADOWS = 128 | |
46 | OVERLAP_TICKS = 256 | |
47 | ||
48 | # self.tickMarkHoursStyle and self.tickMarkMinutesStyle: | |
49 | TICKS_NONE = 1 | |
50 | TICKS_SQUARE = 2 | |
51 | TICKS_CIRCLE = 4 | |
52 | TICKS_POLY = 8 | |
53 | TICKS_DECIMAL = 16 | |
54 | TICKS_ROMAN = 32 | |
55 | ||
56 | ||
57 | class AnalogClockWindow(wx.PyWindow): | |
58 | """An analog clock window""" | |
59 | ||
60 | def __init__(self, parent, ID=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, | |
61 | style=0, name="clock"): | |
62 | ||
63 | # Initialize the wxWindow... | |
64 | wx.PyWindow.__init__(self, parent, ID, pos, size, style, name) | |
65 | ||
66 | # Initialize some variables and defaults... | |
67 | self.clockStep = 1 | |
68 | self.prefs_open = False | |
69 | ||
70 | self.tickShapeHours = self.tickShapeMinutes= [[0,0], | |
71 | [1,-1], | |
72 | [2,0], | |
73 | [1,4]] | |
74 | self.handHoursThickness = 5 | |
75 | self.handHoursColour = (0, 0, 0) | |
76 | ||
77 | self.handMinutesThickness = 3 | |
78 | self.handMinutesColour = (0, 0, 0) | |
79 | ||
80 | self.handSecondsThickness = 1 | |
81 | self.handSecondsColour = (0, 0, 0) | |
82 | ||
83 | self.tickMarkHoursPen = wx.Pen((0, 0, 0), 1, wx.SOLID) | |
84 | self.tickMarkHoursBrush = wx.Brush((0, 0, 0), wx.SOLID) | |
85 | self.markSizeHour = 10 | |
86 | self.tickMarkHoursFont = wx.Font(1, wx.SWISS, wx.NORMAL, wx.BOLD) | |
87 | self.tickMarkHoursFont.SetPointSize(self.markSizeHour) | |
88 | ||
89 | self.tickMarkMinutesPen = wx.Pen((0, 0, 0), 1, wx.SOLID) | |
90 | self.tickMarkMinutesBrush = wx.Brush((0, 0, 0), wx.SOLID) | |
91 | self.markSizeMin = 6 | |
92 | self.tickMarkMinutesFont = wx.Font(self.markSizeMin, wx.SWISS, wx.NORMAL, wx.BOLD) | |
93 | ||
94 | self.offM = 0 | |
95 | ||
96 | self.shadowPenColour = self.shadowBrushColour = (128,128,128) | |
97 | ||
98 | self.watchPen = None | |
99 | self.watchBrush = None | |
100 | ||
101 | self.clockStyle = SHOW_HOURS_TICKS | SHOW_MINUTES_TICKS | SHOW_SHADOWS | ROTATE_TICKS | |
102 | self.handsStyle = SHOW_SECONDS_HAND | |
103 | ||
104 | self.tickMarkHoursStyle = TICKS_POLY | |
105 | self.tickMarkMinutesStyle = TICKS_CIRCLE | |
106 | ||
107 | self.currentTime=None | |
108 | ||
109 | size = wx.Size(*size) | |
110 | bestSize = self.GetBestSize() | |
111 | size.x = max(size.x, bestSize.x) | |
112 | size.y = max(size.y, bestSize.y) | |
113 | self.SetSize(size) | |
114 | ||
115 | # Make an initial bitmap for the face, it will be updated and | |
116 | # painted at the first EVT_SIZE event. | |
117 | W, H = size | |
118 | self.faceBitmap = wx.EmptyBitmap(max(W,1), max(H,1)) | |
119 | ||
120 | # Set event handlers... | |
121 | self.Bind(wx.EVT_PAINT, self.OnPaint) | |
122 | self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None) | |
123 | self.Bind(wx.EVT_SIZE, self.OnSize) | |
124 | self.Bind(wx.EVT_TIMER, self.OnTimerExpire) | |
125 | self.Bind(wx.EVT_WINDOW_DESTROY, self.OnQuit) | |
126 | self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown) | |
127 | self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick) | |
128 | ||
129 | # Initialize the timer that drives the update of the clock | |
130 | # face. Update every half second to ensure that there is at | |
131 | # least one true update during each realtime second. | |
132 | self.timer = wx.Timer(self) | |
133 | self.timer.Start(500) | |
134 | ||
135 | ||
136 | def DoGetBestSize(self): | |
137 | return wx.Size(25,25) | |
138 | ||
139 | ||
140 | def OnPaint(self, event): | |
141 | dc = wx.BufferedPaintDC(self) | |
142 | if hasattr(self, 'coords'): | |
143 | self._doDrawHands(dc, True) | |
144 | ||
145 | ||
146 | def OnTimerExpire(self, event): | |
147 | size = self.GetClientSize() | |
148 | dc = wx.BufferedDC(wx.ClientDC(self), size) | |
149 | self._doDrawHands(dc, True) | |
150 | ||
151 | ||
152 | def OnQuit(self, event): | |
153 | self.timer.Stop() | |
154 | del self.timer | |
155 | ||
156 | ||
157 | def OnRightDown(self, event): | |
158 | self.x = event.GetX() | |
159 | self.y = event.GetY() | |
160 | event.Skip() | |
161 | ||
162 | ||
163 | def OnRightClick(self, event): | |
164 | # only do this part the first time so the events are only bound once | |
165 | if not hasattr(self, "popupID1"): | |
166 | self.popupID1 = wx.NewId() | |
167 | self.popupID2 = wx.NewId() | |
168 | self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1) | |
169 | self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2) | |
170 | ||
171 | # make a menu | |
172 | sm = wx.Menu() | |
173 | ||
174 | sm.Append(self.popupID1, "Customize...") | |
175 | sm.Append(self.popupID2, "About...") | |
176 | ||
177 | # If there already a setup window open, we must not appear... | |
178 | if not self.prefs_open: | |
179 | # Popup the menu. If an item is selected then its handler | |
180 | # will be called before PopupMenu returns. | |
181 | self.PopupMenu(sm, (self.x,self.y)) | |
182 | sm.Destroy() | |
183 | ||
184 | ||
185 | def OnPopupOne(self, event): | |
186 | self.prefs_open=True | |
187 | frame = ACCustomizationFrame(self, -1, "AnalogClock Preferences") | |
188 | frame.Show(True) | |
189 | ||
190 | ||
191 | def OnPopupTwo(self, event): | |
192 | Content-type: text/html ]>