From 7d05a469b8be4e574432e6eacb64a6799b596c53 Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Mon, 2 Oct 2023 11:30:41 -0500 Subject: [PATCH] Add an option to modify the font size of the app This option is present in the new "Edit"->"Configuration" dialog. This modifies the font size of both Qt and matplotlib. When the user modifies the font size in the dialog, most (but not all) widgets in the application are updated immediately. It appears that any widgets with custom style sheets do not get updated. Perhaps some other types of widgets don't get updated either. But restarting the application normally appears to update everything to the new font size. It would be nice to get all widgets to update immediately when the user modifies the font size. But for now, we can just present a warning that the user should restart the application normally in order to get all widgets to update. Fixes: #1575 Signed-off-by: Patrick Avery --- hexrd/ui/config_dialog.py | 35 ++++++++++++++++ hexrd/ui/hexrd_config.py | 24 +++++++++++ hexrd/ui/resources/ui/config_dialog.ui | 56 ++++++++++++++++++-------- 3 files changed, 99 insertions(+), 16 deletions(-) diff --git a/hexrd/ui/config_dialog.py b/hexrd/ui/config_dialog.py index 467a9a22d..387c7bacd 100644 --- a/hexrd/ui/config_dialog.py +++ b/hexrd/ui/config_dialog.py @@ -1,3 +1,5 @@ +from PySide2.QtWidgets import QMessageBox + from hexrd.ui.hexrd_config import HexrdConfig from hexrd.ui.ui_loader import UiLoader @@ -18,9 +20,11 @@ def exec_(self): def update_gui(self): self.max_cpus_ui = self.max_cpus_config + self.font_size_ui = self.font_size_config def update_config(self): self.max_cpus_config = self.max_cpus_ui + self.font_size_config = self.font_size_ui def on_accepted(self): self.update_config() @@ -40,6 +44,14 @@ def max_cpus_ui(self, v): self.ui.max_cpus.setValue(v) + @property + def font_size_ui(self): + return self.ui.font_size.value() + + @font_size_ui.setter + def font_size_ui(self, v): + self.ui.font_size.setValue(v) + @property def max_cpus_config(self): return HexrdConfig().max_cpus @@ -47,3 +59,26 @@ def max_cpus_config(self): @max_cpus_config.setter def max_cpus_config(self, v): HexrdConfig().max_cpus = v + + @property + def font_size_config(self): + return HexrdConfig().font_size + + @font_size_config.setter + def font_size_config(self, v): + if self.font_size_config == v: + # Just return + return + + # Warn the user that they must restart the application for all + # widgets to be updated properly. + msg = ( + 'Upon changing the font size, many (but not all) widgets ' + 'will update immediately.\n\nTo ensure all widgets are updated, ' + 'please close the application normally via the "X" button in the ' + 'top corner of the main window, and then start the application ' + 'again.' + ) + QMessageBox.warning(self.ui, 'WARNING', msg) + + HexrdConfig().font_size = v diff --git a/hexrd/ui/hexrd_config.py b/hexrd/ui/hexrd_config.py index 40e50fe3b..734ba8256 100644 --- a/hexrd/ui/hexrd_config.py +++ b/hexrd/ui/hexrd_config.py @@ -7,6 +7,7 @@ from PySide2.QtCore import Signal, QCoreApplication, QObject, QSettings, QTimer import h5py +import matplotlib import numpy as np import yaml @@ -296,6 +297,9 @@ def __init__(self): self._previous_structureless_calibration_picks_data = None self.image_mode = constants.ViewType.raw + # Make sure that the matplotlib font size matches the application + self.font_size = self.font_size + self.setup_logging() default_conv = constants.DEFAULT_EULER_ANGLE_CONVENTION @@ -370,6 +374,7 @@ def _attributes_to_persist(self): ('config_calibration', None), ('config_indexing', None), ('config_image', None), + ('font_size', 11), ('images_dir', None), ('working_dir', None), ('hdf5_path', []), @@ -2316,6 +2321,25 @@ def set_tab_images(self, v): tab_images = property(tab_images, set_tab_images) + @property + def font_size(self): + return QCoreApplication.instance().font().pointSize() + + @font_size.setter + def font_size(self, v): + # Make sure this is an int + v = int(v) + + app = QCoreApplication.instance() + font = app.font() + font.setPointSize(v) + app.setFont(font) + + # Update the matplotlib font size too + if matplotlib.rcParams['font.size'] != v: + matplotlib.rcParams.update({'font.size': v}) + self.deep_rerender_needed.emit() + def set_euler_angle_convention(self, new_conv, convert_config=True): allowed_conventions = [ diff --git a/hexrd/ui/resources/ui/config_dialog.ui b/hexrd/ui/resources/ui/config_dialog.ui index 79aa7d6b1..f1c698294 100644 --- a/hexrd/ui/resources/ui/config_dialog.ui +++ b/hexrd/ui/resources/ui/config_dialog.ui @@ -7,13 +7,30 @@ 0 0 374 - 94 + 122 HEXRDGUI Configuration + + + + <html><head/><body><p>Limit the number of CPUs used for multiprocessing.</p></body></html> + + + Limit CPUs? + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + @@ -27,17 +44,7 @@ - - - - <html><head/><body><p>Limit the number of CPUs used for multiprocessing.</p></body></html> - - - Limit CPUs? - - - - + Qt::Vertical @@ -50,10 +57,26 @@ - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + Font Size: + + + font_size + + + + + + + 1 + + + 10000 + + + 11 @@ -62,6 +85,7 @@ limit_cpus max_cpus + font_size