snakeware

Python-based Linux distro for x86-64 and RPi
git clone git://squid-tech.com/snakeware.git
Log | Files | Refs | README

commit ae70cdf957e47e1213b193f584db104b2e855682
parent 14ef553af27f5ade11bed4356ff9fb1d56c3a6a1
Author: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Date:   Fri,  5 Jun 2020 19:24:27 +0000

fixup! Format Python code with psf/black push

Diffstat:
Msnakewm/apps/tools/aclock/aclock.py | 97++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 67 insertions(+), 30 deletions(-)

diff --git a/snakewm/apps/tools/aclock/aclock.py b/snakewm/apps/tools/aclock/aclock.py @@ -1,4 +1,3 @@ - # Analog PyGame clock import pygame @@ -14,8 +13,10 @@ WHITE = 255, 255, 255 GRAY = 76, 80, 82 RED = 255, 0, 0 + class SnakeAClock(pygame_gui.elements.UIWindow): DIMS = (300, 300) + def __init__(self, pos, manager): super().__init__( pygame.Rect(pos, (self.DIMS[0] + 32, self.DIMS[1] + 60)), @@ -45,54 +46,90 @@ class SnakeAClock(pygame_gui.elements.UIWindow): self.dsurf.image.blit(self.dial, (0, 0)) def clocksize(self): - return int(.95 * min(self.DIMS)/2) + return int(0.95 * min(self.DIMS) / 2) def diam(self, x, r1, r2, r3, dx): - x1, y1 = r1*self.clocksize()*sin(x*pi/180), r1*self.clocksize()*cos(x*pi/180) - x2, y2 = r2*self.clocksize()*sin((x+dx)*pi/180), r2*self.clocksize()*cos((x+dx)*pi/180) - x3, y3 = r3*self.clocksize()*sin(x*pi/180), r3*self.clocksize()*cos(x*pi/180) - x4, y4 = r2*self.clocksize()*sin((x-dx)*pi/180), r2*self.clocksize()*cos((x-dx)*pi/180) + x1, y1 = ( + r1 * self.clocksize() * sin(x * pi / 180), + r1 * self.clocksize() * cos(x * pi / 180), + ) + x2, y2 = ( + r2 * self.clocksize() * sin((x + dx) * pi / 180), + r2 * self.clocksize() * cos((x + dx) * pi / 180), + ) + x3, y3 = ( + r3 * self.clocksize() * sin(x * pi / 180), + r3 * self.clocksize() * cos(x * pi / 180), + ) + x4, y4 = ( + r2 * self.clocksize() * sin((x - dx) * pi / 180), + r2 * self.clocksize() * cos((x - dx) * pi / 180), + ) p = [ - (int(x1+self.DIMS[0]//2), int(-y1+self.DIMS[1]//2)), - (int(x2+self.DIMS[0]//2), int(-y2+self.DIMS[1]//2)), - (int(x3+self.DIMS[0]//2), int(-y3+self.DIMS[1]//2)), - (int(x4+self.DIMS[0]//2), int(-y4+self.DIMS[1]//2)), + (int(x1 + self.DIMS[0] // 2), int(-y1 + self.DIMS[1] // 2)), + (int(x2 + self.DIMS[0] // 2), int(-y2 + self.DIMS[1] // 2)), + (int(x3 + self.DIMS[0] // 2), int(-y3 + self.DIMS[1] // 2)), + (int(x4 + self.DIMS[0] // 2), int(-y4 + self.DIMS[1] // 2)), ] pygame.draw.polygon(self.dial, WHITE, p) def draw_dial(self): self.dial = pygame.Surface(self.DIMS) self.dial.fill(DARK) - pygame.draw.circle(self.dial, WHITE, (self.DIMS[0]//2, self.DIMS[1]//2), self.clocksize()) - pygame.draw.circle(self.dial, GRAY, (self.DIMS[0]//2, self.DIMS[1]//2), int(.99*self.clocksize())) + pygame.draw.circle( + self.dial, WHITE, (self.DIMS[0] // 2, self.DIMS[1] // 2), self.clocksize() + ) + pygame.draw.circle( + self.dial, + GRAY, + (self.DIMS[0] // 2, self.DIMS[1] // 2), + int(0.99 * self.clocksize()), + ) for x in range(60): - if x % 5 == 0: continue - x1, y1 = .95*self.clocksize()*sin(6*x*pi/180), .95*self.clocksize()*cos(6*x*pi/180) - x2, y2 = .92*self.clocksize()*sin(6*x*pi/180), .92*self.clocksize()*cos(6*x*pi/180) - pygame.draw.line(self.dial, WHITE, - (int(x1+self.DIMS[0]//2), int(y1+self.DIMS[1]//2)), - (int(x2+self.DIMS[0]//2), int(y2+self.DIMS[1]//2)), 2) + if x % 5 == 0: + continue + x1, y1 = ( + 0.95 * self.clocksize() * sin(6 * x * pi / 180), + 0.95 * self.clocksize() * cos(6 * x * pi / 180), + ) + x2, y2 = ( + 0.92 * self.clocksize() * sin(6 * x * pi / 180), + 0.92 * self.clocksize() * cos(6 * x * pi / 180), + ) + pygame.draw.line( + self.dial, + WHITE, + (int(x1 + self.DIMS[0] // 2), int(y1 + self.DIMS[1] // 2)), + (int(x2 + self.DIMS[0] // 2), int(y2 + self.DIMS[1] // 2)), + 2, + ) for x in range(0, 360, 30): if x % 90 == 0: - self.diam(x, .95, .88, .88, 2) + self.diam(x, 0.95, 0.88, 0.88, 2) else: - self.diam(x, .95, .95, .87, 1) + self.diam(x, 0.95, 0.95, 0.87, 1) def draw_hands(self): # hour hand now = datetime.datetime.now() - x = 30*((now.hour - 12) % 12) + now.minute/2 - self.diam(x, .45, .08, -.08, 30) + x = 30 * ((now.hour - 12) % 12) + now.minute / 2 + self.diam(x, 0.45, 0.08, -0.08, 30) # minute hand - x = 6*now.minute + now.second/10 - self.diam(x, .75, .08, -.08, 25) + x = 6 * now.minute + now.second / 10 + self.diam(x, 0.75, 0.08, -0.08, 25) # second hand - x = 6*now.second - x1, y1 = .8*self.clocksize()*sin(x*pi/180), .8*self.clocksize()*cos(x*pi/180) + x = 6 * now.second + x1, y1 = ( + 0.8 * self.clocksize() * sin(x * pi / 180), + 0.8 * self.clocksize() * cos(x * pi / 180), + ) x2, y2 = 0, 0 - pygame.draw.line(self.dial, RED, - (int(x1+self.DIMS[0]//2), int(-y1+self.DIMS[1]//2)), - (int(x2+self.DIMS[0]//2), int(-y2+self.DIMS[1]//2)), 3) - + pygame.draw.line( + self.dial, + RED, + (int(x1 + self.DIMS[0] // 2), int(-y1 + self.DIMS[1] // 2)), + (int(x2 + self.DIMS[0] // 2), int(-y2 + self.DIMS[1] // 2)), + 3, + )