Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to modify the font size of the app #1582

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions hexrd/ui/config_dialog.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from PySide2.QtWidgets import QMessageBox

from hexrd.ui.hexrd_config import HexrdConfig
from hexrd.ui.ui_loader import UiLoader

Expand All @@ -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()
Expand All @@ -40,10 +44,41 @@ 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

@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
24 changes: 24 additions & 0 deletions hexrd/ui/hexrd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from PySide2.QtCore import Signal, QCoreApplication, QObject, QSettings, QTimer

import h5py
import matplotlib
import numpy as np
import yaml

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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', []),
Expand Down Expand Up @@ -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 = [
Expand Down
56 changes: 40 additions & 16 deletions hexrd/ui/resources/ui/config_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@
<x>0</x>
<y>0</y>
<width>374</width>
<height>94</height>
<height>122</height>
</rect>
</property>
<property name="windowTitle">
<string>HEXRDGUI Configuration</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QCheckBox" name="limit_cpus">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Limit the number of CPUs used for multiprocessing.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Limit CPUs?</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QDialogButtonBox" name="button_box">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="max_cpus">
<property name="enabled">
Expand All @@ -27,17 +44,7 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="limit_cpus">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Limit the number of CPUs used for multiprocessing.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Limit CPUs?</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -50,10 +57,26 @@
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QDialogButtonBox" name="button_box">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<item row="1" column="0">
<widget class="QLabel" name="font_size_label">
<property name="text">
<string>Font Size:</string>
</property>
<property name="buddy">
<cstring>font_size</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="font_size">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
<property name="value">
<number>11</number>
</property>
</widget>
</item>
Expand All @@ -62,6 +85,7 @@
<tabstops>
<tabstop>limit_cpus</tabstop>
<tabstop>max_cpus</tabstop>
<tabstop>font_size</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down
Loading