Skip to content

Commit

Permalink
Add various warning banners to aid user visibility
Browse files Browse the repository at this point in the history
Needed to change from direct signals to a shared global variable and
polling
  • Loading branch information
julianneswinoga committed Feb 25, 2024
1 parent 0f43a6f commit 9ef5478
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions OATFWGUI/log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions OATFWGUI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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():
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions OATFWGUI/platform_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import platform
import logging

from qwarningbannerholder import global_warning_banners

platform_lookup_cache = None
log = logging.getLogger('')

Expand Down Expand Up @@ -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
25 changes: 20 additions & 5 deletions OATFWGUI/qwarningbannerholder.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 9ef5478

Please sign in to comment.