Source code for mantidimaging.gui.windows.welcome_screen.presenter

# Copyright (C) 2022 ISIS Rutherford Appleton Laboratory UKRI
# SPDX - License - Identifier: GPL-3.0-or-later

from PyQt5.QtCore import QSettings
from logging import getLogger

from mantidimaging.core.utility import cuda_check
from mantidimaging.gui.mvp_base.presenter import BasePresenter
from mantidimaging.gui.windows.welcome_screen.view import WelcomeScreenView
from mantidimaging.core.utility.version_check import versions

LOG = getLogger(__name__)

WELCOME_LINKS = [["Homepage", "https://github.com/mantidproject/mantidimaging"],
                 ["Documentation", "https://mantidproject.github.io/mantidimaging/index.html"],
                 ["Troubleshooting", "https://mantidproject.github.io/mantidimaging/troubleshooting.html"]]


[docs] class WelcomeScreenPresenter(BasePresenter): def __init__(self, parent=None, view=None): if view is None: view = WelcomeScreenView(parent, self) super().__init__(view) self.settings = QSettings() self.link_count = 0 self.do_set_up()
[docs] def do_set_up(self): self.view.set_version_label(f"Mantid Imaging {versions.get_version()}") self.set_up_links() self.set_up_show_at_start() self.check_issues()
[docs] def show(self): self.view.show()
[docs] @staticmethod def show_at_start_enabled(): settings = QSettings() return settings.value("welcome_screen/show_at_start", defaultValue=True, type=bool)
[docs] @staticmethod def show_today(): """Show if show_at_start or if version has changed""" settings = QSettings() show_at_start = settings.value("welcome_screen/show_at_start", defaultValue=True, type=bool) if not show_at_start: last_run_version = settings.value("welcome_screen/last_run_version", defaultValue="") if last_run_version != versions.get_conda_installed_version(): return True else: return show_at_start
[docs] def set_up_show_at_start(self): show_at_start = WelcomeScreenPresenter.show_at_start_enabled() self.view.set_show_at_start(show_at_start) self.show_at_start_changed()
[docs] def show_at_start_changed(self): show_at_start = self.view.get_show_at_start() self.settings.setValue("welcome_screen/show_at_start", show_at_start) self.settings.setValue("welcome_screen/last_run_version", versions.get_conda_installed_version())
[docs] def check_issues(self): issues = [] if not versions.is_conda_uptodate(): msg, detailed = versions.conda_update_message() issues.append(msg) LOG.info(detailed) if not cuda_check.CudaChecker().cuda_is_present(): msg, detailed = cuda_check.not_found_message() issues.append(msg) LOG.info(detailed) if issues: self.view.add_issues("\n".join(issues))