Skip to content

Commit

Permalink
Merge pull request #949 from mantidproject/942_increase_all_fonts_in_…
Browse files Browse the repository at this point in the history
…plot

942 increase all fonts in plot
  • Loading branch information
SilkeSchomann authored Nov 2, 2023
2 parents ba4b8cd + 4ce48d5 commit 5af891e
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 4 deletions.
41 changes: 41 additions & 0 deletions src/mslice/plotting/plot_window/cut_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

DEFAULT_LABEL_SIZE = 10
DEFAULT_TITLE_SIZE = 12
DEFAULT_FONT_SIZE_STEP = 1


def get_min(data, absolute_minimum=-np.inf):
Expand Down Expand Up @@ -65,6 +66,13 @@ def __init__(self, figure_manager, cut_plotter_presenter, workspace_name):
self._intensity_type = IntensityType.SCATTERING_FUNCTION
self._intensity_correction_flag = False
self._temp_dependent = False
self.plot_fonts_properties = [
'title_size',
'x_range_font_size',
'y_range_font_size',
'x_label_size',
'y_label_size',
]

def save_default_options(self):
self.default_options = {
Expand Down Expand Up @@ -707,6 +715,10 @@ def title(self, value):
def title_size(self):
return self.manager.title_size

@title_size.setter
def title_size(self, value):
self.manager.title_size = value

@property
def x_label(self):
return self.manager.x_label
Expand All @@ -722,6 +734,10 @@ def x_label(self, value):
def x_label_size(self):
return self.manager.x_label_size

@x_label_size.setter
def x_label_size(self, value):
self.manager.x_label_size = value

@property
def y_label(self):
return self.manager.y_label
Expand All @@ -737,6 +753,10 @@ def y_label(self, value):
def y_label_size(self):
return self.manager.y_label_size

@y_label_size.setter
def y_label_size(self, value):
self.manager.y_label_size = value

@property
def x_range(self):
return self.manager.x_range
Expand Down Expand Up @@ -817,3 +837,24 @@ def is_changed(self, item):
@property
def intensity_type(self):
return self._intensity_type

@property
def all_fonts_size(self):
font_sizes_config = {}
for p in self.plot_fonts_properties:
font_sizes_config[p] = getattr(self, p)

return font_sizes_config

@all_fonts_size.setter
def all_fonts_size(self, values: dict):
for key in values:
setattr(self, key, values[key])

def increase_all_fonts(self):
for p in self.plot_fonts_properties:
setattr(self, p, getattr(self, p) + DEFAULT_FONT_SIZE_STEP)

def decrease_all_fonts(self):
for p in self.plot_fonts_properties:
setattr(self, p, getattr(self, p) - DEFAULT_FONT_SIZE_STEP)
16 changes: 14 additions & 2 deletions src/mslice/plotting/plot_window/plot_figure_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,21 @@ def figure(self):

@property
def title(self):
return self.figure.gca().get_title()
return self.figure.gca().title.get_text()

@title.setter
def title(self, value):
self.figure.gca().set_title(value)
self.figure.gca().title.set_text(value)
self.window.setWindowTitle(value)

@property
def title_size(self):
return self.figure.gca().title.get_size()

@title_size.setter
def title_size(self, value):
self.figure.gca().title.set_size(value)

@property
def x_label(self):
return self.figure.gca().get_xlabel()
Expand All @@ -328,6 +332,10 @@ def x_label(self, value):
def x_label_size(self):
return self.figure.gca().xaxis.label.get_size()

@x_label_size.setter
def x_label_size(self, value):
self.figure.gca().xaxis.label.set_size(value)

@property
def y_label(self):
return self.figure.gca().get_ylabel()
Expand All @@ -340,6 +348,10 @@ def y_label(self, value):
def y_label_size(self):
return self.figure.gca().yaxis.label.get_size()

@y_label_size.setter
def y_label_size(self, value):
self.figure.gca().yaxis.label.set_size(value)

@property
def x_range(self):
return self.figure.gca().get_xlim()
Expand Down
48 changes: 47 additions & 1 deletion src/mslice/plotting/plot_window/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from qtpy.QtCore import Signal
from mslice.models.colors import named_cycle_colors, color_to_name
from mslice.util.qt import load_ui

from qtpy.QtGui import QRegExpValidator
from qtpy.QtCore import QRegExp
from mantidqt.utils.qt.line_edit_double_validator import LineEditDoubleValidator
from mantidqt.icons import get_icon


class PlotOptionsDialog(QtWidgets.QDialog):
Expand All @@ -20,12 +22,19 @@ class PlotOptionsDialog(QtWidgets.QDialog):
yRangeEdited = Signal()
xGridEdited = Signal()
yGridEdited = Signal()
allFontSizeEdited = Signal()
fontSizeUpClicked = Signal()
fontSizeDownClicked = Signal()
allFontSizeFromEmptyToValue = Signal()
ok_clicked = Signal()

def __init__(self, parent, redraw_signal=None):
QtWidgets.QDialog.__init__(self, parent)
load_ui(__file__, 'plot_options.ui', self)

self.sclUpFntSz.setIcon(get_icon("mdi.arrow-up"))
self.sclDownFntSz.setIcon(get_icon("mdi.arrow-down"))

self.x_min_validator = LineEditDoubleValidator(self.lneXMin, 0.0)
self.lneXMin.setValidator(self.x_min_validator)
self.x_max_validator = LineEditDoubleValidator(self.lneXMax, 0.0)
Expand All @@ -34,6 +43,9 @@ def __init__(self, parent, redraw_signal=None):
self.lneYMin.setValidator(self.y_min_validator)
self.y_max_validator = LineEditDoubleValidator(self.lneYMax, 0.0)
self.lneYMax.setValidator(self.y_max_validator)
two_postv_ints_regex = QRegExp(r"^\s*[1-9][0-9]?$")
self.all_fonts_size_validator = QRegExpValidator(two_postv_ints_regex)
self.allFntSz.setValidator(self.all_fonts_size_validator)

self.lneFigureTitle.editingFinished.connect(self.titleEdited)
self.lneXAxisLabel.editingFinished.connect(self.xLabelEdited)
Expand All @@ -46,8 +58,31 @@ def __init__(self, parent, redraw_signal=None):
self.buttonBox.rejected.connect(self.reject)
self.chkXGrid.stateChanged.connect(self.xGridEdited)
self.chkYGrid.stateChanged.connect(self.yGridEdited)

self.allFntSz.textEdited.connect(self._font_sizes_changed)
self.sclUpFntSz.clicked.connect(self._scale_up_fonts_clicked)
self.sclDownFntSz.clicked.connect(self._scale_down_fonts_clicked)

self.redraw_signal = redraw_signal

self.allFntSzBuffer = ''

def _font_sizes_changed(self):
if self.allFntSzBuffer == '':
self.allFontSizeFromEmptyToValue.emit()
self.allFntSzBuffer = str(self.allFntSz.text())

self.allFontSizeEdited.emit()
self.redraw_signal.emit()

def _scale_up_fonts_clicked(self):
self.fontSizeUpClicked.emit()
self.redraw_signal.emit()

def _scale_down_fonts_clicked(self):
self.fontSizeDownClicked.emit()
self.redraw_signal.emit()

def _ok_clicked(self):
self.ok_clicked.emit()
self.redraw_signal.emit()
Expand Down Expand Up @@ -134,6 +169,17 @@ def y_grid(self, value):
def is_kept_open(self):
return self.keep_open.isChecked()

@property
def all_fonts_size(self):
try:
return float(str(self.allFntSz.text()))
except ValueError:
return None

@all_fonts_size.setter
def all_fonts_size(self, value):
self.allFntSz.setText(str(value))


class SlicePlotOptions(PlotOptionsDialog):

Expand Down
34 changes: 34 additions & 0 deletions src/mslice/plotting/plot_window/plot_options.ui
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,40 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Figure Fonts</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblAllFntSz">
<property name="text">
<string>Set all fonts size</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="allFntSz">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="sclUpFntSz">
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="sclDownFntSz">
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
47 changes: 47 additions & 0 deletions src/mslice/plotting/plot_window/slice_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

DEFAULT_LABEL_SIZE = 10
DEFAULT_TITLE_SIZE = 12
DEFAULT_FONT_SIZE_STEP = 1


class SlicePlot(IPlot):
Expand Down Expand Up @@ -54,6 +55,15 @@ def __init__(self, figure_manager, slice_plotter_presenter, workspace_name):
self.temp_dependent = False
self.temp = None
self.default_options = None
self.plot_fonts_properties = [
'title_size',
'x_range_font_size',
'y_range_font_size',
'x_label_size',
'y_label_size',
'colorbar_label_size',
'colorbar_range_font_size'
]

def save_default_options(self):
self.default_options = {
Expand Down Expand Up @@ -473,6 +483,10 @@ def colorbar_label(self, value):
def colorbar_label_size(self):
return self._canvas.figure.get_axes()[1].yaxis.label.get_size()

@colorbar_label_size.setter
def colorbar_label_size(self, value):
self._canvas.figure.get_axes()[1].yaxis.label.set_size(value)

@property
def colorbar_range(self):
return self._canvas.figure.gca().collections[0].get_clim()
Expand Down Expand Up @@ -512,6 +526,10 @@ def title(self, value):
def title_size(self):
return self.manager.title_size

@title_size.setter
def title_size(self, value):
self.manager.title_size = value

@property
def x_label(self):
return self.manager.x_label
Expand All @@ -527,6 +545,10 @@ def x_label(self, value):
def x_label_size(self):
return self.manager.x_label_size

@x_label_size.setter
def x_label_size(self, value):
self.manager.x_label_size = value

@property
def y_label(self):
return self.manager.y_label
Expand All @@ -542,6 +564,10 @@ def y_label(self, value):
def y_label_size(self):
return self.manager.y_label_size

@y_label_size.setter
def y_label_size(self, value):
self.manager.y_label_size = value

@property
def x_range(self):
return self.manager.x_range
Expand Down Expand Up @@ -613,3 +639,24 @@ def _get_overplot_datum(): # needed for interface consistency with cut plot

def set_cross_cursor(self):
self._canvas.setCursor(Qt.CrossCursor)

@property
def all_fonts_size(self):
font_sizes_config = {}
for p in self.plot_fonts_properties:
font_sizes_config[p] = getattr(self, p)

return font_sizes_config

@all_fonts_size.setter
def all_fonts_size(self, values: dict):
for key in values:
setattr(self, key, values[key])

def increase_all_fonts(self):
for p in self.plot_fonts_properties:
setattr(self, p, getattr(self, p) + DEFAULT_FONT_SIZE_STEP)

def decrease_all_fonts(self):
for p in self.plot_fonts_properties:
setattr(self, p, getattr(self, p) - DEFAULT_FONT_SIZE_STEP)
Loading

0 comments on commit 5af891e

Please sign in to comment.