From f0159eb6ff177ec9bd28c270585840388b24d911 Mon Sep 17 00:00:00 2001 From: Andrew Hamilton Date: Tue, 31 May 2022 16:41:09 +1000 Subject: [PATCH] Coding style - Use match statement where possible. --- eris/eris/__main__.py | 13 +++++++------ fill3/fill3/__init__.py | 34 ++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/eris/eris/__main__.py b/eris/eris/__main__.py index bb1a32d..da6e76a 100755 --- a/eris/eris/__main__.py +++ b/eris/eris/__main__.py @@ -616,12 +616,13 @@ class Help: def on_mouse_input(self, term_code): event = terminal.decode_mouse_input(term_code) - if event[1] == terminal.MOUSE_WHEEL_UP: - self.view.portal.scroll_up() - fill3.APPEARANCE_CHANGED_EVENT.set() - elif event[1] == terminal.MOUSE_WHEEL_DOWN: - self.view.portal.scroll_down() - fill3.APPEARANCE_CHANGED_EVENT.set() + match event[1]: + case terminal.MOUSE_WHEEL_UP: + self.view.portal.scroll_up() + fill3.APPEARANCE_CHANGED_EVENT.set() + case terminal.MOUSE_WHEEL_DOWN: + self.view.portal.scroll_down() + fill3.APPEARANCE_CHANGED_EVENT.set() def on_keyboard_input(self, term_code): action = self.key_map.get(term_code) or self.key_map.get(term_code.lower()) diff --git a/fill3/fill3/__init__.py b/fill3/fill3/__init__.py index e09a5b7..49ec20b 100755 --- a/fill3/fill3/__init__.py +++ b/fill3/fill3/__init__.py @@ -236,27 +236,29 @@ class Portal: widget_width, widget_height = appearance_dimensions x, y = self.position if widget_width <= portal_width: - if self.x_alignment == Alignment.left: - x = 0 - elif self.x_alignment == Alignment.center: - x = (widget_width - portal_width) // 2 - elif self.x_alignment == Alignment.right: - x = widget_width - portal_width - else: - raise NotImplementedError + match self.x_alignment: + case Alignment.left: + x = 0 + case Alignment.center: + x = (widget_width - portal_width) // 2 + case Alignment.right: + x = widget_width - portal_width + case _: + raise NotImplementedError elif x < 0: x = 0 elif x > (widget_width - portal_width): x = widget_width - portal_width if widget_height <= portal_height: - if self.y_alignment == Alignment.top: - y = 0 - elif self.y_alignment == Alignment.center: - y = (widget_height - portal_height) // 2 - elif self.y_alignment == Alignment.bottom: - y = widget_height - portal_height - else: - raise NotImplementedError + match self.y_alignment: + case Alignment.top: + y = 0 + case Alignment.center: + y = (widget_height - portal_height) // 2 + case Alignment.bottom: + y = widget_height - portal_height + case _: + raise NotImplementedError elif y < 0: y = 0 elif y > (widget_height - portal_height):