From: mar77i Date: Sat, 20 Sep 2025 13:34:06 +0000 (+0200) Subject: ruff me up, fam X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=2934069cdca6a81d221a31a57c20cc236ca58d49;p=zenbook_gui ruff me up, fam --- diff --git a/bookpaint/color_menu.py b/bookpaint/color_menu.py index 275eff1..5f645a7 100644 --- a/bookpaint/color_menu.py +++ b/bookpaint/color_menu.py @@ -29,7 +29,7 @@ def draw_cursor(surf, color, pos): (pos[0] + r, pos[1]), (pos[0], pos[1] + r), (pos[0] - r, pos[1]), - ) + ), ) @@ -62,7 +62,10 @@ class ColorCircle(Child): for x, col in enumerate(pa): for y in range(len(col)): pa[x][y] = pygame.Color( - y // 2, y // 2, y // 2, 255 - (y, x)[i] * 255 // max(size), + y // 2, + y // 2, + y // 2, + 255 - (y, x)[i] * 255 // max(size), ) return overlay_surfs @@ -70,7 +73,7 @@ class ColorCircle(Child): super().__init__(parent) self.rect = rect self.radii = (378, min(rect.size) // 2) - self.radii_squared = tuple(r ** 2 for r in self.radii) + self.radii_squared = tuple(r**2 for r in self.radii) self.avg_radius = sum(self.radii) / len(self.radii) self.hue_circle = self.render_hue_circle() self.hue_angle = 0 @@ -108,7 +111,7 @@ class ColorCircle(Child): sz = rotated_hue_surf.get_size() self.surf.blit( rotated_hue_surf, - (self.rect.centerx - sz[0] // 2, self.rect.centery - sz[1] // 2) + (self.rect.centerx - sz[0] // 2, self.rect.centery - sz[1] // 2), ) sz = self.hue_surf_rect.size @@ -462,7 +465,7 @@ class ColorMenu(BaseMenu): self, pygame.Rect( (label_right, hue_slider.rect.top), - (label_width, button_height) + (label_width, button_height), ), "H", Label.HAlign.CENTER, @@ -515,7 +518,10 @@ class ColorMenu(BaseMenu): value_spinner, ), (self.color_circle,), - (self.hs_map, value_slider2,), + ( + self.hs_map, + value_slider2, + ), ), ) @@ -590,7 +596,10 @@ class ColorMenu(BaseMenu): if sender != self.color_circle: self.color_circle.hue_angle = values["h"] * tau / 255 sz = self.color_circle.hue_surf_rect.size - self.color_circle.sv_pos = (values["s"] * sz[0] / 255, values["v"] * sz[1] / 255) + self.color_circle.sv_pos = ( + values["s"] * sz[0] / 255, + values["v"] * sz[1] / 255, + ) if sender != self.hs_map: ... @@ -623,9 +632,7 @@ class ColorMenu(BaseMenu): kwargs["color"] = color elif dest in self.HSV_LETTERS: hsv_controls = [ - next( - d for d in self.channel_slots[c] if not isinstance(d, Slider) - ) + next(d for d in self.channel_slots[c] if not isinstance(d, Slider)) for c in self.HSV_LETTERS ] index = self.HSV_LETTERS.index(dest) @@ -643,7 +650,7 @@ class ColorMenu(BaseMenu): else: try: color = pygame.Color(color_like) - except: + except ValueError: color = pygame.Color(f"0x{color_like}") self.parent.draw_image.color = color self.update_controls() diff --git a/bookpaint/draw_image.py b/bookpaint/draw_image.py index 7244da6..09f9106 100644 --- a/bookpaint/draw_image.py +++ b/bookpaint/draw_image.py @@ -62,13 +62,13 @@ class DrawImage(Child): self.dot(self.image, ev.pos) return if self.stroke_method is self.StrokeMethod.ROUND: - StrokeRoundLine( - self.prev_pos, ev.pos, self.line_width - ).draw(self.image, self.color) + StrokeRoundLine(self.prev_pos, ev.pos, self.line_width).draw( + self.image, self.color + ) elif self.stroke_method is self.StrokeMethod.SQUARE: - StrokeSquareLine( - self.prev_pos, ev.pos, self.line_width - ).draw(self.image, self.color) + StrokeSquareLine(self.prev_pos, ev.pos, self.line_width).draw( + self.image, self.color + ) elif self.stroke_method is self.StrokeMethod.PYGAME: pygame.draw.line( self.image, self.color, self.prev_pos, ev.pos, self.line_width diff --git a/bookpaint/page_menu.py b/bookpaint/page_menu.py index 5dd9f96..6f77415 100644 --- a/bookpaint/page_menu.py +++ b/bookpaint/page_menu.py @@ -20,7 +20,9 @@ class PageMenu(BaseMenu): y = self.base_rect.top self.label = Label( self, - pygame.Rect((self.base_rect.left, y), (self.base_rect.width, button_height)), + pygame.Rect( + (self.base_rect.left, y), (self.base_rect.width, button_height) + ), "", Label.HAlign.CENTER, ) @@ -39,7 +41,7 @@ class PageMenu(BaseMenu): self, pygame.Rect((x, y), (button_width, button_height)), value, - callback + callback, ) x += button_width @@ -68,5 +70,5 @@ class PageMenu(BaseMenu): pygame.K_PAGEDOWN: partial(nav, nav=BookManager.Nav.NEXT), pygame.K_END: partial(nav, nav=BookManager.Nav.LAST), pygame.K_n: partial(nav, nav=BookManager.Nav.NEW), - } + }, } diff --git a/connect_four.py b/connect_four.py index 7b2f426..04099c1 100755 --- a/connect_four.py +++ b/connect_four.py @@ -14,7 +14,7 @@ def distance(a, b): class WinMessage(MessageBox): - root: "ConnectFour" + root: "Root" def __init__(self, parent, rect): super().__init__(parent, rect, "") @@ -72,9 +72,7 @@ class Root(BaseRoot): (self.rect.width, self.rect.height + self.part_size[1]), ) self.part_radius = int(self.RADIUS * min(self.part_size)) - self.field = [ - [0] * self.FIELD_SIZE[0] for _ in range(self.FIELD_SIZE[1]) - ] + self.field = [[0] * self.FIELD_SIZE[0] for _ in range(self.FIELD_SIZE[1])] self.adding = None self.drop_y = 0 self.current_player = 0 @@ -82,7 +80,7 @@ class Root(BaseRoot): self, pygame.Rect( (size[0] // 6, size[1] * 3 // 8), (size[0] * 2 // 3, size[1] // 4) - ) + ), ) self.top_button = ColorButton( self, @@ -116,7 +114,7 @@ class Root(BaseRoot): self.surf, self.PLAYER_COLORS[self.current_player], ( - self.rect.left + self.part_size[0] * (x + .5), + self.rect.left + self.part_size[0] * (x + 0.5), self.rect.top - self.part_size[1] // 2 + drop_y, ), self.part_radius, @@ -132,18 +130,16 @@ class Root(BaseRoot): ) pygame.draw.circle( surf, - ( - pygame.Color(0, 0, 0, 0), *self.PLAYER_COLORS - )[self.field[y][x]], + (pygame.Color(0, 0, 0, 0), *self.PLAYER_COLORS)[self.field[y][x]], part_rect.center, self.part_radius, ) return surf def draw_adding(self): - StrokeCircleSegment( - self.adding[1:], self.PULL_DOWN, 0, pi, 16 - ).draw(self.surf, "darkgray") + StrokeCircleSegment(self.adding[1:], self.PULL_DOWN, 0, pi, 16).draw( + self.surf, "darkgray" + ) def draw(self): self.surf.fill("black") @@ -239,7 +235,7 @@ class Root(BaseRoot): if 0 not in self.field[0]: return None for y, row in zip( - range(self.top_row, self.FIELD_SIZE[1]), self.field[self.top_row:] + range(self.top_row, self.FIELD_SIZE[1]), self.field[self.top_row :] ): for x, v in enumerate(row): if self.has_won_at(x, y): diff --git a/keyboard/clock.py b/keyboard/clock.py index 31c6a2b..60a5ac8 100644 --- a/keyboard/clock.py +++ b/keyboard/clock.py @@ -12,14 +12,14 @@ class ClockWidget(Child): HANDS = ( (-1 / 16, 3 / 16), # fullday (-1 / 16, 7 / 16), # hour - (-1 / 16, 3 / 4), # minute + (-1 / 16, 3 / 4), # minute (-1 / 8, 13 / 16), # second ) WIDTHS = ( - 0.0325, # fullday + 0.0325, # fullday 0.02625, # hour - 0.0175, # minute - 0.005, # second + 0.0175, # minute + 0.005, # second ) def __init__(self, parent, rect): @@ -122,5 +122,5 @@ class ClockWidget(Child): (points[0][0] + offset[0], points[0][1] + offset[1]), (points[1][0] + offset[0], points[1][1] + offset[1]), (points[1][0] - offset[0], points[1][1] - offset[1]), - ] + ], ) diff --git a/keyboard/config.py b/keyboard/config.py index 60cd65d..17b6437 100644 --- a/keyboard/config.py +++ b/keyboard/config.py @@ -7,11 +7,15 @@ from pathlib import Path class Config: def __init__(self, base): - self.path = Path( - os.environ.get( - "XDG_CONFIG_HOME", f"{os.path.expanduser('~')}{os.pathsep}.config" + self.path = ( + Path( + os.environ.get( + "XDG_CONFIG_HOME", f"{os.path.expanduser('~')}{os.pathsep}.config" + ) ) - ) / "zenbook_gui" / f"{base}.json" + / "zenbook_gui" + / f"{base}.json" + ) self.loaded = None def load(self): diff --git a/keyboard/key.py b/keyboard/key.py index 6a63df8..83af3c1 100644 --- a/keyboard/key.py +++ b/keyboard/key.py @@ -27,7 +27,7 @@ KEYBOARD = ( ("F11", Key.f11), ("F12", Key.f12), "\n", - ("§", KeyCode.from_vk(0xa7), {"x_hint": 1.5}), + ("§", KeyCode.from_vk(0xA7), {"x_hint": 1.5}), ("1", KeyCode.from_vk(0x31)), ("2", KeyCode.from_vk(0x32)), ("3", KeyCode.from_vk(0x33)), @@ -39,7 +39,7 @@ KEYBOARD = ( ("9", KeyCode.from_vk(0x39)), ("0", KeyCode.from_vk(0x30)), ("'", KeyCode.from_vk(0x27)), - ("^", KeyCode.from_vk(0xfe52)), + ("^", KeyCode.from_vk(0xFE52)), ("←", Key.backspace, {"x_hint": 1.5}), "\n", ("Tab", Key.tab, {"x_hint": 2}), @@ -48,13 +48,13 @@ KEYBOARD = ( ("E", KeyCode.from_vk(0x65)), ("R", KeyCode.from_vk(0x72)), ("T", KeyCode.from_vk(0x74)), - ("Z", KeyCode.from_vk(0x7a)), + ("Z", KeyCode.from_vk(0x7A)), ("U", KeyCode.from_vk(0x75)), ("I", KeyCode.from_vk(0x69)), - ("O", KeyCode.from_vk(0x6f)), + ("O", KeyCode.from_vk(0x6F)), ("P", KeyCode.from_vk(0x70)), - ("ü", KeyCode.from_vk(0xfc)), - ("¨", KeyCode.from_vk(0xfe57)), + ("ü", KeyCode.from_vk(0xFC)), + ("¨", KeyCode.from_vk(0xFE57)), ("$", KeyCode.from_vk(0x24)), "\n", ("CpsLk", Key.caps_lock, {"x_hint": 2.5, "led_mask": 1}), @@ -64,25 +64,25 @@ KEYBOARD = ( ("F", KeyCode.from_vk(0x66)), ("G", KeyCode.from_vk(0x67)), ("H", KeyCode.from_vk(0x68)), - ("J", KeyCode.from_vk(0x6a)), - ("K", KeyCode.from_vk(0x6b)), - ("L", KeyCode.from_vk(0x6c)), - ("ö", KeyCode.from_vk(0xf6)), - ("ä", KeyCode.from_vk(0xe4)), + ("J", KeyCode.from_vk(0x6A)), + ("K", KeyCode.from_vk(0x6B)), + ("L", KeyCode.from_vk(0x6C)), + ("ö", KeyCode.from_vk(0xF6)), + ("ä", KeyCode.from_vk(0xE4)), ("↵", Key.enter, {"x_hint": 1.5}), "\n", ("↑", Key.shift, {"x_hint": 2}), - ("<", KeyCode.from_vk(0x3c)), + ("<", KeyCode.from_vk(0x3C)), ("Y", KeyCode.from_vk(0x79)), ("X", KeyCode.from_vk(0x78)), ("C", KeyCode.from_vk(0x63)), ("V", KeyCode.from_vk(0x76)), ("B", KeyCode.from_vk(0x62)), - ("N", KeyCode.from_vk(0x6e)), - ("M", KeyCode.from_vk(0x6d)), - (",", KeyCode.from_vk(0x2c)), - (".", KeyCode.from_vk(0x2e)), - ("-", KeyCode.from_vk(0x2d)), + ("N", KeyCode.from_vk(0x6E)), + ("M", KeyCode.from_vk(0x6D)), + (",", KeyCode.from_vk(0x2C)), + (".", KeyCode.from_vk(0x2E)), + ("-", KeyCode.from_vk(0x2D)), ("↑", Key.shift, {"x_hint": 2}), "\n", ("Ctrl", Key.ctrl_l, {"x_hint": 2}), @@ -90,7 +90,7 @@ KEYBOARD = ( ("Alt", Key.alt_l), ("␣", Key.space, {"x_hint": 7}), ("⚙", "Settings"), - ("AltGr", KeyCode.from_vk(0xfe03)), + ("AltGr", KeyCode.from_vk(0xFE03)), ("Ctrl", Key.ctrl_r, {"x_hint": 2}), ) @@ -115,26 +115,26 @@ CURSOR_KEYS = ( KEYPAD_KEYS = ( ("NUM", Key.num_lock, {"led_mask": 2}), - ("/", KeyCode.from_vk(0xffaf)), - ("*", KeyCode.from_vk(0xffaa)), - ("-", KeyCode.from_vk(0xffad)), + ("/", KeyCode.from_vk(0xFFAF)), + ("*", KeyCode.from_vk(0xFFAA)), + ("-", KeyCode.from_vk(0xFFAD)), "\n", - ("7", KeyCode.from_vk(0xffb7)), - ("8", KeyCode.from_vk(0xffb8)), - ("9", KeyCode.from_vk(0xffb9)), - ("+", KeyCode.from_vk(0xffab), {"y_hint": 2}), + ("7", KeyCode.from_vk(0xFFB7)), + ("8", KeyCode.from_vk(0xFFB8)), + ("9", KeyCode.from_vk(0xFFB9)), + ("+", KeyCode.from_vk(0xFFAB), {"y_hint": 2}), "\n", - ("4", KeyCode.from_vk(0xffb4)), - ("5", KeyCode.from_vk(0xffb5)), - ("6", KeyCode.from_vk(0xffb6)), + ("4", KeyCode.from_vk(0xFFB4)), + ("5", KeyCode.from_vk(0xFFB5)), + ("6", KeyCode.from_vk(0xFFB6)), "\n", - ("1", KeyCode.from_vk(0xffb1)), - ("2", KeyCode.from_vk(0xffb2)), - ("3", KeyCode.from_vk(0xffb3)), - ("Enter", KeyCode.from_vk(0xff8d), {"y_hint": 2}), + ("1", KeyCode.from_vk(0xFFB1)), + ("2", KeyCode.from_vk(0xFFB2)), + ("3", KeyCode.from_vk(0xFFB3)), + ("Enter", KeyCode.from_vk(0xFF8D), {"y_hint": 2}), "\n", - ("0", KeyCode.from_vk(0xffb0), {"x_hint": 2}), - (".", KeyCode.from_vk(0xffae)), + ("0", KeyCode.from_vk(0xFFB0), {"x_hint": 2}), + (".", KeyCode.from_vk(0xFFAE)), ) @@ -146,7 +146,9 @@ class KeyButton(Button): self.touch_key = None # sounds from https://freesoundsite.com/sound-collections/click-sound-effects/ self.sounds = ( - pygame.mixer.Sound(Path(__file__).parent / "sounds" / "Flicker_Sound_Effect.mp3"), + pygame.mixer.Sound( + Path(__file__).parent / "sounds" / "Flicker_Sound_Effect.mp3" + ), pygame.mixer.Sound(Path(__file__).parent / "sounds" / "Clutch.mp3"), ) for sound in self.sounds: @@ -271,7 +273,7 @@ def get_keyboard_keys(parent, rect, callback, keys): key[0], callback, data=key[1], - led_mask=led_mask + led_mask=led_mask, ) ) x += key_width diff --git a/keyboard/menu.py b/keyboard/menu.py index 3956486..3d92a68 100644 --- a/keyboard/menu.py +++ b/keyboard/menu.py @@ -76,5 +76,5 @@ class MenuModal(QuittableModal): os.execl( sys.executable, executable, - *sys.orig_argv[sys.orig_argv[0] == executable:], + *sys.orig_argv[sys.orig_argv[0] == executable :], ) diff --git a/keyboard/touchbutton.py b/keyboard/touchbutton.py index 1289e34..e249afc 100644 --- a/keyboard/touchbutton.py +++ b/keyboard/touchbutton.py @@ -19,10 +19,10 @@ class TouchButton(Button): if not self.pushed or self.touch_key is None: return if ( - (event.touch_id, event.finger_id) == self.touch_key - and not self.rect.collidepoint( - MultitouchHandler.map_coords((event.x, event.y), self.surf.get_size()) - ) + event.touch_id, + event.finger_id, + ) == self.touch_key and not self.rect.collidepoint( + MultitouchHandler.map_coords((event.x, event.y), self.surf.get_size()) ): self.touch_key = None self.pushed = False diff --git a/launch.py b/launch.py index 39ecddd..cb91755 100755 --- a/launch.py +++ b/launch.py @@ -75,9 +75,10 @@ def run_cmd(cmd, expect_returncode=0): def check_has_pkg(pkg): - return f"No module named {pkg}.__main__;".encode() in run_cmd( - (executable, "-m", pkg), 1 - ).stderr + return ( + f"No module named {pkg}.__main__;".encode() + in run_cmd((executable, "-m", pkg), 1).stderr + ) def get_ipv4_is_connected(): @@ -85,7 +86,7 @@ def get_ipv4_is_connected(): with open("/proc/net/route") as fh: for line in fh: fields = line.rstrip().split("\t") - if fields[1] == '00000000' and int(fields[3], 16) & 2: + if fields[1] == "00000000" and int(fields[3], 16) & 2: return True return False @@ -93,18 +94,14 @@ def get_ipv4_is_connected(): def walk_outer(path): return ( path, - *( - base / ent - for base, dirs, files in path.walk() - for ent in (*dirs, *files) - ) + *(base / ent for base, dirs, files in path.walk() for ent in (*dirs, *files)), ) def get_venv_environ(venv_dir): new_env = {"VIRTUAL_ENV": str(venv_dir)} venv_bin_str = str(venv_dir / "bin") - if venv_bin_str not in os.environ['PATH'].split(os.pathsep): + if venv_bin_str not in os.environ["PATH"].split(os.pathsep): new_env["PATH"] = f"{venv_bin_str}{os.pathsep}{os.environ['PATH']}" return new_env @@ -122,7 +119,7 @@ def setup_venv(): raise SystemError("'venv' is not a directory.") run_cmd((sys.executable, "-m", "venv", str(venv_dir))) os.environ.update(get_venv_environ(venv_dir)) - has_pkgs = (venv_dir_is_dir and all(check_has_pkg(pkg) for pkg in pkgs)) + has_pkgs = venv_dir_is_dir and all(check_has_pkg(pkg) for pkg in pkgs) if get_ipv4_is_connected(): yesterday = time() - 86400 if not has_pkgs or all( @@ -149,7 +146,7 @@ def pre_run(): os.execl( sys.executable, executable, - *sys.orig_argv[sys.orig_argv[0] == executable:], + *sys.orig_argv[sys.orig_argv[0] == executable :], ) exit(1) if pkg == "pygame": diff --git a/memory.py b/memory.py index 3952314..1ef7d42 100755 --- a/memory.py +++ b/memory.py @@ -23,12 +23,12 @@ class NameMenu(QuittableModal): self.inputs = [ TextInput( self, - pygame.Rect((int(self.lw / 2), 288), (int(self.lw * .8), 128)), + pygame.Rect((int(self.lw / 2), 288), (int(self.lw * 0.8), 128)), partial(self.set_player_name, 0), ), TextInput( self, - pygame.Rect((int(self.lw / 2), 288 + 144), (int(self.lw * .8), 128)), + pygame.Rect((int(self.lw / 2), 288 + 144), (int(self.lw * 0.8), 128)), partial(self.set_player_name, 1), ), ] @@ -40,9 +40,11 @@ class NameMenu(QuittableModal): ) Button( self, - pygame.Rect((int(self.lw * 1.5), 288), (self.lw * .8, 144)).inflate(-16, -16), + pygame.Rect((int(self.lw * 1.5), 288), (self.lw * 0.8, 144)).inflate( + -16, -16 + ), "START GAME", - self.deactivate + self.deactivate, ) self.player_names = [] @@ -64,9 +66,9 @@ class NameMenu(QuittableModal): TextInput( self, pygame.Rect( - (int(self.lw / 2), 288 + 144 * num), (int(self.lw * .8), 128) + (int(self.lw / 2), 288 + 144 * num), (int(self.lw * 0.8), 128) ), - partial(self.set_player_name, num) + partial(self.set_player_name, num), ) ) self.add_button.rect.top += 144 @@ -122,9 +124,9 @@ class EndGameMenu(QuittableModal): if len(winners) == 1: self.labels[0].value = f"WINNER: {str(winners[0])} !!!" else: - self.labels[0].value = ( - f"WINNERS: {', '.join(str(winner) for winner in winners)} !!!" - ) + self.labels[ + 0 + ].value = f"WINNERS: {', '.join(str(winner) for winner in winners)} !!!" def draw_modal(self): super().draw_modal() @@ -202,7 +204,7 @@ class Root(BaseRoot): self.current_player = 0 self.name_menu = NameMenu(self) size = self.surf.get_size() - thirds = (size[0] // 3, size[1] //3) + thirds = (size[0] // 3, size[1] // 3) self.end_game_menu = EndGameMenu(self, pygame.Rect(thirds, thirds)) self.cards = [] initial_cards = [] @@ -215,7 +217,7 @@ class Root(BaseRoot): self, pygame.Rect((512, 144), (self.surf.get_width() - 1024, 128)), "", - self.next_turn + self.next_turn, ) self.turn_done = False self.name_menu.activate() diff --git a/rps/rps.py b/rps/rps.py index 90596f9..67dce1e 100644 --- a/rps/rps.py +++ b/rps/rps.py @@ -63,22 +63,26 @@ class Root(BaseRoot): self.rps_buttons = ( RPSButton( self, - pygame.Rect((0, size[1] // 2), (size[0] // 2, size[1] // 2)).inflate(-256, -256), + pygame.Rect((0, size[1] // 2), (size[0] // 2, size[1] // 2)).inflate( + -256, -256 + ), 192, partial(self.finger_push, 0), ), RPSButton( self, - pygame.Rect((size[0] // 2, size[1] // 2), (size[0] // 2, size[1] // 2)).inflate(-256, -256), + pygame.Rect( + (size[0] // 2, size[1] // 2), (size[0] // 2, size[1] // 2) + ).inflate(-256, -256), 192, partial(self.finger_push, 1), ), ) self.reset_button = FingerButton( self, - pygame.Rect( - (size[0] // 2 - 256, size[1] * 3 // 4), (512, 256) - ).inflate(-32, -32), + pygame.Rect((size[0] // 2 - 256, size[1] * 3 // 4), (512, 256)).inflate( + -32, -32 + ), "Reset", self.reset, ) @@ -102,20 +106,54 @@ class Root(BaseRoot): mask = int(self.v1 is not None) | (int(self.v2 is not None) << 1) fs = self.big_font.render(str(self.p1), True, "yellow") fs_size = fs.get_size() - self.surf.blit(fs, (center[0] - half_radius - fs_size[0] // 2, center[1] - half_radius - fs_size[1] // 2)) + self.surf.blit( + fs, + ( + center[0] - half_radius - fs_size[0] // 2, + center[1] - half_radius - fs_size[1] // 2, + ), + ) fs = self.big_font.render(str(self.p2), True, "yellow") - self.surf.blit(fs, (center[0] + half_radius - fs_size[0] // 2, center[1] - half_radius - fs_size[1] // 2)) + self.surf.blit( + fs, + ( + center[0] + half_radius - fs_size[0] // 2, + center[1] - half_radius - fs_size[1] // 2, + ), + ) if mask & 1: - pygame.draw.circle(self.surf, "cyan", (center[0] - half_radius, center[1] + half_radius), radius // 3) + pygame.draw.circle( + self.surf, + "cyan", + (center[0] - half_radius, center[1] + half_radius), + radius // 3, + ) if mask & (1 << 1): - pygame.draw.circle(self.surf, "cyan", (center[0] + half_radius, center[1] + half_radius), radius // 3) + pygame.draw.circle( + self.surf, + "cyan", + (center[0] + half_radius, center[1] + half_radius), + radius // 3, + ) if mask == 3: fs = self.font.render(str(self.v1), True, "black") fs_size = fs.get_size() - self.surf.blit(fs, (center[0] - half_radius - fs_size[0] // 2, center[1] + half_radius - fs_size[1] // 2)) + self.surf.blit( + fs, + ( + center[0] - half_radius - fs_size[0] // 2, + center[1] + half_radius - fs_size[1] // 2, + ), + ) fs = self.font.render(str(self.v2), True, "black") fs_size = fs.get_size() - self.surf.blit(fs, (center[0] + half_radius - fs_size[0] // 2, center[1] + half_radius - fs_size[1] // 2)) + self.surf.blit( + fs, + ( + center[0] + half_radius - fs_size[0] // 2, + center[1] + half_radius - fs_size[1] // 2, + ), + ) def finger_push(self, player, value): setattr(self, "v1" if player == 0 else "v2", value) diff --git a/rps/rps_button.py b/rps/rps_button.py index e81960c..f16f45e 100644 --- a/rps/rps_button.py +++ b/rps/rps_button.py @@ -89,7 +89,7 @@ class RPSButton(Child): 16, ).draw(self.surf, "darkgray") i = next_i - rots = (-60, 0, 60, -60)[value["flipped"]:] + rots = (-60, 0, 60, -60)[value["flipped"] :] for rot, part, label in zip(rots, (1, -3, 5), value["labels"]): fs = self.font.render(label, True, "white") if rot != 0: diff --git a/ui/drop_down.py b/ui/drop_down.py index 2d857b1..45d22bd 100644 --- a/ui/drop_down.py +++ b/ui/drop_down.py @@ -14,7 +14,8 @@ class DropDownMenu(Modal): Button( self, pygame.Rect( - (rect.left, rect.bottom + i * rect.height), rect.size, + (rect.left, rect.bottom + i * rect.height), + rect.size, ), entry, partial(self.choose, i), diff --git a/ui/fps_widget.py b/ui/fps_widget.py index a33bbc7..dcd00e8 100644 --- a/ui/fps_widget.py +++ b/ui/fps_widget.py @@ -16,9 +16,7 @@ class FPSWidget(Child): def draw(self): surf_size = self.surf.get_size() - fs = self.font.render( - f"{int(self.current_fps)} FPS", True, self.FPS_COLOR - ) + fs = self.font.render(f"{int(self.current_fps)} FPS", True, self.FPS_COLOR) fs_size = fs.get_size() self.surf.blit( fs, (surf_size[0] - fs_size[0] - 7, surf_size[1] - fs_size[1] - 7) diff --git a/ui/label.py b/ui/label.py index e76c5de..fe5d885 100644 --- a/ui/label.py +++ b/ui/label.py @@ -28,7 +28,8 @@ class Label(Child): def get_blit_pos_center(self): fs_size = self.font.size(self.value) return ( - self.rect.centerx - fs_size[0] // 2, self.rect.centery - fs_size[1] // 2 + self.rect.centerx - fs_size[0] // 2, + self.rect.centery - fs_size[1] // 2, ) def get_blit_pos_right(self): diff --git a/ui/multitouch.py b/ui/multitouch.py index c24c91d..06b0dbb 100755 --- a/ui/multitouch.py +++ b/ui/multitouch.py @@ -24,7 +24,7 @@ class MultitouchHandler: def __init__(self, device): self.device = device - self.touch_id = int(self.device.path[self.device.path.find("event") + 5:]) + self.touch_id = int(self.device.path[self.device.path.find("event") + 5 :]) x_info = self.device.absinfo(ecodes.ABS_MT_POSITION_X) y_info = self.device.absinfo(ecodes.ABS_MT_POSITION_Y) self.info = { @@ -63,8 +63,12 @@ class MultitouchHandler: def push_event(self, event_type, finger_new, finger_old): x_info = self.info[ecodes.ABS_MT_POSITION_X] y_info = self.info[ecodes.ABS_MT_POSITION_Y] - x = (finger_new.get(self.x_lookup, x_info[1]) - x_info[0]) / (x_info[1] - x_info[0]) - y = (finger_new.get(self.y_lookup, x_info[1]) - y_info[0]) / (y_info[1] - y_info[0]) + x = (finger_new.get(self.x_lookup, x_info[1]) - x_info[0]) / ( + x_info[1] - x_info[0] + ) + y = (finger_new.get(self.y_lookup, x_info[1]) - y_info[0]) / ( + y_info[1] - y_info[0] + ) pygame.event.post( pygame.event.Event( event_type, @@ -75,17 +79,19 @@ class MultitouchHandler: "y": y, **( { - "dx": x - ( - finger_old.get(self.x_lookup, x_info[1]) - x_info[0] - ) / x_info[1], - "dy": y - ( - finger_old.get(self.y_lookup, y_info[1]) - y_info[0] - ) / y_info[1], - } if finger_old is not None else {"dx": 0.0, "dy": 0.0} + "dx": x + - (finger_old.get(self.x_lookup, x_info[1]) - x_info[0]) + / x_info[1], + "dy": y + - (finger_old.get(self.y_lookup, y_info[1]) - y_info[0]) + / y_info[1], + } + if finger_old is not None + else {"dx": 0.0, "dy": 0.0} ), "evdev_event": finger_new.copy(), **({"dropped": True} if self.dropped else {}), - } + }, ) ) @@ -129,7 +135,7 @@ class MultitouchHandler: def handle_abs(self, event): if event.code == ecodes.ABS_MT_SLOT: self.slot = event.value - elif event.code == ecodes.ABS_MT_TRACKING_ID and event.value == -1: + elif event.code == ecodes.ABS_MT_TRACKING_ID and event.value == -1: self.current_finger().clear() return self.current_finger()[self.get_lookup(ecodes.ABS, event.code)] = event.value @@ -149,12 +155,8 @@ class MultitouchHandler: code = ecodes.ABS[event.code] elif event.type == ecodes.EV_MSC: code = ecodes.MSC[event.code] - elif event.type == ecodes.EV_KEY and event.code in { - *ecodes.KEY, *ecodes.BTN - }: - code = ecodes.KEY.get( - event.code, ecodes.BTN[event.code] - ) + elif event.type == ecodes.EV_KEY and event.code in {*ecodes.KEY, *ecodes.BTN}: + code = ecodes.KEY.get(event.code, ecodes.BTN[event.code]) else: code = f"{ecodes.EV[event.type]}[{event.code}]" print(ecodes.EV[event.type], code, event.value) diff --git a/ui/scroll.py b/ui/scroll.py index 4053676..970dbdc 100644 --- a/ui/scroll.py +++ b/ui/scroll.py @@ -23,7 +23,7 @@ class Scroll(Parent, Child): "pos": ( ev.pos[0] - self.rect.left + self.scroll_x, ev.pos[1] - self.rect.top + self.scroll_y, - ) + ), }, ) super().handle_event(ev) @@ -40,7 +40,7 @@ class Scroll(Parent, Child): ( min(self.rect.width, size[0] - self.scroll_x), min(self.rect.height, size[1] - self.scroll_y), - ) + ), ) ) diff --git a/ui/slider.py b/ui/slider.py index 176f624..7d9f94a 100644 --- a/ui/slider.py +++ b/ui/slider.py @@ -27,8 +27,8 @@ class Slider(Child): super().__init__(parent) self.rect = rect self.direction = direction - self.extent = ( - self._get_extent_base() - (1 if handle_size is None else handle_size) + self.extent = self._get_extent_base() - ( + 1 if handle_size is None else handle_size ) self.value = value self.handle_size = handle_size @@ -171,7 +171,7 @@ class Slider(Child): value = -value limited = True if value > self.extent: - value = self.extent ** 2 // value + value = self.extent**2 // value limited = True return value, limited diff --git a/ui/spinner.py b/ui/spinner.py index 962513b..c1d2556 100644 --- a/ui/spinner.py +++ b/ui/spinner.py @@ -85,9 +85,7 @@ class Spinner(Parent, Child): button_size = (rect.height // 2, rect.height // 2) self.text_input = TextInput( self, - pygame.Rect( - rect.topleft, (rect.width - button_size[0], rect.height) - ), + pygame.Rect(rect.topleft, (rect.width - button_size[0], rect.height)), self.call_callback, str(value), re.compile(r"[-+]?\d*").fullmatch, diff --git a/ui/switch.py b/ui/switch.py index ed2921b..75773ed 100644 --- a/ui/switch.py +++ b/ui/switch.py @@ -22,11 +22,8 @@ class EaseInOutElastic: st = x * 2 st1 = st - 1 sgn = (st >= 1) * 2 - 1 - return ( - 2 ** (-sgn * 10 * st1 - 1) - * sin((st1 - self.s) * tau / self.p) - * sgn - + (sgn > 0) + return 2 ** (-sgn * 10 * st1 - 1) * sin((st1 - self.s) * tau / self.p) * sgn + ( + sgn > 0 ) @@ -83,7 +80,7 @@ class Switch(Child): self.surf, pygame.Color(*(int(x * 255) for x in rgb)), (base_left + eased_current * movement_width, self.rect.top + base_radius), - base_radius + base_radius, ) def set_value(self, value): diff --git a/ui/text_input.py b/ui/text_input.py index 60d0ff7..66b321c 100644 --- a/ui/text_input.py +++ b/ui/text_input.py @@ -126,7 +126,7 @@ class TextInput(Focusable, Child): fs = self.font.render(self.value, True, "gray") fs, self.offset, x = self.maybe_scroll_font_surface( self.font, - self.value[:self.cursor.pos], + self.value[: self.cursor.pos], fs, *self.padded_rect.size, ) @@ -226,7 +226,7 @@ class TextInput(Focusable, Child): def key_delete(self): value = self.value if self.cursor.pos < len(value): - self.value = f"{value[:self.cursor.pos]}{value[self.cursor.pos + 1:]}" + self.value = f"{value[: self.cursor.pos]}{value[self.cursor.pos + 1 :]}" def filter_value(self, value): if not self.value_filter: @@ -238,7 +238,9 @@ class TextInput(Focusable, Child): def key_printable_unicode(self, unicode): len_old_value = len(self.value) - value = f"{self.value[:self.cursor.pos]}{unicode}{self.value[self.cursor.pos:]}" + value = ( + f"{self.value[: self.cursor.pos]}{unicode}{self.value[self.cursor.pos :]}" + ) result = self.filter_value(value) if isinstance(result, str): value = result diff --git a/vectors/stroke_circle_segment.py b/vectors/stroke_circle_segment.py index bdf0558..3fbd85d 100644 --- a/vectors/stroke_circle_segment.py +++ b/vectors/stroke_circle_segment.py @@ -14,11 +14,16 @@ class StrokeCircleSegment(StrokeCircle): def get_points(self): return [ - (self.center[0] + cos(a) * self.radius, self.center[1] + sin(a) * self.radius) + ( + self.center[0] + cos(a) * self.radius, + self.center[1] + sin(a) * self.radius, + ) for a in self.get_angle_segments( self.start_angle, self.end_angle, - StrokeRoundLine.corners_needed_to_appear_round((self.radius + self.width / 2)), + StrokeRoundLine.corners_needed_to_appear_round( + (self.radius + self.width / 2) + ), ) ] diff --git a/vectors/stroke_round_line.py b/vectors/stroke_round_line.py index eea860f..66d0398 100644 --- a/vectors/stroke_round_line.py +++ b/vectors/stroke_round_line.py @@ -8,6 +8,7 @@ class StrokeRoundLine(Polygon): Enclose a rectangle fitted between two points with a regular, non-rotated n-gon that should be visually indistinguishable with a half circle """ + def __init__(self, p1, p2, width): self.p1 = p1 self.p2 = p2 @@ -24,9 +25,7 @@ class StrokeRoundLine(Polygon): initial_corner = opposing_corner = num_vertices back = (0, 0) else: - initial_corner = ceil( - atan2(-delta[0], delta[1]) * num_vertices / tau - ) + initial_corner = ceil(atan2(-delta[0], delta[1]) * num_vertices / tau) opposing_corner = ( floor(atan2(delta[0], -delta[1]) * num_vertices / tau) - initial_corner ) % num_vertices @@ -52,7 +51,7 @@ class StrokeRoundLine(Polygon): return points @staticmethod - def corners_needed_to_appear_round(radius, threshold=.5): + def corners_needed_to_appear_round(radius, threshold=0.5): return ceil(pi / acos(1 - threshold / radius)) def fit(self, pos, unit): diff --git a/vectors/stroke_square_line.py b/vectors/stroke_square_line.py index e45050f..6a5053f 100644 --- a/vectors/stroke_square_line.py +++ b/vectors/stroke_square_line.py @@ -7,6 +7,7 @@ class StrokeSquareLine(Polygon): """ Rotate a rectangle along the direction in which we're drawing. """ + def __init__(self, p1, p2, width): self.p1 = p1 self.p2 = p2 diff --git a/vs_memory.py b/vs_memory.py index bcb5c66..e416661 100755 --- a/vs_memory.py +++ b/vs_memory.py @@ -109,7 +109,7 @@ class Root(BaseRoot): ) len_teams = len(self.teams) # fits one column of memory destinations (todo) - #assert len_teams < 15 and len_teams % 2 == 0, len_teams + # assert len_teams < 15 and len_teams % 2 == 0, len_teams self.num_pairs = len_teams // 2 self.failed = 0 self.successful = 0 @@ -174,7 +174,7 @@ class Root(BaseRoot): self.num_pairs_label.enabled = False self.num_pairs.enabled = False available_teams = list(self.teams) - for child in self.memory_destinations[:2 * self.num_pairs.value]: + for child in self.memory_destinations[: 2 * self.num_pairs.value]: child.enabled = True child.highlight = False child.team = choice(available_teams) @@ -196,7 +196,8 @@ class Root(BaseRoot): self.place_memory_card(memory_card.rect) while any( c.rect.colliderect(memory_card.rect) - for c in self.memory_cards if c != memory_card + for c in self.memory_cards + if c != memory_card ): self.place_memory_card(memory_card.rect) self.dirty = True diff --git a/zenbook_conf/shapes.py b/zenbook_conf/shapes.py index 4d7be4b..dca7ab4 100644 --- a/zenbook_conf/shapes.py +++ b/zenbook_conf/shapes.py @@ -1,7 +1,12 @@ from math import cos, pi, sin, tau from vectors import ( - Polygon, Rect, Shapes, StrokeCircleSegment, StrokeRoundLine, StrokeSquareLine + Polygon, + Rect, + Shapes, + StrokeCircleSegment, + StrokeRoundLine, + StrokeSquareLine, ) @@ -48,7 +53,11 @@ touchscreen = Shapes( 1, ), StrokeCircleSegment( - (4, 13), FINGER_RADIUS, tau * 3 / 8, tau * 7 / 8, 1, + (4, 13), + FINGER_RADIUS, + tau * 3 / 8, + tau * 7 / 8, + 1, ), StrokeRoundLine( ( @@ -62,13 +71,25 @@ touchscreen = Shapes( StrokeCircleSegment((8.25, 6), FINGER_RADIUS, pi, tau, 1), StrokeRoundLine((9.5, 6), (9.5, 11), 1), StrokeCircleSegment( - (11, 11.5), FINGER_RADIUS, tau * 5 / 8, tau * 7 / 8, 1, + (11, 11.5), + FINGER_RADIUS, + tau * 5 / 8, + tau * 7 / 8, + 1, ), StrokeCircleSegment( - (13.25, 12), FINGER_RADIUS, tau * 5 / 8, tau * 7 / 8, 1, + (13.25, 12), + FINGER_RADIUS, + tau * 5 / 8, + tau * 7 / 8, + 1, ), StrokeCircleSegment( - (15.5, 12.5), FINGER_RADIUS, tau * 5 / 8, tau, 1, + (15.5, 12.5), + FINGER_RADIUS, + tau * 5 / 8, + tau, + 1, ), StrokeRoundLine((16.75, 12.5), (17, 16), 1), StrokeCircleSegment((8.25, 6), 3, pi, tau, 1), diff --git a/zenbook_conf/xrandr.py b/zenbook_conf/xrandr.py index 3f69415..a47e88c 100644 --- a/zenbook_conf/xrandr.py +++ b/zenbook_conf/xrandr.py @@ -12,7 +12,11 @@ class XrandrConf: MM_SIZE_PATTERN = re.compile(r"(\d+)mm x (\d+)mm") DIRECTIONS = ("normal", "left", "inverted", "right", "invalid direction") REFLECTIONS = ( - "none", "[Xx] axis", "[Yy] axis", "X and Y axis", "invalid reflection" + "none", + "[Xx] axis", + "[Yy] axis", + "X and Y axis", + "invalid reflection", ) DIRECTIONS_REFLECTIONS_PATTERN = re.compile( f"({'|'.join(DIRECTIONS)})( {'|'.join(REFLECTIONS)})? \\(" @@ -46,7 +50,8 @@ class XrandrConf: { "name": name, "size": cls.int_tuple(cls.strip_each(size.split("x"))), - } for name, size in ( + } + for name, size in ( cls.strip_each(p.split(" ", 1)) for p in cls.strip_each(sizes.split(",")) ) @@ -58,9 +63,7 @@ class XrandrConf: name, connected, rest = self.strip_each(line.split(" ", 2)) output = { "name": name, - "connected": self.CONNECTED_MAPPING.get( - connected, "unknown connection" - ), + "connected": self.CONNECTED_MAPPING.get(connected, "unknown connection"), } if output["connected"] is False: return output @@ -69,9 +72,7 @@ class XrandrConf: if self.simple or resolution is None: return output parsed = self.int_tuple(resolution.group(i) for i in range(1, 5)) - direction_reflection = ( - self.DIRECTIONS_REFLECTIONS_PATTERN.search(rest) - ) + direction_reflection = self.DIRECTIONS_REFLECTIONS_PATTERN.search(rest) end = direction_reflection.end() output.update( { @@ -83,17 +84,15 @@ class XrandrConf: "available_rotations_reflections": [ m.group(0) for m in self.AVAILABLE_DIRECTIONS_REFLECTIONS_PATTERN.finditer( - rest[end:rest.find(")", end)] + rest[end : rest.find(")", end)] ) ], - "modes": [] + "modes": [], } ) mm_size = self.MM_SIZE_PATTERN.search(rest) if mm_size: - output["mm_size"] = ( - int(mm_size.group(1)), int(mm_size.group(2)) - ) + output["mm_size"] = (int(mm_size.group(1)), int(mm_size.group(2))) return output @classmethod @@ -123,9 +122,9 @@ class XrandrConf: def get_conf(self): screens = [] current_screen = None - lines = subprocess.check_output( - ["xrandr", "--verbose"], text=True - ).split(os.linesep) + lines = subprocess.check_output(["xrandr", "--verbose"], text=True).split( + os.linesep + ) for i, line in enumerate(lines): if not line: continue @@ -138,14 +137,14 @@ class XrandrConf: output = screens[current_screen]["outputs"][-1] if line[3] == " " or "modes" not in output: continue - output["modes"].append(self.parse_mode(*lines[i:i + 3])) + output["modes"].append(self.parse_mode(*lines[i : i + 3])) return screens @classmethod def call(cls, output, *args, **kwargs): args = [f"--{arg}" for arg in args] for key, value in kwargs.items(): - args.extend((f"--{key.replace("_", "-")}", value)) + args.extend((f"--{key.replace('_', '-')}", value)) return subprocess.run(["xrandr", "--output", cls.OUTPUTS[output], *args]) def renew(self): diff --git a/zenbook_conf/zenbook_conf.py b/zenbook_conf/zenbook_conf.py index 16171ec..4e3463e 100644 --- a/zenbook_conf/zenbook_conf.py +++ b/zenbook_conf/zenbook_conf.py @@ -35,7 +35,7 @@ class Root(BaseRoot): self, pygame.Rect((128, 612), (256, 128)), self.bluetooth_conf.update, - self.bluetooth_conf.conf + self.bluetooth_conf.conf, ) touch_switch = Switch( self, @@ -55,9 +55,7 @@ class Root(BaseRoot): laptop_single.fit((100, top + 32), (16, 16)), pygame.Rect((68, top), (416, 416)), None, - partial( - self.laptop_cb, "single", bt_switch, touch_switch, stylus_switch - ), + partial(self.laptop_cb, "single", bt_switch, touch_switch, stylus_switch), self.xrandr_conf.is_active("single"), ) self.double_button = IconButton( @@ -65,9 +63,7 @@ class Root(BaseRoot): laptop_double.fit((600, top + 32), (16, 16)), pygame.Rect((568, top), (416, 416)), None, - partial( - self.laptop_cb, "double", bt_switch, touch_switch, stylus_switch - ), + partial(self.laptop_cb, "double", bt_switch, touch_switch, stylus_switch), self.xrandr_conf.is_active("double"), ) self.vertical_button = IconButton( @@ -113,13 +109,13 @@ class Root(BaseRoot): self, pygame.Rect((784, touch_switch.rect.top), (384, 128)), "Re-apply", - partial(self.xinput_conf.reapply_by_type, "touchpad") + partial(self.xinput_conf.reapply_by_type, "touchpad"), ) Button( self, pygame.Rect((784, stylus_switch.rect.top), (384, 128)), "Re-apply", - partial(self.xinput_conf.reapply_by_type, "stylus") + partial(self.xinput_conf.reapply_by_type, "stylus"), ) Button( self,