self.delete(self.hourHand) # стрелки, центр
self.delete(self.minsHand) self.delete(self.secsHand)
originX = originY = radius = cfg.size // 2 # 3.x деление //
hour = hour + (mins / 60.0)
hx, hy = self.point(hour, 12, (radius * .80), originX, originY)
mx, my = self.point(mins, 60, (radius * .90), originX, originY)
sx, sy = self.point(secs, 60, (radius * .95), originX, originY)
self.hourHand = self.create_line(originX, originY, hx, hy, width=(cfg.size * .04),
arrow=’last’, arrowshape=(25,25,15), fill=cfg.hh) self.minsHand = self.create_line(originX, originY, mx, my, width=(cfg.size * .03),
arrow=’last’, arrowshape=(20,20,10), fill=cfg.mh) self.secsHand = self.create_line(originX, originY, sx, sy, width=1,
arrow=’last’, arrowshape=(5,10,5), fill=cfg.sh) cogsz = cfg.size * .01
self.cog = self.create_oval(originX-cogsz, originY+cogsz,
originX+cogsz, originY-cogsz, fill=cfg.cog) self.dchars(self.ampm, 0, END) self.insert(self.ampm, END, ampm)
def onResize(self, newWidth, newHeight, cfg): newSize = min(newWidth, newHeight)
#print(‘analog onResize’, cfg.size+4, newSize) if newSize != cfg.size+4: cfg.size = newSize-4 self.delete(‘all’)
self.drawClockface(cfg) # onUpdate called next
##############################################################################
# Составной объект часов
##############################################################################
ChecksPerSec = 10 # частота проверки системного времени
class Clock(Frame):
def __init__(self, config=ClockConfig, parent=None):
Frame.__init__(self, parent) self.cfg = config
self.makeWidgets(parent) # дочерние виджеты компонуются методом pack, self.labelOn = 0 # но клиенты могут использовать pack или grid
self.display = self.digitalDisplay self.lastSec = self.lastMin = -1 self.countdownSeconds = 0
self.onSwitchMode(None)
self.onTimer()
def makeWidgets(self, parent):
self.digitalDisplay = DigitalDisplay(self, self.cfg) self.analogDisplay = AnalogDisplay(self, self.cfg) self.dateLabel = Label(self, bd=3, bg=’red’, fg=’blue’) parent.bind(‘<ButtonPress-1>’, self.onSwitchMode) parent.bind(‘<ButtonPress-3>’, self.onToggleLabel) parent.bind(‘<Configure>’, self.onResize) parent.bind(‘<KeyPress-s>’, self.onCountdownSec) parent.bind(‘<KeyPress-m>’, self.onCountdownMin)
def onSwitchMode(self, event): self.display.pack_forget() if self.display == self.analogDisplay: self.display = self.digitalDisplay else: