import sys import time from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QPushButton, QLabel from PyQt6.QtCore import QObject, pyqtSignal, Qt class ThreadSafetyTool(QObject): """Marshal function calls to the main thread.""" _signal = pyqtSignal(object, tuple, dict) def __init__(self): super().__init__() self._signal.connect(self._execute, Qt.ConnectionType.QueuedConnection) def _execute(self, func, args, kwargs): func(*args, **kwargs) def __call__(self, func): """Decorator that forces a function to run on the main thread.""" def wrapper(*args, **kwargs): self._signal.emit(func, args, kwargs) return wrapper