From ac10be4e6e6b758692690492dff8bbebaa26b52e Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Thu, 14 Mar 2024 17:09:59 +0000 Subject: [PATCH 01/19] basic theme used --- mantidimaging/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mantidimaging/main.py b/mantidimaging/main.py index ac3206daa4a..f770f182fcb 100755 --- a/mantidimaging/main.py +++ b/mantidimaging/main.py @@ -17,6 +17,8 @@ from mantidimaging import helper as h from mantidimaging.core.utility.command_line_arguments import CommandLineArguments +from qt_material import apply_stylesheet + formatwarning_orig = warnings.formatwarning warnings.formatwarning = lambda message, category, filename, lineno, line=None: formatwarning_orig( message, category, filename, lineno, line="") @@ -57,7 +59,9 @@ def parse_args() -> argparse.Namespace: def setup_application() -> QApplication: QGuiApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) q_application = QApplication(sys.argv) - q_application.setStyle('Fusion') + #q_application.setStyle('Fusion') + + apply_stylesheet(q_application, theme='light_blue.xml', invert_secondary=True) q_application.setApplicationName("Mantid Imaging") q_application.setOrganizationName("mantidproject") q_application.setOrganizationDomain("mantidproject.org") From 5fd9e4fb8f8ac8c0da314ba07e797f04b2b3e047 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Fri, 15 Mar 2024 17:53:29 +0000 Subject: [PATCH 02/19] Settings menu added which theme combobox added --- mantidimaging/gui/mvp_base/view.py | 10 ++ mantidimaging/gui/ui/main_window.ui | 9 +- mantidimaging/gui/ui/settings_window.ui | 100 ++++++++++++++++++ mantidimaging/gui/windows/main/view.py | 30 +++++- .../gui/windows/settings/__init__.py | 3 + .../gui/windows/settings/presenter.py | 33 ++++++ mantidimaging/gui/windows/settings/view.py | 44 ++++++++ mantidimaging/main.py | 17 ++- 8 files changed, 240 insertions(+), 6 deletions(-) create mode 100644 mantidimaging/gui/ui/settings_window.ui create mode 100644 mantidimaging/gui/windows/settings/__init__.py create mode 100644 mantidimaging/gui/windows/settings/presenter.py create mode 100644 mantidimaging/gui/windows/settings/view.py diff --git a/mantidimaging/gui/mvp_base/view.py b/mantidimaging/gui/mvp_base/view.py index 95902f4ed03..e26fd4e8abd 100644 --- a/mantidimaging/gui/mvp_base/view.py +++ b/mantidimaging/gui/mvp_base/view.py @@ -5,13 +5,16 @@ import time from logging import getLogger +from PyQt5 import QtCore from PyQt5.QtCore import Qt, QTimer from PyQt5.QtWidgets import QMainWindow, QMessageBox, QDialog +from qt_material import apply_stylesheet from mantidimaging.gui.utility import compile_ui LOG = getLogger(__name__) perf_logger = getLogger("perf." + __name__) +settings = QtCore.QSettings('mantidproject', 'Mantid Imaging') class BaseMainWindowView(QMainWindow): @@ -25,6 +28,13 @@ def __init__(self, parent, ui_file=None): if ui_file is not None: compile_ui(ui_file, self) + print(f"mvp_case: {settings.value('theme_selection')=}") + + if settings.value('theme_selection') == 'Fusion': + self.setStyleSheet('Fusion') + else: + apply_stylesheet(self, theme=settings.value('theme_selection'), invert_secondary=False) + def closeEvent(self, e): LOG.debug('UI window closed') self.cleanup() diff --git a/mantidimaging/gui/ui/main_window.ui b/mantidimaging/gui/ui/main_window.ui index 34715b3c458..e9e5f67babb 100644 --- a/mantidimaging/gui/ui/main_window.ui +++ b/mantidimaging/gui/ui/main_window.ui @@ -27,7 +27,7 @@ 0 0 1100 - 25 + 22 @@ -46,6 +46,8 @@ + + @@ -239,6 +241,11 @@ Open Live Viewer + + + Settings + + diff --git a/mantidimaging/gui/ui/settings_window.ui b/mantidimaging/gui/ui/settings_window.ui new file mode 100644 index 00000000000..c3aebfe3a7a --- /dev/null +++ b/mantidimaging/gui/ui/settings_window.ui @@ -0,0 +1,100 @@ + + + SettingsWindow + + + + 0 + 0 + 418 + 348 + + + + MainWindow + + + + + + 10 + 10 + 1921 + 951 + + + + + 1 + 1 + + + + + + + + 1 + 1 + + + + 0 + + + + Appearance + + + + + 10 + 10 + 341 + 241 + + + + + + + Theme: + + + + + + + + 0 + 0 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + diff --git a/mantidimaging/gui/windows/main/view.py b/mantidimaging/gui/windows/main/view.py index 73dfc52d0f3..0b0bec370eb 100644 --- a/mantidimaging/gui/windows/main/view.py +++ b/mantidimaging/gui/windows/main/view.py @@ -11,10 +11,11 @@ from uuid import UUID import numpy as np -from PyQt5.QtCore import Qt, pyqtSignal, QUrl, QPoint +from PyQt5.QtCore import Qt, pyqtSignal, QUrl, QPoint, QSettings from PyQt5.QtGui import QIcon, QDragEnterEvent, QDropEvent, QDesktopServices from PyQt5.QtWidgets import QAction, QDialog, QLabel, QMessageBox, QMenu, QFileDialog, QSplitter, \ QTreeWidgetItem, QTreeWidget +from qt_material import apply_stylesheet from mantidimaging.core.data import ImageStack from mantidimaging.core.data.dataset import StrictDataset @@ -37,6 +38,7 @@ from mantidimaging.gui.windows.nexus_load_dialog.view import NexusLoadDialog from mantidimaging.gui.windows.operations import FiltersWindowView from mantidimaging.gui.windows.recon import ReconstructWindowView +from mantidimaging.gui.windows.settings.view import SettingsWindowView from mantidimaging.gui.windows.spectrum_viewer.view import SpectrumViewerWindowView from mantidimaging.gui.windows.live_viewer.view import LiveViewerWindowView from mantidimaging.gui.windows.stack_choice.compare_presenter import StackComparePresenter @@ -54,6 +56,8 @@ LOG = getLogger(__name__) perf_logger = getLogger("perf." + __name__) +settings = QSettings('mantidproject', 'Mantid Imaging') + class QTreeDatasetWidgetItem(QTreeWidgetItem): @@ -94,12 +98,14 @@ class MainWindowView(BaseMainWindowView): actionLoadNeXusFile: QAction actionSaveImages: QAction actionSaveNeXusFile: QAction + actionSettings: QAction actionExit: QAction filters: FiltersWindowView | None = None recon: ReconstructWindowView | None = None spectrum_viewer: SpectrumViewerWindowView | None = None live_viewer: LiveViewerWindowView | None = None + settings_window: SettingsWindowView | None = None image_load_dialog: ImageLoadDialog | None = None image_save_dialog: ImageSaveDialog | None = None @@ -108,6 +114,8 @@ class MainWindowView(BaseMainWindowView): add_to_dataset_dialog: AddImagesToDatasetDialog | None = None move_stack_dialog: MoveStackDialog | None = None + default_theme_enabled: int = 1 + def __init__(self, open_dialogs: bool = True): super().__init__(None, "gui/ui/main_window.ui") @@ -193,6 +201,7 @@ def setup_shortcuts(self): self.actionRecon.triggered.connect(self.show_recon_window) self.actionSpectrumViewer.triggered.connect(self.show_spectrum_viewer_window) self.actionLiveViewer.triggered.connect(self.live_view_choose_directory) + self.actionSettings.triggered.connect(self.show_settings_window) self.actionCompareImages.triggered.connect(self.show_stack_select_dialog) @@ -372,6 +381,23 @@ def show_nexus_save_dialog(self): self.nexus_save_dialog = NexusSaveDialog(self, self.strict_dataset_list) self.nexus_save_dialog.show() + def show_settings_window(self): + if not self.settings_window: + self.settings_window = SettingsWindowView(self) + self.settings_window.show() + else: + self.settings_window.activateWindow() + self.settings_window.raise_() + self.settings_window.show() + + def set_theme(self, theme: str) -> None: + for window in [self, self.recon, self.live_viewer, self.spectrum_viewer, self.filters, self.settings_window]: + if window: + if theme == 'Fusion': + window.setStyleSheet(theme) + else: + apply_stylesheet(window, theme=theme, invert_secondary=False) + def show_recon_window(self): if not self.recon: self.recon = ReconstructWindowView(self) @@ -507,6 +533,8 @@ def closeEvent(self, event): self.spectrum_viewer.close() if self.filters: self.filters.close() + if self.settings_window: + self.settings_window.close() else: # Ignore the close event, keeping window open diff --git a/mantidimaging/gui/windows/settings/__init__.py b/mantidimaging/gui/windows/settings/__init__.py new file mode 100644 index 00000000000..ce6ef2fb43a --- /dev/null +++ b/mantidimaging/gui/windows/settings/__init__.py @@ -0,0 +1,3 @@ +# Copyright (C) 2024 ISIS Rutherford Appleton Laboratory UKRI +# SPDX - License - Identifier: GPL-3.0-or-later +from __future__ import annotations diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py new file mode 100644 index 00000000000..387e077fd36 --- /dev/null +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -0,0 +1,33 @@ +# Copyright (C) 2024 ISIS Rutherford Appleton Laboratory UKRI +# SPDX - License - Identifier: GPL-3.0-or-later +from __future__ import annotations + +from logging import getLogger +from typing import TYPE_CHECKING + +from PyQt5.QtCore import QSettings + +from mantidimaging.gui.mvp_base import BasePresenter + +LOG = getLogger(__name__) + +if TYPE_CHECKING: + from mantidimaging.gui.windows.settings.view import SettingsWindowView # pragma: no cover + from mantidimaging.gui.windows.main import MainWindowView + +settings = QSettings('mantidproject', 'Mantid Imaging') + + +class SettingsWindowPresenter(BasePresenter): + view: 'SettingsWindowView' + + def __init__(self, view: 'SettingsWindowView', main_window: 'MainWindowView'): + super().__init__(view) + self.view = view + self.main_window = main_window + self.current_theme = settings.value('theme_selection') + + def set_theme(self): + self.current_theme = self.view.current_theme + settings.setValue('theme_selection', self.current_theme) + self.main_window.set_theme(self.current_theme) diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py new file mode 100644 index 00000000000..4e7ebbeaee0 --- /dev/null +++ b/mantidimaging/gui/windows/settings/view.py @@ -0,0 +1,44 @@ +# Copyright (C) 2024 ISIS Rutherford Appleton Laboratory UKRI +# SPDX - License - Identifier: GPL-3.0-or-later +from __future__ import annotations +from logging import getLogger +from typing import TYPE_CHECKING + +from PyQt5.QtCore import QSettings +from PyQt5.QtWidgets import QTabWidget, QWidget, QComboBox, QLabel + +from mantidimaging.gui.mvp_base import BaseMainWindowView + +from qt_material import list_themes + +from mantidimaging.gui.windows.settings.presenter import SettingsWindowPresenter + +if TYPE_CHECKING: + from mantidimaging.gui.windows.main import MainWindowView # noqa:F401 # pragma: no cover + +LOG = getLogger(__name__) + +settings = QSettings('mantidproject', 'Mantid Imaging') + + +class SettingsWindowView(BaseMainWindowView): + settingsTabWidget: QTabWidget + appearanceTab: QWidget + themeName: QComboBox + themeLabel: QLabel + + def __init__(self, main_window: 'MainWindowView'): + super().__init__(None, 'gui/ui/settings_window.ui') + self.setWindowTitle('Settings') + self.main_window = main_window + self.presenter = SettingsWindowPresenter(self, main_window) + + self.themeName.addItem('Fusion') + self.themeName.addItems(list_themes()) + self.themeName.setCurrentText(self.presenter.current_theme) + + self.themeName.currentTextChanged.connect(self.presenter.set_theme) + + @property + def current_theme(self) -> str: + return self.themeName.currentText() diff --git a/mantidimaging/main.py b/mantidimaging/main.py index f770f182fcb..a51fb528b7f 100755 --- a/mantidimaging/main.py +++ b/mantidimaging/main.py @@ -17,12 +17,21 @@ from mantidimaging import helper as h from mantidimaging.core.utility.command_line_arguments import CommandLineArguments -from qt_material import apply_stylesheet - formatwarning_orig = warnings.formatwarning warnings.formatwarning = lambda message, category, filename, lineno, line=None: formatwarning_orig( message, category, filename, lineno, line="") +settings = QtCore.QSettings('mantidproject', 'Mantid Imaging') + +if settings.contains("theme_selection"): + # there is the key in QSettings + print('Checking for theme preference in config') + theme_selection = settings.value('theme_selection') + print('Found theme_selection in config:' + theme_selection) +else: + print('theme_selection not found in config. Using default Fusion') + settings.setValue('theme_selection', 'Fusion') + def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Mantid Imaging GUI") @@ -59,9 +68,9 @@ def parse_args() -> argparse.Namespace: def setup_application() -> QApplication: QGuiApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) q_application = QApplication(sys.argv) - #q_application.setStyle('Fusion') + q_application.setStyle(settings.value('theme_selection')) - apply_stylesheet(q_application, theme='light_blue.xml', invert_secondary=True) + #apply_stylesheet(q_application, theme='light_blue.xml', invert_secondary=True) q_application.setApplicationName("Mantid Imaging") q_application.setOrganizationName("mantidproject") q_application.setOrganizationDomain("mantidproject.org") From b273e9b897700d8c684c3fe574161b60a0493edd Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Mon, 18 Mar 2024 10:16:10 +0000 Subject: [PATCH 03/19] Added release note and qt-material dependancy --- docs/release_notes/next/feature-2144-UI-theme-settings | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/release_notes/next/feature-2144-UI-theme-settings diff --git a/docs/release_notes/next/feature-2144-UI-theme-settings b/docs/release_notes/next/feature-2144-UI-theme-settings new file mode 100644 index 00000000000..def6f3f86e9 --- /dev/null +++ b/docs/release_notes/next/feature-2144-UI-theme-settings @@ -0,0 +1 @@ +#2144: MI UI theme can be changed in runtime via a settings menu \ No newline at end of file From 1cf26c55551e43e87350ae436d0cc2b4b077973b Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Mon, 18 Mar 2024 15:56:12 +0000 Subject: [PATCH 04/19] Added fonts sizing to settings, refactored logic to presenter --- conda/meta.yaml | 1 + mantidimaging/gui/mvp_base/view.py | 2 -- mantidimaging/gui/ui/settings_window.ui | 19 ++++++++++- mantidimaging/gui/windows/main/presenter.py | 34 ++++++++++++++++++- mantidimaging/gui/windows/main/view.py | 13 +++---- .../gui/windows/settings/presenter.py | 10 +++++- mantidimaging/gui/windows/settings/view.py | 15 ++++++-- mantidimaging/main.py | 8 ++--- 8 files changed, 81 insertions(+), 21 deletions(-) diff --git a/conda/meta.yaml b/conda/meta.yaml index 6362ef24da7..57e319eaead 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -38,6 +38,7 @@ requirements: - pyqt=5.15.* - pyqtgraph=0.13.3 - qt-gtk-platformtheme # [linux] + - qt-material build: number: 1 diff --git a/mantidimaging/gui/mvp_base/view.py b/mantidimaging/gui/mvp_base/view.py index e26fd4e8abd..8c147819c90 100644 --- a/mantidimaging/gui/mvp_base/view.py +++ b/mantidimaging/gui/mvp_base/view.py @@ -28,8 +28,6 @@ def __init__(self, parent, ui_file=None): if ui_file is not None: compile_ui(ui_file, self) - print(f"mvp_case: {settings.value('theme_selection')=}") - if settings.value('theme_selection') == 'Fusion': self.setStyleSheet('Fusion') else: diff --git a/mantidimaging/gui/ui/settings_window.ui b/mantidimaging/gui/ui/settings_window.ui index c3aebfe3a7a..cbd902fafb6 100644 --- a/mantidimaging/gui/ui/settings_window.ui +++ b/mantidimaging/gui/ui/settings_window.ui @@ -72,7 +72,7 @@ - + Qt::Vertical @@ -85,6 +85,23 @@ + + + + + 0 + 0 + + + + + + + + Menu font size: + + + diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 751e4e56fd6..9bc9c969e6b 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -10,7 +10,10 @@ from collections.abc import Iterable import numpy as np -from PyQt5.QtWidgets import QTabBar, QApplication, QTreeWidgetItem +from PyQt5.QtCore import QSettings +from PyQt5.QtGui import QFont +from PyQt5.QtWidgets import QTabBar, QApplication, QTreeWidgetItem, QSpinBox +from qt_material import apply_stylesheet from mantidimaging.core.data import ImageStack from mantidimaging.core.data.dataset import StrictDataset, MixedDataset, _get_stack_data_type @@ -29,6 +32,22 @@ RECON_TEXT = "Recon" +settings = QSettings('mantidproject', 'Mantid Imaging') + +extra_style_default = { + + # Density Scale + 'density_scale': '-5', + + # font + 'font_size': '10px', + } + +if settings.contains("extra_style") and settings.value('extra_style'): + extra_style = settings.value('extra_style') +else: + settings.setValue('extra_style', extra_style_default) + class StackId(NamedTuple): id: uuid.UUID @@ -828,3 +847,16 @@ def _create_strict_dataset_stack_name(stack_type: str, dataset_name: str) -> str def is_dataset_strict(self, ds_id: uuid.UUID) -> bool: return self.model.is_dataset_strict(ds_id) + + def do_update_UI(self) -> None: + theme = settings.value('theme_selection') + extra_style = settings.value('extra_style') + font = QFont("Arial", int(extra_style['font_size'].replace('px', ''))) + for window in [self.view, self.view.recon, self.view.live_viewer, self.view.spectrum_viewer, self.view.filters, + self.view.settings_window]: + if window: + QApplication.instance().setFont(font) + window.setStyleSheet(theme) + if theme != 'Fusion': + apply_stylesheet(window, theme=theme, invert_secondary=False, extra=extra_style) + diff --git a/mantidimaging/gui/windows/main/view.py b/mantidimaging/gui/windows/main/view.py index 0b0bec370eb..f66358468fd 100644 --- a/mantidimaging/gui/windows/main/view.py +++ b/mantidimaging/gui/windows/main/view.py @@ -15,7 +15,7 @@ from PyQt5.QtGui import QIcon, QDragEnterEvent, QDropEvent, QDesktopServices from PyQt5.QtWidgets import QAction, QDialog, QLabel, QMessageBox, QMenu, QFileDialog, QSplitter, \ QTreeWidgetItem, QTreeWidget -from qt_material import apply_stylesheet + from mantidimaging.core.data import ImageStack from mantidimaging.core.data.dataset import StrictDataset @@ -175,11 +175,14 @@ def __init__(self, open_dialogs: bool = True): self.tabifiedDockWidgetActivated.connect(self._on_tab_bar_clicked) + self.presenter.do_update_UI() + def _window_ready(self) -> None: if perf_logger.isEnabledFor(1): perf_logger.info(f"Mantid Imaging ready in {time.monotonic() - process_start_time}") super()._window_ready() + def setup_shortcuts(self): self.actionLoadDataset.triggered.connect(self.show_image_load_dialog) self.actionLoadImages.triggered.connect(self.load_image_stack) @@ -390,14 +393,6 @@ def show_settings_window(self): self.settings_window.raise_() self.settings_window.show() - def set_theme(self, theme: str) -> None: - for window in [self, self.recon, self.live_viewer, self.spectrum_viewer, self.filters, self.settings_window]: - if window: - if theme == 'Fusion': - window.setStyleSheet(theme) - else: - apply_stylesheet(window, theme=theme, invert_secondary=False) - def show_recon_window(self): if not self.recon: self.recon = ReconstructWindowView(self) diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index 387e077fd36..c93e0ec7a9c 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -26,8 +26,16 @@ def __init__(self, view: 'SettingsWindowView', main_window: 'MainWindowView'): self.view = view self.main_window = main_window self.current_theme = settings.value('theme_selection') + self.current_menu_font_size = settings.value('extra_style')['font_size'] def set_theme(self): self.current_theme = self.view.current_theme settings.setValue('theme_selection', self.current_theme) - self.main_window.set_theme(self.current_theme) + self.main_window.presenter.do_update_UI() + + def set_extra_style(self): + extra_style = settings.value('extra_style') + extra_style.update({'font_size': self.view.current_menu_font_size + 'px'}) + settings.setValue('extra_style', extra_style) + self.main_window.presenter.do_update_UI() + diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index 4e7ebbeaee0..e90b33e63d7 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -9,7 +9,7 @@ from mantidimaging.gui.mvp_base import BaseMainWindowView -from qt_material import list_themes +from qt_material import list_themes, QtStyleTools from mantidimaging.gui.windows.settings.presenter import SettingsWindowPresenter @@ -21,11 +21,13 @@ settings = QSettings('mantidproject', 'Mantid Imaging') -class SettingsWindowView(BaseMainWindowView): +class SettingsWindowView(BaseMainWindowView, QtStyleTools): settingsTabWidget: QTabWidget appearanceTab: QWidget themeName: QComboBox themeLabel: QLabel + menuFontSizeLabel: QLabel + menuFontSizeChoice: QComboBox def __init__(self, main_window: 'MainWindowView'): super().__init__(None, 'gui/ui/settings_window.ui') @@ -37,8 +39,17 @@ def __init__(self, main_window: 'MainWindowView'): self.themeName.addItems(list_themes()) self.themeName.setCurrentText(self.presenter.current_theme) + self.menuFontSizeChoice.addItems(['8', '10', '12', '14', '16']) + print(f"{self.presenter.current_menu_font_size=}") + self.menuFontSizeChoice.setCurrentText(self.presenter.current_menu_font_size.replace('px','')) + self.themeName.currentTextChanged.connect(self.presenter.set_theme) + self.menuFontSizeChoice.currentTextChanged.connect(self.presenter.set_extra_style) @property def current_theme(self) -> str: return self.themeName.currentText() + + @property + def current_menu_font_size(self) -> str: + return self.menuFontSizeChoice.currentText() diff --git a/mantidimaging/main.py b/mantidimaging/main.py index a51fb528b7f..79d435c8c50 100755 --- a/mantidimaging/main.py +++ b/mantidimaging/main.py @@ -25,12 +25,10 @@ if settings.contains("theme_selection"): # there is the key in QSettings - print('Checking for theme preference in config') theme_selection = settings.value('theme_selection') - print('Found theme_selection in config:' + theme_selection) else: - print('theme_selection not found in config. Using default Fusion') settings.setValue('theme_selection', 'Fusion') + theme_selection = None def parse_args() -> argparse.Namespace: @@ -68,9 +66,9 @@ def parse_args() -> argparse.Namespace: def setup_application() -> QApplication: QGuiApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) q_application = QApplication(sys.argv) - q_application.setStyle(settings.value('theme_selection')) + if theme_selection: + q_application.setStyle(settings.value('theme_selection')) - #apply_stylesheet(q_application, theme='light_blue.xml', invert_secondary=True) q_application.setApplicationName("Mantid Imaging") q_application.setOrganizationName("mantidproject") q_application.setOrganizationDomain("mantidproject.org") From 6858cfdb1984796cccc2bffdec5f893f31bfa918 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Mon, 18 Mar 2024 17:16:16 +0000 Subject: [PATCH 05/19] yapf fixes --- mantidimaging/gui/windows/main/presenter.py | 19 ++++++++++--------- mantidimaging/gui/windows/main/view.py | 1 - .../gui/windows/settings/presenter.py | 1 - mantidimaging/gui/windows/settings/view.py | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 9bc9c969e6b..08bf7f53dbb 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -12,7 +12,7 @@ import numpy as np from PyQt5.QtCore import QSettings from PyQt5.QtGui import QFont -from PyQt5.QtWidgets import QTabBar, QApplication, QTreeWidgetItem, QSpinBox +from PyQt5.QtWidgets import QTabBar, QApplication, QTreeWidgetItem from qt_material import apply_stylesheet from mantidimaging.core.data import ImageStack @@ -36,12 +36,12 @@ extra_style_default = { - # Density Scale - 'density_scale': '-5', + # Density Scale + 'density_scale': '-5', - # font - 'font_size': '10px', - } + # font + 'font_size': '10px', +} if settings.contains("extra_style") and settings.value('extra_style'): extra_style = settings.value('extra_style') @@ -852,11 +852,12 @@ def do_update_UI(self) -> None: theme = settings.value('theme_selection') extra_style = settings.value('extra_style') font = QFont("Arial", int(extra_style['font_size'].replace('px', ''))) - for window in [self.view, self.view.recon, self.view.live_viewer, self.view.spectrum_viewer, self.view.filters, - self.view.settings_window]: + for window in [ + self.view, self.view.recon, self.view.live_viewer, self.view.spectrum_viewer, self.view.filters, + self.view.settings_window + ]: if window: QApplication.instance().setFont(font) window.setStyleSheet(theme) if theme != 'Fusion': apply_stylesheet(window, theme=theme, invert_secondary=False, extra=extra_style) - diff --git a/mantidimaging/gui/windows/main/view.py b/mantidimaging/gui/windows/main/view.py index f66358468fd..70a7dc9b9cb 100644 --- a/mantidimaging/gui/windows/main/view.py +++ b/mantidimaging/gui/windows/main/view.py @@ -16,7 +16,6 @@ from PyQt5.QtWidgets import QAction, QDialog, QLabel, QMessageBox, QMenu, QFileDialog, QSplitter, \ QTreeWidgetItem, QTreeWidget - from mantidimaging.core.data import ImageStack from mantidimaging.core.data.dataset import StrictDataset from mantidimaging.core.io.utility import find_first_file_that_is_possibly_a_sample diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index c93e0ec7a9c..4bc8a936d96 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -38,4 +38,3 @@ def set_extra_style(self): extra_style.update({'font_size': self.view.current_menu_font_size + 'px'}) settings.setValue('extra_style', extra_style) self.main_window.presenter.do_update_UI() - diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index e90b33e63d7..ca48982c7c4 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -41,7 +41,7 @@ def __init__(self, main_window: 'MainWindowView'): self.menuFontSizeChoice.addItems(['8', '10', '12', '14', '16']) print(f"{self.presenter.current_menu_font_size=}") - self.menuFontSizeChoice.setCurrentText(self.presenter.current_menu_font_size.replace('px','')) + self.menuFontSizeChoice.setCurrentText(self.presenter.current_menu_font_size.replace('px', '')) self.themeName.currentTextChanged.connect(self.presenter.set_theme) self.menuFontSizeChoice.currentTextChanged.connect(self.presenter.set_extra_style) From bcd2064d32d5fe990e33d542f2d9be54a43ad347 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Tue, 19 Mar 2024 10:54:16 +0000 Subject: [PATCH 06/19] Theme QSettings check in mvp base class --- mantidimaging/gui/mvp_base/view.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mantidimaging/gui/mvp_base/view.py b/mantidimaging/gui/mvp_base/view.py index 8c147819c90..4addad764a6 100644 --- a/mantidimaging/gui/mvp_base/view.py +++ b/mantidimaging/gui/mvp_base/view.py @@ -16,6 +16,9 @@ perf_logger = getLogger("perf." + __name__) settings = QtCore.QSettings('mantidproject', 'Mantid Imaging') +if not settings.contains("theme_selection") or settings.value("theme_selection") is None: + settings.setValue('theme_selection', 'Fusion') + class BaseMainWindowView(QMainWindow): From fa10f23d15e7d8916b0b76c2519655556c6b4595 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Tue, 19 Mar 2024 12:06:35 +0000 Subject: [PATCH 07/19] qt-material version specified --- conda/meta.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conda/meta.yaml b/conda/meta.yaml index 57e319eaead..58788babf88 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -37,8 +37,9 @@ requirements: - jenkspy=0.2.0 - pyqt=5.15.* - pyqtgraph=0.13.3 + - qt-material=2.14 - qt-gtk-platformtheme # [linux] - - qt-material + build: number: 1 From f51c7e5dc6e6a80e56d82506d859d99e0322d848 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Wed, 20 Mar 2024 08:59:11 +0000 Subject: [PATCH 08/19] MI uses OS theme by default (with print statements) --- mantidimaging/gui/ui/settings_window.ui | 36 +++++++++---- mantidimaging/gui/windows/main/presenter.py | 54 +++++++++++++++++-- .../gui/windows/settings/presenter.py | 16 ++++++ mantidimaging/gui/windows/settings/view.py | 15 +++++- 4 files changed, 105 insertions(+), 16 deletions(-) diff --git a/mantidimaging/gui/ui/settings_window.ui b/mantidimaging/gui/ui/settings_window.ui index cbd902fafb6..d5784339e1a 100644 --- a/mantidimaging/gui/ui/settings_window.ui +++ b/mantidimaging/gui/ui/settings_window.ui @@ -72,7 +72,24 @@ - + + + + + 0 + 0 + + + + + + + + Menu font size: + + + + Qt::Vertical @@ -85,20 +102,17 @@ - - - - - 0 - 0 - + + + + Dark mode: - - + + - Menu font size: + diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 08bf7f53dbb..29fd2fab061 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -9,9 +9,10 @@ from typing import TYPE_CHECKING, Any, NamedTuple from collections.abc import Iterable +import darkdetect import numpy as np -from PyQt5.QtCore import QSettings -from PyQt5.QtGui import QFont +from PyQt5.QtCore import QSettings, Qt +from PyQt5.QtGui import QFont, QPalette, QColor from PyQt5.QtWidgets import QTabBar, QApplication, QTreeWidgetItem from qt_material import apply_stylesheet @@ -47,6 +48,12 @@ extra_style = settings.value('extra_style') else: settings.setValue('extra_style', extra_style_default) +settings.setValue('os_theme', darkdetect.theme()) +#settings.clear() +print(f"{settings.value('use_dark_mode')=}") +print(f"{settings.value('os_theme')=}") +print(f"{settings.value('override_os_theme')=}") +print(f"{not settings.value('override_os_theme')=}") class StackId(NamedTuple): @@ -851,6 +858,9 @@ def is_dataset_strict(self, ds_id: uuid.UUID) -> bool: def do_update_UI(self) -> None: theme = settings.value('theme_selection') extra_style = settings.value('extra_style') + os_theme = settings.value('os_theme') + use_dark_mode = settings.value('use_dark_mode') + override_os_theme = settings.value('override_os_theme') font = QFont("Arial", int(extra_style['font_size'].replace('px', ''))) for window in [ self.view, self.view.recon, self.view.live_viewer, self.view.spectrum_viewer, self.view.filters, @@ -859,5 +869,43 @@ def do_update_UI(self) -> None: if window: QApplication.instance().setFont(font) window.setStyleSheet(theme) - if theme != 'Fusion': + if theme == 'Fusion': + print(f"Using Fusion theme\n {use_dark_mode=}") + if not override_os_theme: + if os_theme == 'Light': + self.use_fusion_light_mode() + elif os_theme == 'Dark': + self.use_fusion_dark_mode() + else: + if use_dark_mode: + print("using dark mode") + self.use_fusion_dark_mode() + else: + print("using light mode") + self.use_fusion_light_mode() + QApplication.instance().setFont(font) + window.setStyleSheet(theme) + else: + print(f"using apply_stylesheet: {theme=}") apply_stylesheet(window, theme=theme, invert_secondary=False, extra=extra_style) + + def use_fusion_dark_mode(self) -> None: + palette = QPalette() + palette.setColor(QPalette.Window, QColor(53, 53, 53)) + palette.setColor(QPalette.WindowText, Qt.white) + palette.setColor(QPalette.Base, QColor(25, 25, 25)) + palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53)) + palette.setColor(QPalette.ToolTipBase, Qt.black) + palette.setColor(QPalette.ToolTipText, Qt.white) + palette.setColor(QPalette.Text, Qt.white) + palette.setColor(QPalette.Button, QColor(53, 53, 53)) + palette.setColor(QPalette.ButtonText, Qt.white) + palette.setColor(QPalette.BrightText, Qt.red) + palette.setColor(QPalette.Link, QColor(42, 130, 218)) + palette.setColor(QPalette.Highlight, QColor(42, 130, 218)) + palette.setColor(QPalette.HighlightedText, Qt.black) + QApplication.instance().setPalette(palette) + + def use_fusion_light_mode(self) -> None: + palette = QPalette() + QApplication.instance().setPalette(palette) diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index 4bc8a936d96..ba191eadafd 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -31,6 +31,10 @@ def __init__(self, view: 'SettingsWindowView', main_window: 'MainWindowView'): def set_theme(self): self.current_theme = self.view.current_theme settings.setValue('theme_selection', self.current_theme) + if self.current_theme == 'Fusion': + self.view.useOsThemeCheckBox.setEnabled(True) + else: + self.view.useOsThemeCheckBox.setEnabled(False) self.main_window.presenter.do_update_UI() def set_extra_style(self): @@ -38,3 +42,15 @@ def set_extra_style(self): extra_style.update({'font_size': self.view.current_menu_font_size + 'px'}) settings.setValue('extra_style', extra_style) self.main_window.presenter.do_update_UI() + + def set_dark_mode(self): + print(f"{self.view.useOsThemeCheckBox.isChecked()=}") + if self.view.useOsThemeCheckBox.isChecked(): + use_dark_mode = 1 + else: + use_dark_mode = 0 + print(f"{use_dark_mode=}") + + settings.setValue('use_dark_mode', use_dark_mode) + settings.setValue('override_os_theme', True) + self.main_window.presenter.do_update_UI() diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index ca48982c7c4..dde2d5e4409 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -4,8 +4,8 @@ from logging import getLogger from typing import TYPE_CHECKING -from PyQt5.QtCore import QSettings -from PyQt5.QtWidgets import QTabWidget, QWidget, QComboBox, QLabel +from PyQt5.QtCore import QSettings, QSignalBlocker +from PyQt5.QtWidgets import QTabWidget, QWidget, QComboBox, QLabel, QCheckBox from mantidimaging.gui.mvp_base import BaseMainWindowView @@ -28,6 +28,7 @@ class SettingsWindowView(BaseMainWindowView, QtStyleTools): themeLabel: QLabel menuFontSizeLabel: QLabel menuFontSizeChoice: QComboBox + useOsThemeCheckBox: QCheckBox def __init__(self, main_window: 'MainWindowView'): super().__init__(None, 'gui/ui/settings_window.ui') @@ -45,6 +46,16 @@ def __init__(self, main_window: 'MainWindowView'): self.themeName.currentTextChanged.connect(self.presenter.set_theme) self.menuFontSizeChoice.currentTextChanged.connect(self.presenter.set_extra_style) + self.useOsThemeCheckBox.stateChanged.connect(self.presenter.set_dark_mode) + + if self.current_theme != 'Fusion': + self.useOsThemeCheckBox.setEnabled(False) + with (QSignalBlocker(self.useOsThemeCheckBox)): + if settings.value('use_dark_mode') or (settings.value('os_theme') == 'Dark' + and not settings.value('override_os_theme')): + self.useOsThemeCheckBox.setChecked(True) + else: + self.useOsThemeCheckBox.setChecked(False) @property def current_theme(self) -> str: From 4235c4f772cafd94936d0ad0b02005ffc3da495a Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Wed, 20 Mar 2024 09:17:11 +0000 Subject: [PATCH 09/19] print statements removed --- mantidimaging/gui/windows/main/presenter.py | 9 --------- mantidimaging/gui/windows/settings/presenter.py | 2 -- mantidimaging/gui/windows/settings/view.py | 1 - 3 files changed, 12 deletions(-) diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 29fd2fab061..6edd89d7327 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -49,11 +49,6 @@ else: settings.setValue('extra_style', extra_style_default) settings.setValue('os_theme', darkdetect.theme()) -#settings.clear() -print(f"{settings.value('use_dark_mode')=}") -print(f"{settings.value('os_theme')=}") -print(f"{settings.value('override_os_theme')=}") -print(f"{not settings.value('override_os_theme')=}") class StackId(NamedTuple): @@ -870,7 +865,6 @@ def do_update_UI(self) -> None: QApplication.instance().setFont(font) window.setStyleSheet(theme) if theme == 'Fusion': - print(f"Using Fusion theme\n {use_dark_mode=}") if not override_os_theme: if os_theme == 'Light': self.use_fusion_light_mode() @@ -878,15 +872,12 @@ def do_update_UI(self) -> None: self.use_fusion_dark_mode() else: if use_dark_mode: - print("using dark mode") self.use_fusion_dark_mode() else: - print("using light mode") self.use_fusion_light_mode() QApplication.instance().setFont(font) window.setStyleSheet(theme) else: - print(f"using apply_stylesheet: {theme=}") apply_stylesheet(window, theme=theme, invert_secondary=False, extra=extra_style) def use_fusion_dark_mode(self) -> None: diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index ba191eadafd..66647a91187 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -44,12 +44,10 @@ def set_extra_style(self): self.main_window.presenter.do_update_UI() def set_dark_mode(self): - print(f"{self.view.useOsThemeCheckBox.isChecked()=}") if self.view.useOsThemeCheckBox.isChecked(): use_dark_mode = 1 else: use_dark_mode = 0 - print(f"{use_dark_mode=}") settings.setValue('use_dark_mode', use_dark_mode) settings.setValue('override_os_theme', True) diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index dde2d5e4409..6669f3561d4 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -41,7 +41,6 @@ def __init__(self, main_window: 'MainWindowView'): self.themeName.setCurrentText(self.presenter.current_theme) self.menuFontSizeChoice.addItems(['8', '10', '12', '14', '16']) - print(f"{self.presenter.current_menu_font_size=}") self.menuFontSizeChoice.setCurrentText(self.presenter.current_menu_font_size.replace('px', '')) self.themeName.currentTextChanged.connect(self.presenter.set_theme) From e2591eecd5a16bc34a189a16472eb0c1d1b92ce7 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Wed, 20 Mar 2024 09:19:18 +0000 Subject: [PATCH 10/19] darkdetect dependancy added --- conda/meta.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/conda/meta.yaml b/conda/meta.yaml index 58788babf88..2065f4161c3 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -38,6 +38,7 @@ requirements: - pyqt=5.15.* - pyqtgraph=0.13.3 - qt-material=2.14 + - darkdetect=0.8.0 - qt-gtk-platformtheme # [linux] From 313df52307dde96293ada296661a6a414154ca8a Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Wed, 27 Mar 2024 13:36:34 +0000 Subject: [PATCH 11/19] rename check box to darkModeCheckBox --- mantidimaging/gui/ui/settings_window.ui | 2 +- mantidimaging/gui/windows/settings/presenter.py | 6 +++--- mantidimaging/gui/windows/settings/view.py | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mantidimaging/gui/ui/settings_window.ui b/mantidimaging/gui/ui/settings_window.ui index d5784339e1a..5edf22e080c 100644 --- a/mantidimaging/gui/ui/settings_window.ui +++ b/mantidimaging/gui/ui/settings_window.ui @@ -110,7 +110,7 @@ - + diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index 66647a91187..ea146f48f4c 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -32,9 +32,9 @@ def set_theme(self): self.current_theme = self.view.current_theme settings.setValue('theme_selection', self.current_theme) if self.current_theme == 'Fusion': - self.view.useOsThemeCheckBox.setEnabled(True) + self.view.darkModeCheckBox.setEnabled(True) else: - self.view.useOsThemeCheckBox.setEnabled(False) + self.view.darkModeCheckBox.setEnabled(False) self.main_window.presenter.do_update_UI() def set_extra_style(self): @@ -44,7 +44,7 @@ def set_extra_style(self): self.main_window.presenter.do_update_UI() def set_dark_mode(self): - if self.view.useOsThemeCheckBox.isChecked(): + if self.view.darkModeCheckBox.isChecked(): use_dark_mode = 1 else: use_dark_mode = 0 diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index 6669f3561d4..07273299216 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -28,7 +28,7 @@ class SettingsWindowView(BaseMainWindowView, QtStyleTools): themeLabel: QLabel menuFontSizeLabel: QLabel menuFontSizeChoice: QComboBox - useOsThemeCheckBox: QCheckBox + darkModeCheckBox: QCheckBox def __init__(self, main_window: 'MainWindowView'): super().__init__(None, 'gui/ui/settings_window.ui') @@ -45,16 +45,16 @@ def __init__(self, main_window: 'MainWindowView'): self.themeName.currentTextChanged.connect(self.presenter.set_theme) self.menuFontSizeChoice.currentTextChanged.connect(self.presenter.set_extra_style) - self.useOsThemeCheckBox.stateChanged.connect(self.presenter.set_dark_mode) + self.darkModeCheckBox.stateChanged.connect(self.presenter.set_dark_mode) if self.current_theme != 'Fusion': - self.useOsThemeCheckBox.setEnabled(False) - with (QSignalBlocker(self.useOsThemeCheckBox)): + self.darkModeCheckBox.setEnabled(False) + with (QSignalBlocker(self.darkModeCheckBox)): if settings.value('use_dark_mode') or (settings.value('os_theme') == 'Dark' and not settings.value('override_os_theme')): - self.useOsThemeCheckBox.setChecked(True) + self.darkModeCheckBox.setChecked(True) else: - self.useOsThemeCheckBox.setChecked(False) + self.darkModeCheckBox.setChecked(False) @property def current_theme(self) -> str: From c5030eb3b7c8c5432b083c07b8c0b0e271386428 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Thu, 28 Mar 2024 14:27:53 +0000 Subject: [PATCH 12/19] Qsettings values set as strings --- mantidimaging/gui/windows/main/presenter.py | 4 ++-- mantidimaging/gui/windows/settings/presenter.py | 6 +++--- mantidimaging/gui/windows/settings/view.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 6edd89d7327..8f07e833da1 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -865,13 +865,13 @@ def do_update_UI(self) -> None: QApplication.instance().setFont(font) window.setStyleSheet(theme) if theme == 'Fusion': - if not override_os_theme: + if override_os_theme == 'False': if os_theme == 'Light': self.use_fusion_light_mode() elif os_theme == 'Dark': self.use_fusion_dark_mode() else: - if use_dark_mode: + if use_dark_mode == 'True': self.use_fusion_dark_mode() else: self.use_fusion_light_mode() diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index ea146f48f4c..7dda1d3ea4f 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -45,10 +45,10 @@ def set_extra_style(self): def set_dark_mode(self): if self.view.darkModeCheckBox.isChecked(): - use_dark_mode = 1 + use_dark_mode = 'True' else: - use_dark_mode = 0 + use_dark_mode = 'False' settings.setValue('use_dark_mode', use_dark_mode) - settings.setValue('override_os_theme', True) + settings.setValue('override_os_theme', 'True') self.main_window.presenter.do_update_UI() diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index 07273299216..2dffb7ca8b3 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -50,8 +50,8 @@ def __init__(self, main_window: 'MainWindowView'): if self.current_theme != 'Fusion': self.darkModeCheckBox.setEnabled(False) with (QSignalBlocker(self.darkModeCheckBox)): - if settings.value('use_dark_mode') or (settings.value('os_theme') == 'Dark' - and not settings.value('override_os_theme')): + if settings.value('use_dark_mode') == 'True' or (settings.value('os_theme') == 'Dark' + and settings.value('override_os_theme') == 'False'): self.darkModeCheckBox.setChecked(True) else: self.darkModeCheckBox.setChecked(False) From 4072aa70ef473fe7f6555b15fa26f7238cc629ca Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Thu, 28 Mar 2024 14:45:30 +0000 Subject: [PATCH 13/19] ruff fixes --- mantidimaging/gui/windows/main/view.py | 1 - mantidimaging/gui/windows/settings/presenter.py | 4 ++-- mantidimaging/gui/windows/settings/view.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/mantidimaging/gui/windows/main/view.py b/mantidimaging/gui/windows/main/view.py index 70a7dc9b9cb..3d5307691b7 100644 --- a/mantidimaging/gui/windows/main/view.py +++ b/mantidimaging/gui/windows/main/view.py @@ -181,7 +181,6 @@ def _window_ready(self) -> None: perf_logger.info(f"Mantid Imaging ready in {time.monotonic() - process_start_time}") super()._window_ready() - def setup_shortcuts(self): self.actionLoadDataset.triggered.connect(self.show_image_load_dialog) self.actionLoadImages.triggered.connect(self.load_image_stack) diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index 7dda1d3ea4f..fc2ce6448df 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -19,9 +19,9 @@ class SettingsWindowPresenter(BasePresenter): - view: 'SettingsWindowView' + view: SettingsWindowView - def __init__(self, view: 'SettingsWindowView', main_window: 'MainWindowView'): + def __init__(self, view: SettingsWindowView, main_window: MainWindowView): super().__init__(view) self.view = view self.main_window = main_window diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index 2dffb7ca8b3..99d746e73db 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -30,7 +30,7 @@ class SettingsWindowView(BaseMainWindowView, QtStyleTools): menuFontSizeChoice: QComboBox darkModeCheckBox: QCheckBox - def __init__(self, main_window: 'MainWindowView'): + def __init__(self, main_window: MainWindowView): super().__init__(None, 'gui/ui/settings_window.ui') self.setWindowTitle('Settings') self.main_window = main_window From 1c11c495db77eb43efeb812cefb84d296f7d604c Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Wed, 3 Apr 2024 12:33:49 +0100 Subject: [PATCH 14/19] MI uses OS default font settings --- mantidimaging/gui/windows/main/presenter.py | 7 ++++--- mantidimaging/gui/windows/settings/presenter.py | 6 +++++- mantidimaging/main.py | 6 +++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 8f07e833da1..3ae519868ee 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -41,13 +41,14 @@ 'density_scale': '-5', # font - 'font_size': '10px', + 'font_size': settings.value('default_font_size', defaultValue='12') + 'px', } -if settings.contains("extra_style") and settings.value('extra_style'): +if settings.contains("extra_style") and settings.value('extra_style') is not None: extra_style = settings.value('extra_style') else: settings.setValue('extra_style', extra_style_default) + extra_style = extra_style_default settings.setValue('os_theme', darkdetect.theme()) @@ -856,7 +857,7 @@ def do_update_UI(self) -> None: os_theme = settings.value('os_theme') use_dark_mode = settings.value('use_dark_mode') override_os_theme = settings.value('override_os_theme') - font = QFont("Arial", int(extra_style['font_size'].replace('px', ''))) + font = QFont(settings.value('default_font_family'), int(extra_style['font_size'].replace('px', ''))) for window in [ self.view, self.view.recon, self.view.live_viewer, self.view.spectrum_viewer, self.view.filters, self.view.settings_window diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index fc2ce6448df..e8efc537f35 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -26,7 +26,10 @@ def __init__(self, view: SettingsWindowView, main_window: MainWindowView): self.view = view self.main_window = main_window self.current_theme = settings.value('theme_selection') - self.current_menu_font_size = settings.value('extra_style')['font_size'] + if settings.value('selected_font_size') is None: + self.current_menu_font_size = settings.value('default_font_size') + else: + self.current_menu_font_size = settings.value('selected_font_size') def set_theme(self): self.current_theme = self.view.current_theme @@ -39,6 +42,7 @@ def set_theme(self): def set_extra_style(self): extra_style = settings.value('extra_style') + settings.setValue('selected_font_size', self.view.current_menu_font_size) extra_style.update({'font_size': self.view.current_menu_font_size + 'px'}) settings.setValue('extra_style', extra_style) self.main_window.presenter.do_update_UI() diff --git a/mantidimaging/main.py b/mantidimaging/main.py index 79d435c8c50..765a24e8424 100755 --- a/mantidimaging/main.py +++ b/mantidimaging/main.py @@ -10,7 +10,7 @@ from PyQt5.QtWidgets import QApplication from PyQt5 import QtCore -from PyQt5.QtGui import QGuiApplication +from PyQt5.QtGui import QGuiApplication, QFont, QFontInfo import mantidimaging.core.parallel.manager as pm @@ -69,6 +69,10 @@ def setup_application() -> QApplication: if theme_selection: q_application.setStyle(settings.value('theme_selection')) + default_font = QFont('-1') + default_font_info = QFontInfo(default_font) + settings.setValue('default_font_size', str(default_font.pointSize())) + settings.setValue('default_font_family', str(default_font_info.family())) q_application.setApplicationName("Mantid Imaging") q_application.setOrganizationName("mantidproject") q_application.setOrganizationDomain("mantidproject.org") From 21fdbc384c571d64fccf8efdef46468897490ffa Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Tue, 9 Apr 2024 10:03:54 +0100 Subject: [PATCH 15/19] Font is read from OS via QFont --- mantidimaging/gui/windows/main/presenter.py | 23 ++++----------------- mantidimaging/gui/windows/settings/view.py | 2 +- mantidimaging/main.py | 14 ++++++++++++- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 3ae519868ee..658423701db 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -9,7 +9,6 @@ from typing import TYPE_CHECKING, Any, NamedTuple from collections.abc import Iterable -import darkdetect import numpy as np from PyQt5.QtCore import QSettings, Qt from PyQt5.QtGui import QFont, QPalette, QColor @@ -35,22 +34,6 @@ settings = QSettings('mantidproject', 'Mantid Imaging') -extra_style_default = { - - # Density Scale - 'density_scale': '-5', - - # font - 'font_size': settings.value('default_font_size', defaultValue='12') + 'px', -} - -if settings.contains("extra_style") and settings.value('extra_style') is not None: - extra_style = settings.value('extra_style') -else: - settings.setValue('extra_style', extra_style_default) - extra_style = extra_style_default -settings.setValue('os_theme', darkdetect.theme()) - class StackId(NamedTuple): id: uuid.UUID @@ -881,7 +864,8 @@ def do_update_UI(self) -> None: else: apply_stylesheet(window, theme=theme, invert_secondary=False, extra=extra_style) - def use_fusion_dark_mode(self) -> None: + @staticmethod + def use_fusion_dark_mode() -> None: palette = QPalette() palette.setColor(QPalette.Window, QColor(53, 53, 53)) palette.setColor(QPalette.WindowText, Qt.white) @@ -898,6 +882,7 @@ def use_fusion_dark_mode(self) -> None: palette.setColor(QPalette.HighlightedText, Qt.black) QApplication.instance().setPalette(palette) - def use_fusion_light_mode(self) -> None: + @staticmethod + def use_fusion_light_mode() -> None: palette = QPalette() QApplication.instance().setPalette(palette) diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index 99d746e73db..26cb92e5445 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -40,7 +40,7 @@ def __init__(self, main_window: MainWindowView): self.themeName.addItems(list_themes()) self.themeName.setCurrentText(self.presenter.current_theme) - self.menuFontSizeChoice.addItems(['8', '10', '12', '14', '16']) + self.menuFontSizeChoice.addItems([str(font_size) for font_size in range(4, 21)]) self.menuFontSizeChoice.setCurrentText(self.presenter.current_menu_font_size.replace('px', '')) self.themeName.currentTextChanged.connect(self.presenter.set_theme) diff --git a/mantidimaging/main.py b/mantidimaging/main.py index 765a24e8424..d47a89311a8 100755 --- a/mantidimaging/main.py +++ b/mantidimaging/main.py @@ -8,6 +8,7 @@ import warnings import os +import darkdetect from PyQt5.QtWidgets import QApplication from PyQt5 import QtCore from PyQt5.QtGui import QGuiApplication, QFont, QFontInfo @@ -69,10 +70,21 @@ def setup_application() -> QApplication: if theme_selection: q_application.setStyle(settings.value('theme_selection')) - default_font = QFont('-1') + default_font = QFont() default_font_info = QFontInfo(default_font) + extra_style_default = { + + # Density Scale + 'density_scale': '-5', + + # font + 'font_size': str(default_font.pointSize()) + 'px', + } + settings.setValue('extra_style', extra_style_default) + settings.setValue('os_theme', darkdetect.theme()) settings.setValue('default_font_size', str(default_font.pointSize())) settings.setValue('default_font_family', str(default_font_info.family())) + q_application.setApplicationName("Mantid Imaging") q_application.setOrganizationName("mantidproject") q_application.setOrganizationDomain("mantidproject.org") From e7ea98587efcd84988243951c3c9fc7461b94c5c Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Tue, 9 Apr 2024 10:56:13 +0100 Subject: [PATCH 16/19] Only set extra_style_default on first startup --- mantidimaging/gui/windows/main/presenter.py | 1 + mantidimaging/main.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 658423701db..8d80b443487 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -841,6 +841,7 @@ def do_update_UI(self) -> None: use_dark_mode = settings.value('use_dark_mode') override_os_theme = settings.value('override_os_theme') font = QFont(settings.value('default_font_family'), int(extra_style['font_size'].replace('px', ''))) + print(f"extra_style: {extra_style}") for window in [ self.view, self.view.recon, self.view.live_viewer, self.view.spectrum_viewer, self.view.filters, self.view.settings_window diff --git a/mantidimaging/main.py b/mantidimaging/main.py index d47a89311a8..a77bbbbe430 100755 --- a/mantidimaging/main.py +++ b/mantidimaging/main.py @@ -80,7 +80,8 @@ def setup_application() -> QApplication: # font 'font_size': str(default_font.pointSize()) + 'px', } - settings.setValue('extra_style', extra_style_default) + if settings.value('extra_style') is None: + settings.setValue('extra_style', extra_style_default) settings.setValue('os_theme', darkdetect.theme()) settings.setValue('default_font_size', str(default_font.pointSize())) settings.setValue('default_font_family', str(default_font_info.family())) From 050079bc8a177bb2303c6a5b39aac9b1e21ce616 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Tue, 9 Apr 2024 15:16:09 +0100 Subject: [PATCH 17/19] Use OS theme checkbox in settings window --- mantidimaging/gui/mvp_base/view.py | 6 -- mantidimaging/gui/ui/settings_window.ui | 98 ++++++++++++++++--- mantidimaging/gui/windows/main/presenter.py | 14 ++- .../gui/windows/settings/presenter.py | 36 ++++++- mantidimaging/gui/windows/settings/view.py | 5 + mantidimaging/main.py | 1 + 6 files changed, 132 insertions(+), 28 deletions(-) diff --git a/mantidimaging/gui/mvp_base/view.py b/mantidimaging/gui/mvp_base/view.py index 4addad764a6..6f2263d90a1 100644 --- a/mantidimaging/gui/mvp_base/view.py +++ b/mantidimaging/gui/mvp_base/view.py @@ -8,7 +8,6 @@ from PyQt5 import QtCore from PyQt5.QtCore import Qt, QTimer from PyQt5.QtWidgets import QMainWindow, QMessageBox, QDialog -from qt_material import apply_stylesheet from mantidimaging.gui.utility import compile_ui @@ -31,11 +30,6 @@ def __init__(self, parent, ui_file=None): if ui_file is not None: compile_ui(ui_file, self) - if settings.value('theme_selection') == 'Fusion': - self.setStyleSheet('Fusion') - else: - apply_stylesheet(self, theme=settings.value('theme_selection'), invert_secondary=False) - def closeEvent(self, e): LOG.debug('UI window closed') self.cleanup() diff --git a/mantidimaging/gui/ui/settings_window.ui b/mantidimaging/gui/ui/settings_window.ui index 5edf22e080c..e471cfe2dee 100644 --- a/mantidimaging/gui/ui/settings_window.ui +++ b/mantidimaging/gui/ui/settings_window.ui @@ -6,14 +6,26 @@ 0 0 - 418 - 348 + 454 + 444 + + + 456 + 449 + + MainWindow + + + 0 + 0 + + @@ -24,7 +36,7 @@ - + 1 1 @@ -50,8 +62,8 @@ 10 10 - 341 - 241 + 411 + 361 @@ -72,6 +84,13 @@ + + + + Menu font size: + + + @@ -82,14 +101,35 @@ - - + + - Menu font size: + Dark mode: + + + + + + + + + + + + + + Use OS defaults: + + + + + + + Qt::Vertical @@ -102,19 +142,45 @@ - - + + + + + + Performance + + + + + 10 + 10 + 411 + 361 + + + + + - Dark mode: + Processes (applies on restart): - - - - + + + + + + + Qt::Vertical - + + + 20 + 40 + + + diff --git a/mantidimaging/gui/windows/main/presenter.py b/mantidimaging/gui/windows/main/presenter.py index 8d80b443487..1e9043373d7 100644 --- a/mantidimaging/gui/windows/main/presenter.py +++ b/mantidimaging/gui/windows/main/presenter.py @@ -835,13 +835,17 @@ def is_dataset_strict(self, ds_id: uuid.UUID) -> bool: return self.model.is_dataset_strict(ds_id) def do_update_UI(self) -> None: - theme = settings.value('theme_selection') - extra_style = settings.value('extra_style') + if settings.value('use_os_defaults', defaultValue='True') == 'True': + extra_style = settings.value('extra_style_default') + theme = 'Fusion' + override_os_theme = 'False' + else: + extra_style = settings.value('extra_style') + use_dark_mode = settings.value('use_dark_mode') + theme = settings.value('theme_selection') + override_os_theme = settings.value('override_os_theme') os_theme = settings.value('os_theme') - use_dark_mode = settings.value('use_dark_mode') - override_os_theme = settings.value('override_os_theme') font = QFont(settings.value('default_font_family'), int(extra_style['font_size'].replace('px', ''))) - print(f"extra_style: {extra_style}") for window in [ self.view, self.view.recon, self.view.live_viewer, self.view.spectrum_viewer, self.view.filters, self.view.settings_window diff --git a/mantidimaging/gui/windows/settings/presenter.py b/mantidimaging/gui/windows/settings/presenter.py index e8efc537f35..229026a9143 100644 --- a/mantidimaging/gui/windows/settings/presenter.py +++ b/mantidimaging/gui/windows/settings/presenter.py @@ -5,7 +5,7 @@ from logging import getLogger from typing import TYPE_CHECKING -from PyQt5.QtCore import QSettings +from PyQt5.QtCore import QSettings, QSignalBlocker from mantidimaging.gui.mvp_base import BasePresenter @@ -56,3 +56,37 @@ def set_dark_mode(self): settings.setValue('use_dark_mode', use_dark_mode) settings.setValue('override_os_theme', 'True') self.main_window.presenter.do_update_UI() + + def set_to_os_defaults(self): + if self.view.osDefaultsCheckBox.isChecked(): + settings.setValue('use_os_defaults', 'True') + theme_text = 'Fusion' + theme_enabled = False + font_text = settings.value('default_font_size') + font_enabled = False + if settings.value('os_theme') == 'Dark': + dark_mode_checked = True + else: + dark_mode_checked = False + dark_mode_enabled = False + else: + settings.setValue('use_os_defaults', 'False') + theme_text = settings.value('theme_selection') + theme_enabled = True + font_text = settings.value('selected_font_size') + font_enabled = True + if settings.value('use_dark_mode') == 'True': + dark_mode_checked = True + else: + dark_mode_checked = False + dark_mode_enabled = True + with QSignalBlocker(self.view.themeName): + self.view.themeName.setCurrentText(theme_text) + self.view.themeName.setEnabled(theme_enabled) + with QSignalBlocker(self.view.menuFontSizeChoice): + self.view.menuFontSizeChoice.setCurrentText(font_text) + self.view.menuFontSizeChoice.setEnabled(font_enabled) + with QSignalBlocker(self.view.darkModeCheckBox): + self.view.darkModeCheckBox.setChecked(dark_mode_checked) + self.view.darkModeCheckBox.setEnabled(dark_mode_enabled) + self.main_window.presenter.do_update_UI() diff --git a/mantidimaging/gui/windows/settings/view.py b/mantidimaging/gui/windows/settings/view.py index 26cb92e5445..41931f7123f 100644 --- a/mantidimaging/gui/windows/settings/view.py +++ b/mantidimaging/gui/windows/settings/view.py @@ -29,6 +29,7 @@ class SettingsWindowView(BaseMainWindowView, QtStyleTools): menuFontSizeLabel: QLabel menuFontSizeChoice: QComboBox darkModeCheckBox: QCheckBox + osDefaultsCheckBox: QCheckBox def __init__(self, main_window: MainWindowView): super().__init__(None, 'gui/ui/settings_window.ui') @@ -46,6 +47,7 @@ def __init__(self, main_window: MainWindowView): self.themeName.currentTextChanged.connect(self.presenter.set_theme) self.menuFontSizeChoice.currentTextChanged.connect(self.presenter.set_extra_style) self.darkModeCheckBox.stateChanged.connect(self.presenter.set_dark_mode) + self.osDefaultsCheckBox.stateChanged.connect(self.presenter.set_to_os_defaults) if self.current_theme != 'Fusion': self.darkModeCheckBox.setEnabled(False) @@ -56,6 +58,9 @@ def __init__(self, main_window: MainWindowView): else: self.darkModeCheckBox.setChecked(False) + if settings.value('use_os_defaults') == 'True' or settings.value('use_os_defaults') is None: + self.osDefaultsCheckBox.setChecked(True) + @property def current_theme(self) -> str: return self.themeName.currentText() diff --git a/mantidimaging/main.py b/mantidimaging/main.py index a77bbbbe430..f62c1a46365 100755 --- a/mantidimaging/main.py +++ b/mantidimaging/main.py @@ -80,6 +80,7 @@ def setup_application() -> QApplication: # font 'font_size': str(default_font.pointSize()) + 'px', } + settings.setValue('extra_style_default', extra_style_default) if settings.value('extra_style') is None: settings.setValue('extra_style', extra_style_default) settings.setValue('os_theme', darkdetect.theme()) From 44467f535b524192ed0487bcb91bd1937232586d Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Wed, 10 Apr 2024 15:16:03 +0100 Subject: [PATCH 18/19] small changes and refactoring UI updating into mvp base --- mantidimaging/gui/mvp_base/view.py | 4 ++- mantidimaging/gui/ui/settings_window.ui | 40 ------------------------- mantidimaging/gui/windows/main/view.py | 4 +-- mantidimaging/main.py | 11 ++----- 4 files changed, 6 insertions(+), 53 deletions(-) diff --git a/mantidimaging/gui/mvp_base/view.py b/mantidimaging/gui/mvp_base/view.py index 6f2263d90a1..1a67fcab80d 100644 --- a/mantidimaging/gui/mvp_base/view.py +++ b/mantidimaging/gui/mvp_base/view.py @@ -7,7 +7,7 @@ from PyQt5 import QtCore from PyQt5.QtCore import Qt, QTimer -from PyQt5.QtWidgets import QMainWindow, QMessageBox, QDialog +from PyQt5.QtWidgets import QMainWindow, QMessageBox, QDialog, QApplication from mantidimaging.gui.utility import compile_ui @@ -30,6 +30,8 @@ def __init__(self, parent, ui_file=None): if ui_file is not None: compile_ui(ui_file, self) + QApplication.instance().setStyle(settings.value('theme_selection')) + def closeEvent(self, e): LOG.debug('UI window closed') self.cleanup() diff --git a/mantidimaging/gui/ui/settings_window.ui b/mantidimaging/gui/ui/settings_window.ui index e471cfe2dee..d305c616750 100644 --- a/mantidimaging/gui/ui/settings_window.ui +++ b/mantidimaging/gui/ui/settings_window.ui @@ -145,46 +145,6 @@ - - - Performance - - - - - 10 - 10 - 411 - 361 - - - - - - - Processes (applies on restart): - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - diff --git a/mantidimaging/gui/windows/main/view.py b/mantidimaging/gui/windows/main/view.py index 3d5307691b7..cb08d811ffc 100644 --- a/mantidimaging/gui/windows/main/view.py +++ b/mantidimaging/gui/windows/main/view.py @@ -11,7 +11,7 @@ from uuid import UUID import numpy as np -from PyQt5.QtCore import Qt, pyqtSignal, QUrl, QPoint, QSettings +from PyQt5.QtCore import Qt, pyqtSignal, QUrl, QPoint from PyQt5.QtGui import QIcon, QDragEnterEvent, QDropEvent, QDesktopServices from PyQt5.QtWidgets import QAction, QDialog, QLabel, QMessageBox, QMenu, QFileDialog, QSplitter, \ QTreeWidgetItem, QTreeWidget @@ -55,8 +55,6 @@ LOG = getLogger(__name__) perf_logger = getLogger("perf." + __name__) -settings = QSettings('mantidproject', 'Mantid Imaging') - class QTreeDatasetWidgetItem(QTreeWidgetItem): diff --git a/mantidimaging/main.py b/mantidimaging/main.py index f62c1a46365..5ba4d0ac4f4 100755 --- a/mantidimaging/main.py +++ b/mantidimaging/main.py @@ -24,13 +24,6 @@ settings = QtCore.QSettings('mantidproject', 'Mantid Imaging') -if settings.contains("theme_selection"): - # there is the key in QSettings - theme_selection = settings.value('theme_selection') -else: - settings.setValue('theme_selection', 'Fusion') - theme_selection = None - def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser(description="Mantid Imaging GUI") @@ -67,11 +60,10 @@ def parse_args() -> argparse.Namespace: def setup_application() -> QApplication: QGuiApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling) q_application = QApplication(sys.argv) - if theme_selection: - q_application.setStyle(settings.value('theme_selection')) default_font = QFont() default_font_info = QFontInfo(default_font) + extra_style_default = { # Density Scale @@ -83,6 +75,7 @@ def setup_application() -> QApplication: settings.setValue('extra_style_default', extra_style_default) if settings.value('extra_style') is None: settings.setValue('extra_style', extra_style_default) + settings.setValue('os_theme', darkdetect.theme()) settings.setValue('default_font_size', str(default_font.pointSize())) settings.setValue('default_font_family', str(default_font_info.family())) From 884cec40219d6f93423735ec12db2e56203abb64 Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Wed, 10 Apr 2024 15:16:34 +0100 Subject: [PATCH 19/19] pytest fixes --- conftest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/conftest.py b/conftest.py index 84c3e884958..e23c48f76c3 100644 --- a/conftest.py +++ b/conftest.py @@ -5,6 +5,8 @@ from collections import Counter import pytest +from PyQt5 import QtCore +from PyQt5.QtGui import QFont from mantidimaging.core.utility.leak_tracker import leak_tracker @@ -63,3 +65,20 @@ def leak_test_stats(): # leak_tracker.clear() # Uncomment to clear after each test # print(leak_tracker.pretty_print(debug_owners=True)) # uncomment to track leaks + + +@pytest.fixture(autouse=True) +def setup_QSettings(): + settings = QtCore.QSettings('mantidproject', 'Mantid Imaging') + default_font = QFont() + extra_style_default = { + + # Density Scale + 'density_scale': '-5', + + # font + 'font_size': str(default_font.pointSize()) + 'px', + } + settings.setValue('extra_style_default', extra_style_default) + if settings.value('extra_style') is None: + settings.setValue('extra_style', extra_style_default)