Prevent multiple non-modal dialogs of the same kind from being opened

This commit is contained in:
Veronica Berglyd Olsen
2024-01-27 15:38:44 +01:00
parent 2772c9bf0b
commit 9311117257
3 changed files with 28 additions and 17 deletions
+10 -1
View File
@@ -27,7 +27,7 @@ from __future__ import annotations
import logging
from time import time
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, TypeVar
from pathlib import Path
from PyQt5.QtCore import QObject, QRunnable, QThreadPool, pyqtSignal
@@ -42,6 +42,8 @@ if TYPE_CHECKING: # pragma: no cover
logger = logging.getLogger(__name__)
NWWidget = TypeVar("NWWidget", bound=QWidget)
class SharedData(QObject):
@@ -215,6 +217,13 @@ class SharedData(QObject):
QThreadPool.globalInstance().start(runnable, priority=priority)
return
def findTopLevelWidget(self, kind: type[NWWidget]) -> NWWidget | None:
"""Find a top level widget."""
for widget in self.mainGui.children():
if isinstance(widget, kind):
return widget
return None
##
# Signal Proxy
##