From 9ef547839685ce640ce9b1c2dab68a9b788995cd Mon Sep 17 00:00:00 2001 From: Julianne Swinoga Date: Sat, 24 Feb 2024 15:53:10 -0500 Subject: [PATCH] Add various warning banners to aid user visibility Needed to change from direct signals to a shared global variable and polling --- OATFWGUI/log_utils.py | 2 ++ OATFWGUI/main.py | 4 ++++ OATFWGUI/platform_check.py | 3 +++ OATFWGUI/qwarningbannerholder.py | 25 ++++++++++++++++++++----- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/OATFWGUI/log_utils.py b/OATFWGUI/log_utils.py index 0a19b48..4517c86 100644 --- a/OATFWGUI/log_utils.py +++ b/OATFWGUI/log_utils.py @@ -13,6 +13,7 @@ from external_processes import get_install_dir from platform_check import get_platform, PlatformEnum from qt_extensions import get_signal +from qwarningbannerholder import global_warning_banners class LogObject(QObject): @@ -110,6 +111,7 @@ def create_file(self, file_suffix: str = '') -> Optional[str]: watch_success = self.file_watcher.addPath(self.tempfile.name) if not watch_success: self.log.warning(f'Could not watch external file: {self.tempfile.name}') + global_warning_banners.add(f'Could not watch external file: {self.tempfile.name}') return None return self.tempfile.name diff --git a/OATFWGUI/main.py b/OATFWGUI/main.py index 790585f..ebf5465 100755 --- a/OATFWGUI/main.py +++ b/OATFWGUI/main.py @@ -24,6 +24,7 @@ from gui_logic import BusinessLogic from platform_check import get_platform, PlatformEnum from external_processes import external_processes, add_external_process, get_install_dir +from qwarningbannerholder import global_warning_banners from anon_usage_data import create_anon_stats from misc_utils import delete_directory @@ -43,6 +44,7 @@ def check_and_warn_directory_path_length(dir_to_check: Path, max_path_len: int, lengths greater than the default Windows path length of 260 characters. ''' log.warning(general_warn_str + warn_str) + global_warning_banners.add(f'{dir_to_check} might have too many characters in it ({num_chars_in_dir})!') def setup_environment(): @@ -107,6 +109,7 @@ def raw_version_to_semver() -> Optional[semver.VersionInfo]: semver_ver = semver.VersionInfo.parse(__version__) except ValueError as e: log.warning(f'Could not parse my own version string {__version__} {e}') + global_warning_banners.add(f'Could not parse my own version string {__version__}') return None return semver_ver @@ -130,6 +133,7 @@ def check_new_oatfwgui_release() -> Optional[Tuple[str, str]]: release_ver = semver.VersionInfo.parse(release_json['tag_name']) except ValueError as e: log.warning(f'Could not parse tag name as semver {release_json["tag_name"]} {e}') + global_warning_banners.add(f'Could not parse tag name as semver {release_json["tag_name"]}') continue releases[release_ver] = release_json['html_url'] if latest_release_ver is None or release_ver > latest_release_ver: diff --git a/OATFWGUI/platform_check.py b/OATFWGUI/platform_check.py index 8049c7e..28df41a 100644 --- a/OATFWGUI/platform_check.py +++ b/OATFWGUI/platform_check.py @@ -2,6 +2,8 @@ import platform import logging +from qwarningbannerholder import global_warning_banners + platform_lookup_cache = None log = logging.getLogger('') @@ -33,5 +35,6 @@ def get_platform() -> PlatformEnum: log.debug(f'platform_str={platform_str}') if platform_lookup == PlatformEnum.UNKNOWN: log.warning(f'Unknown platform {platform_str}!') + global_warning_banners.add(f'Unknown platform {platform_str}!') return platform_lookup diff --git a/OATFWGUI/qwarningbannerholder.py b/OATFWGUI/qwarningbannerholder.py index 495d2d7..44b8322 100644 --- a/OATFWGUI/qwarningbannerholder.py +++ b/OATFWGUI/qwarningbannerholder.py @@ -1,9 +1,11 @@ -from typing import List +from typing import List, Set -from PySide6.QtCore import Slot, Signal, Qt +from PySide6.QtCore import Slot, Signal, Qt, QTimer from PySide6.QtWidgets import QVBoxLayout, QSizePolicy, QLabel from qt_extensions import RegisteredCustomWidget +global_warning_banners: Set[str] = set() + class QWarningBannerHolder(RegisteredCustomWidget): add_warning_signal = Signal(str) @@ -16,12 +18,25 @@ def __init__(self, parent=None): self.vbox = QVBoxLayout() self.vbox.setAlignment(Qt.AlignHCenter) self.setLayout(self.vbox) + + self.check_timer = QTimer(self) + self.check_timer.timeout.connect(self.check_global_warnings) + self.check_timer.setInterval(1000) # every second + self.check_timer.start() + self.add_warning_signal.connect(self.add_warning) if self.running_in_designer(): - self.add_warning_signal.emit('Test warning 1') - self.add_warning_signal.emit('Test warning 2') - self.add_warning_signal.emit('Test warning 3') + global_warning_banners.add('Test warning 1') + global_warning_banners.add('Test warning 2') + global_warning_banners.add('Test warning 3') + + def check_global_warnings(self): + # Just go through all of our labels and compare the text + # Not efficient but whatever + for warn_str in global_warning_banners: + if not any(warn_str in wid.text() for wid in self.label_widgets): + self.add_warning_signal.emit(warn_str) # Need to use signals and slots else we get: # QObject::setParent: Cannot set parent, new parent is in a different thread