From 1de82ae076c72ec7d3933a0d2906de0d188abe3e Mon Sep 17 00:00:00 2001 From: Mike Sullivan Date: Tue, 9 Apr 2024 10:03:54 +0100 Subject: [PATCH] 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")