diff --git a/src/badger/gui/mini/pages/routine_page.py b/src/badger/gui/mini/pages/routine_page.py index 4bed3b91..7791caac 100644 --- a/src/badger/gui/mini/pages/routine_page.py +++ b/src/badger/gui/mini/pages/routine_page.py @@ -58,7 +58,7 @@ from badger.gui.windows.review_dialog import BadgerReviewDialog from badger.gui.windows.add_random_dialog import BadgerAddRandomDialog from badger.gui.windows.message_dialog import BadgerScrollableMessageBox -from badger.gui.utils import filter_generator_config +from badger.gui.utils import filter_generator_config, with_busy_cursor from badger.environment import instantiate_env from badger.errors import ( BadgerEnvNotFoundError, @@ -1067,6 +1067,7 @@ def refresh_params_generator(self): except Exception as e: QMessageBox.warning(self, "Invalid script!", str(e)) + @with_busy_cursor def select_env(self, i: int): logger.info(f"Environment selected: {self.env_box.env_name} (index={i})") # Reset the initial table actions and ratio var ranges diff --git a/src/badger/gui/utils.py b/src/badger/gui/utils.py index ef5f03a9..c3d977ef 100644 --- a/src/badger/gui/utils.py +++ b/src/badger/gui/utils.py @@ -5,10 +5,12 @@ from importlib import resources from typing import Any from PyQt5.QtWidgets import QAbstractSpinBox, QPushButton, QComboBox, QToolButton -from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel +from PyQt5.QtWidgets import QDialog, QVBoxLayout, QLabel, QApplication from PyQt5.QtCore import Qt, QObject, QEvent, QSize from PyQt5.QtGui import QIcon import copy +from functools import wraps +from typing import Callable def preventAnnoyingSpinboxScrollBehaviour(self, control: QAbstractSpinBox) -> None: @@ -119,3 +121,23 @@ def __init__(self, parent=None, info=None): self.setLayout(layout) # Semi-transparent background self.setStyleSheet("background-color: rgba(0, 0, 0, 80);") + + +def set_busy_cursor() -> None: + QApplication.setOverrideCursor(Qt.BusyCursor) + + +def unset_busy_cursor() -> None: + QApplication.restoreOverrideCursor() + + +def with_busy_cursor(func: Callable) -> Callable: + @wraps(func) + def wrapped(*args, **kwargs): + set_busy_cursor() + try: + return func(*args, **kwargs) + finally: + unset_busy_cursor() + + return wrapped diff --git a/src/badger/gui/windows/expandable_message_box.py b/src/badger/gui/windows/expandable_message_box.py index cc887257..52b34eeb 100644 --- a/src/badger/gui/windows/expandable_message_box.py +++ b/src/badger/gui/windows/expandable_message_box.py @@ -12,6 +12,7 @@ ) from PyQt5.QtGui import QTextOption, QFont, QFontDatabase from PyQt5.QtCore import Qt +from badger.gui.utils import unset_busy_cursor class ExpandableMessageBox(QDialog): @@ -21,6 +22,8 @@ def __init__( super().__init__(parent) self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint) + unset_busy_cursor() + # Main layout mainLayout = QVBoxLayout(self)