From de9e2cfc404cbf3553f9e98f14d3b89e6449f969 Mon Sep 17 00:00:00 2001 From: Ben Kerman Date: Thu, 16 Mar 2023 07:02:16 +0100 Subject: [PATCH] Check for division by zero when calculating browser aspect ratio (#2437) --- CONTRIBUTORS | 1 + qt/aqt/browser/browser.py | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b113e4775..a2d8fc932 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -116,6 +116,7 @@ Daniel Tang Jack Pearson yellowjello Ingemar Berg +Ben Kerman ******************** diff --git a/qt/aqt/browser/browser.py b/qt/aqt/browser/browser.py index c4e9bc696..574e803ad 100644 --- a/qt/aqt/browser/browser.py +++ b/qt/aqt/browser/browser.py @@ -153,7 +153,7 @@ class Browser(QMainWindow): restoreState(self, self._editor_state_key) # responsive layout - self.aspect_ratio = self.width() / self.height() + self.aspect_ratio = self.width() / self.height() if self.height() != 0 else 0 self.set_layout(self.mw.pm.browser_layout(), True) # disable undo/redo self.on_undo_state_change(mw.undo_actions_info()) @@ -234,12 +234,13 @@ class Browser(QMainWindow): self.form.splitter.setOrientation(Qt.Orientation.Horizontal) def resizeEvent(self, event: QResizeEvent) -> None: - aspect_ratio = self.width() / self.height() + if self.height() != 0: + aspect_ratio = self.width() / self.height() - if self.auto_layout: - self.maybe_update_layout(aspect_ratio) + if self.auto_layout: + self.maybe_update_layout(aspect_ratio) - self.aspect_ratio = aspect_ratio + self.aspect_ratio = aspect_ratio QMainWindow.resizeEvent(self, event)