📄 analogclock.py
字号:
return self.clockStyle
def GetTickStyle(self, target=ALL):
"""Gets the tick style(s)."""
return self.Box.GetTickStyle(target)
def Refresh(self):
"""
Overriden base wx.Window method. Forces an immediate
recalculation and redraw of all clock elements.
"""
size = self.GetClientSize()
if size.x < 1 or size.y < 1:
return
self.Freeze()
self.RecalcCoords(size)
self.DrawBox()
dc = wx.BufferedDC(wx.ClientDC(self), self.GetClientSize())
self.DrawHands(dc)
self.Thaw()
def SetHandSize(self, size, target=ALL):
"""Sets thickness of hands."""
self.Hands.SetSize(size, target)
def SetHandFillColour(self, colour, target=ALL):
"""Sets fill colours of hands."""
self.Hands.SetFillColour(colour, target)
def SetHandBorderColour(self, colour, target=ALL):
"""Sets border colours of hands."""
self.Hands.SetBorderColour(colour, target)
def SetHandBorderWidth(self, width, target=ALL):
"""Sets border widths of hands."""
self.Hands.SetBorderWidth(width, target)
def SetTickSize(self, size, target=ALL):
"""Sets sizes of ticks."""
self.Box.SetTickSize(size, target)
self.Refresh()
def SetTickFillColour(self, colour, target=ALL):
"""Sets fill colours of ticks."""
self.Box.SetTickFillColour(colour, target)
self.Refresh()
def SetTickBorderColour(self, colour, target=ALL):
"""Sets border colours of ticks."""
self.Box.SetTickBorderColour(colour, target)
self.Refresh()
def SetTickBorderWidth(self, width, target=ALL):
"""Sets border widths of ticks."""
self.Box.SetTickBorderWidth(width, target)
self.Refresh()
def SetTickPolygon(self, polygon, target=ALL):
"""
Sets lists of points to be used as polygon shapes
when using the TICKS_POLY style.
"""
self.Box.SetTickPolygon(polygon, target)
self.Refresh()
def SetTickFont(self, font, target=ALL):
"""
Sets fonts for tick marks when using text-based tick styles
such as TICKS_DECIMAL or TICKS_ROMAN.
"""
self.Box.SetTickFont(font, target)
self.Refresh()
def SetTickOffset(self, offset, target=ALL):
"""Sets the distance of tick marks for hours from border."""
self.Box.SetTickOffset(offset, target)
self.Refresh()
def SetFaceFillColour(self, colour):
"""Sets fill colours of watch."""
self.Box.Face.SetFillColour(colour)
self.Refresh()
def SetFaceBorderColour(self, colour):
"""Sets border colours of watch."""
self.Box.Face.SetBorderColour(colour)
self.Refresh()
def SetFaceBorderWidth(self, width):
"""Sets border width of watch."""
self.Box.Face.SetBorderWidth(width)
self.Refresh()
def SetShadowColour(self, colour):
"""Sets the colour to be used to draw shadows."""
self.Hands.SetShadowColour(colour)
self.Box.SetShadowColour(colour)
self.Refresh()
def SetClockStyle(self, style):
"""
Set the clock style, according to the options below.
==================== ================================
SHOW_QUARTERS_TICKS Show marks for hours 3, 6, 9, 12
SHOW_HOURS_TICKS Show marks for all hours
SHOW_MINUTES_TICKS Show marks for minutes
SHOW_HOURS_HAND Show hours hand
SHOW_MINUTES_HAND Show minutes hand
SHOW_SECONDS_HAND Show seconds hand
SHOW_SHADOWS Show hands and marks shadows
ROTATE_TICKS Align tick marks to watch
OVERLAP_TICKS Draw tick marks for minutes even
when they match the hours marks.
==================== ================================
"""
self.clockStyle = style
self.Box.SetIsRotated(style & ROTATE_TICKS)
self.Refresh()
def SetTickStyle(self, style, target=ALL):
"""
Set the tick style, according to the options below.
================= ======================================
TICKS_NONE Don't show tick marks.
TICKS_SQUARE Use squares as tick marks.
TICKS_CIRCLE Use circles as tick marks.
TICKS_POLY Use a polygon as tick marks. A
polygon can be passed using
SetTickPolygon, otherwise the default
polygon will be used.
TICKS_DECIMAL Use decimal numbers as tick marks.
TICKS_ROMAN Use Roman numbers as tick marks.
TICKS_BINARY Use binary numbers as tick marks.
TICKS_HEX Use hexadecimal numbers as tick marks.
================= ======================================
"""
self.Box.SetTickStyle(style, target)
self.Refresh()
def SetBackgroundColour(self, colour):
"""Overriden base wx.Window method."""
wx.Window.SetBackgroundColour(self, colour)
self.Refresh()
def SetForegroundColour(self, colour):
"""
Overriden base wx.Window method. This method sets a colour for
all hands and ticks at once.
"""
wx.Window.SetForegroundColour(self, colour)
self.SetHandFillColour(colour)
self.SetHandBorderColour(colour)
self.SetTickFillColour(colour)
self.SetTickBorderColour(colour)
self.Refresh()
def SetWindowStyle(self, *args, **kwargs):
"""Overriden base wx.Window method."""
size = self.GetSize()
self.Freeze()
wx.Window.SetWindowStyle(self, *args, **kwargs)
self.SetSize((10, 10))
self.SetSize(size)
self.Thaw()
def SetWindowStyleFlag(self, *args, **kwargs):
"""Overriden base wx.Window method."""
self.SetWindowStyle(*args, **kwargs)
# For backwards compatibility -----------------------------------------
class AnalogClockWindow(AnalogClock):
"""
A simple derived class that provides some backwards compatibility
with the old analogclock module.
"""
def SetTickShapes(self, tsh, tsm=None):
self.SetTickPolygon(tsh)
def SetHandWeights(self, h=None, m=None, s=None):
if h:
self.SetHandSize(h, HOUR)
if m:
self.SetHandSize(m, MINUTE)
if s:
self.SetHandSize(h, SECOND)
def SetHandColours(self, h=None, m=None, s=None):
if h and not m and not s:
m=h
s=h
if h:
self.SetHandBorderColour(h, HOUR)
self.SetHandFillColour(h, HOUR)
if m:
self.SetHandBorderColour(m, MINUTE)
self.SetHandFillColour(m, MINUTE)
if s:
self.SetHandBorderColour(h, SECOND)
self.SetHandFillColour(h, SECOND)
def SetTickColours(self, h=None, m=None):
if not m:
m=h
if h:
self.SetTickBorderColour(h, HOUR)
self.SetTickFillColour(h, HOUR)
if m:
self.SetTickBorderColour(m, MINUTE)
self.SetTickFillColour(m, MINUTE)
def SetTickSizes(self, h=None, m=None):
if h:
self.SetTickSize(h, HOUR)
if m:
self.SetTickSize(h, MINUTE)
def SetTickFontss(self, h=None, m=None):
if h:
self.SetTickFont(h, HOUR)
if m:
self.SetTickFont(h, MINUTE)
def SetMinutesOffset(self, o):
pass
def SetShadowColour(self, s):
pass
def SetWatchPenBrush(self, p=None, b=None):
if p:
self.SetFaceBorderColour(p.GetColour())
self.SetFaceBorderWidth(p.GetWidth())
if b:
self.SetFaceFillColour(b.GetColour())
def SetClockStyle(self, style):
style |= SHOW_HOURS_HAND|SHOW_MINUTES_HAND|SHOW_SECONDS_HAND
AnalogClock.SetClockStyle(self, style)
def SetTickStyles(self, h=None, m=None):
if h:
self.SetTickStyle(h, HOUR)
if m:
self.SetTickStyle(h, MINUTE)
# Test stuff ----------------------------------------------------------
if __name__ == "__main__":
print wx.VERSION_STRING
class AcDemoApp(wx.App):
def OnInit(self):
frame = wx.Frame(None, -1, "AnalogClock", size=(375, 375))
clock = AnalogClock(frame)
frame.CentreOnScreen()
frame.Show()
return True
acApp = AcDemoApp(0)
acApp.MainLoop()
#
##
### eof
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -