From 8c407f335b94399a5f1c3341aea439841f0caa7d Mon Sep 17 00:00:00 2001 From: andreasgriffin Date: Sun, 30 Jun 2024 14:50:48 +0200 Subject: [PATCH] bug fix make the timer not dependent on the window... can clear to exceptions if window is destroyed --- bitcoin_qr_tools/qr_widgets.py | 22 ++++++++++++++++++++-- pyproject.toml | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/bitcoin_qr_tools/qr_widgets.py b/bitcoin_qr_tools/qr_widgets.py index a718048..8353a7e 100644 --- a/bitcoin_qr_tools/qr_widgets.py +++ b/bitcoin_qr_tools/qr_widgets.py @@ -34,7 +34,15 @@ from PIL import Image from PyQt6.QtCore import QByteArray, QEvent, QRectF, QSize, Qt, QTimer -from PyQt6.QtGui import QImage, QKeyEvent, QMouseEvent, QPainter, QPaintEvent, QPixmap +from PyQt6.QtGui import ( + QCloseEvent, + QImage, + QKeyEvent, + QMouseEvent, + QPainter, + QPaintEvent, + QPixmap, +) from PyQt6.QtSvg import QSvgRenderer from PyQt6.QtWidgets import QApplication, QDialog, QWidget @@ -121,6 +129,11 @@ def enlarge_image(self): def mousePressEvent(self, event: QMouseEvent): self.enlarge_image() + def closeEvent(self, event: QCloseEvent) -> None: + if self.enlarged_image: + self.enlarged_image.close() + super().closeEvent(event) + class EnlargedImage(ImageWidget): def __init__(self, pil_image: Image, parent=None, screen_fraction=0.4): @@ -191,7 +204,7 @@ def __init__(self, always_animate=False, clickable=True, parent=None): if clickable: self.setCursor(Qt.CursorShape.PointingHandCursor) - self.timer = QTimer(self) + self.timer = QTimer() self.timer.timeout.connect(self.next_svg) def sizeHint(self) -> QSize: @@ -346,6 +359,11 @@ def as_pil_images(self): if renderer.isValid() ] + def closeEvent(self, event: QCloseEvent) -> None: + self.timer.stop() + self.enlarged_image.close() + super().closeEvent(event) + class EnlargedSVG(QDialog): def __init__(self, svg_renderer: QSvgRenderer, parent=None, screen_fraction=0.5): diff --git a/pyproject.toml b/pyproject.toml index c5fa518..4e1deb6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ disable_error_code = "assignment" [tool.poetry] name = "bitcoin-qr-tools" -version = "0.10.2" +version = "0.10.3" authors = ["andreasgriffin "] license = "GPL-3.0" readme = "README.md"