mirror of
https://github.com/LorenEteval/Furious.git
synced 2026-10-05 21:37:56 +03:00
Refine Qt top-level widget lifetimes
Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
@@ -30,18 +30,10 @@ from PySide6.QtGui import *
|
||||
from PySide6.QtWidgets import *
|
||||
|
||||
import io
|
||||
import functools
|
||||
import pyqrcode
|
||||
|
||||
__all__ = ['QRCodeWindow']
|
||||
|
||||
_OpenQRCodeWindows = {}
|
||||
|
||||
|
||||
def _releaseOpenQRCodeWindow(key, *_args):
|
||||
"""Release an exported QR-code window after Qt destroys it."""
|
||||
_OpenQRCodeWindows.pop(key, None)
|
||||
|
||||
|
||||
class QRCodeWindow(AppQMainWindow):
|
||||
"""Present the QR code window."""
|
||||
@@ -54,28 +46,12 @@ class QRCodeWindow(AppQMainWindow):
|
||||
self.setFixedSize(640, 640)
|
||||
self.setAttribute(QtCore.Qt.WidgetAttribute.WA_DeleteOnClose, True)
|
||||
|
||||
self._lifetimeKey = id(self)
|
||||
self.destroyed.connect(
|
||||
functools.partial(_releaseOpenQRCodeWindow, self._lifetimeKey)
|
||||
)
|
||||
|
||||
self.tabWidget = QTabWidget(self)
|
||||
self.tabWidget.setTabsClosable(True)
|
||||
self.tabWidget.tabCloseRequested.connect(self.handleTabCloseRequested)
|
||||
|
||||
self.setCentralWidget(self.tabWidget)
|
||||
|
||||
def show(self):
|
||||
"""Show and retain this unparented window until Qt destroys it."""
|
||||
_OpenQRCodeWindows[self._lifetimeKey] = self
|
||||
|
||||
try:
|
||||
return super().show()
|
||||
except Exception:
|
||||
_releaseOpenQRCodeWindow(self._lifetimeKey)
|
||||
|
||||
raise
|
||||
|
||||
def tabCount(self) -> int:
|
||||
"""Return the tab count value used by the QR code window."""
|
||||
return self.tabWidget.count()
|
||||
|
||||
Reference in New Issue
Block a user