From f22fdc7059afefd794e763ddf2c19d6ce77ec890 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Fri, 29 Sep 2023 15:28:41 +0100 Subject: [PATCH 01/33] Added the scaling factor to name of suntracted ws --- src/mslice/models/workspacemanager/workspace_algorithms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mslice/models/workspacemanager/workspace_algorithms.py b/src/mslice/models/workspacemanager/workspace_algorithms.py index 942bb1a3..682ed460 100644 --- a/src/mslice/models/workspacemanager/workspace_algorithms.py +++ b/src/mslice/models/workspacemanager/workspace_algorithms.py @@ -208,7 +208,7 @@ def subtract(workspaces, background_ws, ssf): InputWorkspace=str(background_ws), Factor=ssf, store=False) try: for ws_name in workspaces: - result = Minus(OutputWorkspace=ws_name + '_subtracted', LHSWorkspace=ws_name, + result = Minus(OutputWorkspace=ws_name + f'_subtracted_by_{ssf:.2f}', LHSWorkspace=ws_name, RHSWorkspace=scaled_bg_ws) propagate_properties(get_workspace_handle(ws_name), result) except ValueError as e: From 0e05810bdc3967fe2ca518fa29909064c08dc794 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Mon, 2 Oct 2023 16:30:50 +0100 Subject: [PATCH 02/33] Simple first version Implemented a tick box to change the font size of both axes simultatneously. The code for this is in the wrong placement currently, and also to change label sizes it'll be trickier. --- src/mslice/plotting/plot_window/quick_options.py | 2 ++ src/mslice/presenters/quick_options_presenter.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/mslice/plotting/plot_window/quick_options.py b/src/mslice/plotting/plot_window/quick_options.py index e07686c4..f53830fa 100644 --- a/src/mslice/plotting/plot_window/quick_options.py +++ b/src/mslice/plotting/plot_window/quick_options.py @@ -46,6 +46,7 @@ def __init__(self, parent, target, existing_values, font_size, grid, log, redraw self.font_size = QtWidgets.QDoubleSpinBox() self.decimals = 1 self.font_size.setValue(font_size) + self.all_fonts_size = QtWidgets.QCheckBox("Update All Fonts") row1 = QtWidgets.QHBoxLayout() row2 = QtWidgets.QHBoxLayout() @@ -71,6 +72,7 @@ def __init__(self, parent, target, existing_values, font_size, grid, log, redraw row5 = QtWidgets.QHBoxLayout() row5.addWidget(self.log_scale) self.layout.addLayout(row5) + self.layout.addWidget(self.all_fonts_size) # Tick box for all font sizes self.layout.addLayout(self.button_row) self.layout.addWidget(self.keep_open) self.ok_button.clicked.disconnect() diff --git a/src/mslice/presenters/quick_options_presenter.py b/src/mslice/presenters/quick_options_presenter.py index bb450286..94272bab 100644 --- a/src/mslice/presenters/quick_options_presenter.py +++ b/src/mslice/presenters/quick_options_presenter.py @@ -55,6 +55,10 @@ def _set_axis_options(view, target, model, has_logarithmic, grid): setattr(model, target + "_font_size", view.font_size.value()) + # Experiment with setting both axis font size + if view.all_fonts_size.isChecked(): + setattr(model, "x_range_font_size", view.font_size.value()) + setattr(model, "y_range_font_size", view.font_size.value()) def _set_label_options(view, target): _set_label(view, target) From f70c0aeb1d5a266c8c74404fb067f62210ecfcf1 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 3 Oct 2023 11:30:30 +0100 Subject: [PATCH 03/33] Created function that updates all font sizes Added function to update all font sizes, The trigger is a tick box, currently included only in the quick options window for axis. --- src/mslice/plotting/plot_window/cut_plot.py | 8 ++++++++ .../plotting/plot_window/plot_figure_manager.py | 8 ++++++++ src/mslice/presenters/quick_options_presenter.py | 12 +++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index bc0dd5d0..1b6ae5c4 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -722,6 +722,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 @@ -737,6 +741,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 diff --git a/src/mslice/plotting/plot_window/plot_figure_manager.py b/src/mslice/plotting/plot_window/plot_figure_manager.py index 2a54ff32..1fb43306 100644 --- a/src/mslice/plotting/plot_window/plot_figure_manager.py +++ b/src/mslice/plotting/plot_window/plot_figure_manager.py @@ -326,6 +326,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() @@ -338,6 +342,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() diff --git a/src/mslice/presenters/quick_options_presenter.py b/src/mslice/presenters/quick_options_presenter.py index 94272bab..fabcac0d 100644 --- a/src/mslice/presenters/quick_options_presenter.py +++ b/src/mslice/presenters/quick_options_presenter.py @@ -55,10 +55,16 @@ def _set_axis_options(view, target, model, has_logarithmic, grid): setattr(model, target + "_font_size", view.font_size.value()) - # Experiment with setting both axis font size if view.all_fonts_size.isChecked(): - setattr(model, "x_range_font_size", view.font_size.value()) - setattr(model, "y_range_font_size", view.font_size.value()) + _set_all_font_sizes(view, model) + + +def _set_all_font_sizes(view, model): + setattr(model, "x_range_font_size", view.font_size.value()) + setattr(model, "y_range_font_size", view.font_size.value()) + setattr(model, "y_label_size", view.font_size.value()) + setattr(model, "x_label_size", view.font_size.value()) + def _set_label_options(view, target): _set_label(view, target) From b642bb73e6c5006c245d4145c2e5614a3cf89bed Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 3 Oct 2023 16:34:49 +0100 Subject: [PATCH 04/33] Changed location of the tick box to inside of plot options Changing the size of all fonts in plot is more of a global option. Set this to show inside plot options ui. Still need to make the same changes for slice plot. Needs further work. --- src/mslice/plotting/plot_window/cut_plot.py | 4 +++ .../plotting/plot_window/plot_options.py | 12 +++++++ .../plotting/plot_window/plot_options.ui | 33 +++++++++++++++++++ .../plotting/plot_window/quick_options.py | 2 -- .../presenters/plot_options_presenter.py | 12 ++++++- 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index 1b6ae5c4..bc5fa74f 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -825,3 +825,7 @@ def is_changed(self, item): @property def intensity_type(self): return self._intensity_type + + @property + def all_fonts_size(self): + return DEFAULT_LABEL_SIZE diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index e2e4e066..c6875800 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -134,6 +134,18 @@ def y_grid(self, value): def is_kept_open(self): return self.keep_open.isChecked() + @property + def all_fonts_size(self): + try: + size = float(str(self.allFontsSize.text())) + except ValueError: + return None + return size + + @all_fonts_size.setter + def all_fonts_size(self, value): + self.allFontsSize.setText(str(value)) + class SlicePlotOptions(PlotOptionsDialog): diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index 1f1998f8..843d765c 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -195,6 +195,39 @@ + + + + Text + + + + + + Font Size + + + + + + + + 16777215 + 16777215 + + + + + + + + Set All Fonts + + + + + + diff --git a/src/mslice/plotting/plot_window/quick_options.py b/src/mslice/plotting/plot_window/quick_options.py index f53830fa..e07686c4 100644 --- a/src/mslice/plotting/plot_window/quick_options.py +++ b/src/mslice/plotting/plot_window/quick_options.py @@ -46,7 +46,6 @@ def __init__(self, parent, target, existing_values, font_size, grid, log, redraw self.font_size = QtWidgets.QDoubleSpinBox() self.decimals = 1 self.font_size.setValue(font_size) - self.all_fonts_size = QtWidgets.QCheckBox("Update All Fonts") row1 = QtWidgets.QHBoxLayout() row2 = QtWidgets.QHBoxLayout() @@ -72,7 +71,6 @@ def __init__(self, parent, target, existing_values, font_size, grid, log, redraw row5 = QtWidgets.QHBoxLayout() row5.addWidget(self.log_scale) self.layout.addLayout(row5) - self.layout.addWidget(self.all_fonts_size) # Tick box for all font sizes self.layout.addLayout(self.button_row) self.layout.addWidget(self.keep_open) self.ok_button.clicked.disconnect() diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index b91b2bfb..83ce4fff 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -82,7 +82,7 @@ def __init__(self, plot_options_dialog, cut_handler): def set_properties(self): properties = ['title', 'x_label', 'y_label', 'x_range', 'y_range', 'x_log', 'y_log', - 'x_grid', 'y_grid', 'show_legends'] + 'x_grid', 'y_grid', 'show_legends', 'all_fonts_size'] for p in properties: setattr(self._view, p, getattr(self._model, p)) @@ -107,3 +107,13 @@ def get_new_config(self): self._model.manager.window.action_toggle_legends.trigger() self._model.set_all_line_options(line_options, new_show_legends) + + if self._view.chkAllFonts.isChecked(): + self._set_all_font_size() + + def _set_all_font_size(self): + font_size = float(str(self._view.allFontsSize.text())) + setattr(self._model, "x_range_font_size", font_size) + setattr(self._model, "y_range_font_size", font_size) + setattr(self._model, "y_label_size", font_size) + setattr(self._model, "x_label_size", font_size) From febdc9d5dfba266adeb66a19a309fca4a5d9400f Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 3 Oct 2023 16:37:29 +0100 Subject: [PATCH 05/33] Deleted old code from previous commit --- src/mslice/presenters/quick_options_presenter.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/mslice/presenters/quick_options_presenter.py b/src/mslice/presenters/quick_options_presenter.py index fabcac0d..bb450286 100644 --- a/src/mslice/presenters/quick_options_presenter.py +++ b/src/mslice/presenters/quick_options_presenter.py @@ -55,16 +55,6 @@ def _set_axis_options(view, target, model, has_logarithmic, grid): setattr(model, target + "_font_size", view.font_size.value()) - if view.all_fonts_size.isChecked(): - _set_all_font_sizes(view, model) - - -def _set_all_font_sizes(view, model): - setattr(model, "x_range_font_size", view.font_size.value()) - setattr(model, "y_range_font_size", view.font_size.value()) - setattr(model, "y_label_size", view.font_size.value()) - setattr(model, "x_label_size", view.font_size.value()) - def _set_label_options(view, target): _set_label(view, target) From 23e9c955adbeeebd216f9c86ec7d7d833d3fe24f Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Wed, 4 Oct 2023 10:19:34 +0100 Subject: [PATCH 06/33] Fitted my changes into the existing paradigm Function that updates all fonts went into CutPlot class. Changed getters and setters of both window view() and CutPlot class. Established connections between getters and setters as done for all the other attributes. --- src/mslice/plotting/plot_window/cut_plot.py | 7 +++++++ src/mslice/plotting/plot_window/plot_options.py | 6 ++++-- src/mslice/plotting/plot_window/plot_options.ui | 4 ++-- src/mslice/presenters/plot_options_presenter.py | 11 +---------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index bc5fa74f..f2bd5e3d 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -829,3 +829,10 @@ def intensity_type(self): @property def all_fonts_size(self): return DEFAULT_LABEL_SIZE + + @all_fonts_size.setter + def all_fonts_size(self, value): + self.x_range_font_size = value + self.y_range_font_size = value + self.x_label_size = value + self.y_label_size = value diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index c6875800..f357a166 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -20,6 +20,7 @@ class PlotOptionsDialog(QtWidgets.QDialog): yRangeEdited = Signal() xGridEdited = Signal() yGridEdited = Signal() + allFontSizeEdited = Signal() ok_clicked = Signal() def __init__(self, parent, redraw_signal=None): @@ -46,6 +47,7 @@ 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.chkAllFntSize.stateChanged.connect(self.allFontSizeEdited) self.redraw_signal = redraw_signal def _ok_clicked(self): @@ -137,14 +139,14 @@ def is_kept_open(self): @property def all_fonts_size(self): try: - size = float(str(self.allFontsSize.text())) + size = float(str(self.allFntSize.text())) except ValueError: return None return size @all_fonts_size.setter def all_fonts_size(self, value): - self.allFontsSize.setText(str(value)) + self.allFntSize.setText(str(value)) class SlicePlotOptions(PlotOptionsDialog): diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index 843d765c..ee0a4b01 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -209,7 +209,7 @@ - + 16777215 @@ -219,7 +219,7 @@ - + Set All Fonts diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 83ce4fff..5c8499cf 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -19,6 +19,7 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.yRangeEdited.connect(partial(self._xy_config_modified, 'y_range')) self._view.xGridEdited.connect(partial(self._value_modified, 'x_grid')) self._view.yGridEdited.connect(partial(self._value_modified, 'y_grid')) + self._view.allFontSizeEdited.connect(partial(self._value_modified, 'all_fonts_size')) def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) @@ -107,13 +108,3 @@ def get_new_config(self): self._model.manager.window.action_toggle_legends.trigger() self._model.set_all_line_options(line_options, new_show_legends) - - if self._view.chkAllFonts.isChecked(): - self._set_all_font_size() - - def _set_all_font_size(self): - font_size = float(str(self._view.allFontsSize.text())) - setattr(self._model, "x_range_font_size", font_size) - setattr(self._model, "y_range_font_size", font_size) - setattr(self._model, "y_label_size", font_size) - setattr(self._model, "x_label_size", font_size) From e51de6fc473364e4604338a2113db71b2f1f6bb4 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Wed, 4 Oct 2023 11:12:38 +0100 Subject: [PATCH 07/33] Altered UI widget Took out checkbox and changed position of widget. --- .../plotting/plot_window/plot_options.py | 2 +- .../plotting/plot_window/plot_options.ui | 59 ++++++++----------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index f357a166..79b8ae83 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -47,7 +47,7 @@ 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.chkAllFntSize.stateChanged.connect(self.allFontSizeEdited) + self.allFntSize.textEdited.connect(self.allFontSizeEdited) self.redraw_signal = redraw_signal def _ok_clicked(self): diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index ee0a4b01..e3e23689 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -195,39 +195,6 @@ - - - - Text - - - - - - Font Size - - - - - - - - 16777215 - 16777215 - - - - - - - - Set All Fonts - - - - - - @@ -264,6 +231,32 @@ + + + + Figure Fonts + + + + + + All fonts size + + + + + + + + 16777215 + 16777215 + + + + + + + From 85e41cd6bf0cfc9e65edcb1e7017660d480d6a8c Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Wed, 4 Oct 2023 11:42:08 +0100 Subject: [PATCH 08/33] Made changes to slice plot Made analogous changes to slice plot --- src/mslice/plotting/plot_window/cut_plot.py | 5 ++++ .../plot_window/plot_figure_manager.py | 4 +++ src/mslice/plotting/plot_window/slice_plot.py | 30 +++++++++++++++++++ .../presenters/plot_options_presenter.py | 2 +- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index f2bd5e3d..c83f20e2 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -707,6 +707,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 @@ -832,6 +836,7 @@ def all_fonts_size(self): @all_fonts_size.setter def all_fonts_size(self, value): + self.title_size = value self.x_range_font_size = value self.y_range_font_size = value self.x_label_size = value diff --git a/src/mslice/plotting/plot_window/plot_figure_manager.py b/src/mslice/plotting/plot_window/plot_figure_manager.py index 1fb43306..a970dc6e 100644 --- a/src/mslice/plotting/plot_window/plot_figure_manager.py +++ b/src/mslice/plotting/plot_window/plot_figure_manager.py @@ -314,6 +314,10 @@ def title(self, value): 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() diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index 780115fd..1e275bb6 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -469,6 +469,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() @@ -508,6 +512,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 @@ -523,6 +531,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 @@ -538,6 +550,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 @@ -609,3 +625,17 @@ 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): + return DEFAULT_LABEL_SIZE + + @all_fonts_size.setter + def all_fonts_size(self, value): + self.title_size = value + self.x_range_font_size = value + self.y_range_font_size = value + self.x_label_size = value + self.y_label_size = value + self.colorbar_label_size = value + self.colorbar_range_font_size = value diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 5c8499cf..88bfa5ff 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -43,7 +43,7 @@ def __init__(self, plot_options_dialog, slice_handler): def set_properties(self): properties = ['title', 'x_label', 'y_label', 'x_range', 'y_range', 'x_grid', 'y_grid', - 'colorbar_range', 'colorbar_log'] + 'colorbar_range', 'colorbar_log', 'all_fonts_size'] for p in properties: setattr(self._view, p, getattr(self._model, p)) From 5a7962a020668f7a63e69a5dcedd660c310c9d3b Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Wed, 4 Oct 2023 15:44:05 +0100 Subject: [PATCH 09/33] Added opiton to scale fonts Added an option to scale all fonts in a slice and cut plot as to preserve the proportion of the font sizes. Changed the getter and setter of plot title as to change only the text in the title, and not other parameters like font size. All functunality is working except when plot options window is set to open. When window is not closed, strange things happen when using the scaling option. --- src/mslice/plotting/plot_window/cut_plot.py | 14 ++++++++++++++ .../plot_window/plot_figure_manager.py | 4 ++-- .../plotting/plot_window/plot_options.py | 14 ++++++++++++++ .../plotting/plot_window/plot_options.ui | 19 ++++++++++++++++++- src/mslice/plotting/plot_window/slice_plot.py | 15 +++++++++++++++ .../presenters/plot_options_presenter.py | 5 +++-- 6 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index c83f20e2..0c882b55 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -1,4 +1,5 @@ from functools import partial +from mantid import PropertyManagerDataService from qtpy import QtWidgets @@ -29,6 +30,7 @@ DEFAULT_LABEL_SIZE = 10 DEFAULT_TITLE_SIZE = 12 +DEFAULT_SCALE_FONT_SIZE = 0 def get_min(data, absolute_minimum=-np.inf): @@ -841,3 +843,15 @@ def all_fonts_size(self, value): self.y_range_font_size = value self.x_label_size = value self.y_label_size = value + + @property + def scale_all_fonts(self): + return DEFAULT_SCALE_FONT_SIZE + + @scale_all_fonts.setter + def scale_all_fonts(self, value): + self.title_size += value + self.x_range_font_size += value + self.y_range_font_size += value + self.x_label_size += value + self.y_label_size += value diff --git a/src/mslice/plotting/plot_window/plot_figure_manager.py b/src/mslice/plotting/plot_window/plot_figure_manager.py index a970dc6e..b6474163 100644 --- a/src/mslice/plotting/plot_window/plot_figure_manager.py +++ b/src/mslice/plotting/plot_window/plot_figure_manager.py @@ -303,11 +303,11 @@ 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 diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index 79b8ae83..c5ceb9d8 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -21,6 +21,7 @@ class PlotOptionsDialog(QtWidgets.QDialog): xGridEdited = Signal() yGridEdited = Signal() allFontSizeEdited = Signal() + scaleAllFontsEdited = Signal() ok_clicked = Signal() def __init__(self, parent, redraw_signal=None): @@ -48,6 +49,7 @@ def __init__(self, parent, redraw_signal=None): self.chkXGrid.stateChanged.connect(self.xGridEdited) self.chkYGrid.stateChanged.connect(self.yGridEdited) self.allFntSize.textEdited.connect(self.allFontSizeEdited) + self.sclAllFntSize.valueChanged.connect(self.scaleAllFontsEdited) self.redraw_signal = redraw_signal def _ok_clicked(self): @@ -148,6 +150,18 @@ def all_fonts_size(self): def all_fonts_size(self, value): self.allFntSize.setText(str(value)) + @property + def scale_all_fonts(self): + try: + scl_factor = float(self.sclAllFntSize.value()) + except ValueError: + return None + return scl_factor + + @scale_all_fonts.setter + def scale_all_fonts(self, value): + self.sclAllFntSize.setValue(value) + class SlicePlotOptions(PlotOptionsDialog): diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index e3e23689..cb2d2b4e 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -240,7 +240,7 @@ - All fonts size + Set all fonts size @@ -254,6 +254,23 @@ + + + + Scale all fonts by + + + + + + + 50 + + + -50 + + + diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index 1e275bb6..d01c2acb 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -27,6 +27,7 @@ DEFAULT_LABEL_SIZE = 10 DEFAULT_TITLE_SIZE = 12 +DEFAULT_SCALE_FONT_SIZE = 0 class SlicePlot(IPlot): @@ -639,3 +640,17 @@ def all_fonts_size(self, value): self.y_label_size = value self.colorbar_label_size = value self.colorbar_range_font_size = value + + @property + def scale_all_fonts(self): + return DEFAULT_SCALE_FONT_SIZE + + @scale_all_fonts.setter + def scale_all_fonts(self, value): + self.title_size += value + self.x_range_font_size += value + self.y_range_font_size += value + self.x_label_size += value + self.y_label_size += value + self.colorbar_label_size += value + self.colorbar_range_font_size += value diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 88bfa5ff..1f6eeef6 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -20,6 +20,7 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.xGridEdited.connect(partial(self._value_modified, 'x_grid')) self._view.yGridEdited.connect(partial(self._value_modified, 'y_grid')) self._view.allFontSizeEdited.connect(partial(self._value_modified, 'all_fonts_size')) + self._view.scaleAllFontsEdited.connect(partial(self._value_modified, 'scale_all_fonts')) def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) @@ -43,7 +44,7 @@ def __init__(self, plot_options_dialog, slice_handler): def set_properties(self): properties = ['title', 'x_label', 'y_label', 'x_range', 'y_range', 'x_grid', 'y_grid', - 'colorbar_range', 'colorbar_log', 'all_fonts_size'] + 'colorbar_range', 'colorbar_log', 'all_fonts_size', 'scale_all_fonts'] for p in properties: setattr(self._view, p, getattr(self._model, p)) @@ -83,7 +84,7 @@ def __init__(self, plot_options_dialog, cut_handler): def set_properties(self): properties = ['title', 'x_label', 'y_label', 'x_range', 'y_range', 'x_log', 'y_log', - 'x_grid', 'y_grid', 'show_legends', 'all_fonts_size'] + 'x_grid', 'y_grid', 'show_legends', 'all_fonts_size', 'scale_all_fonts'] for p in properties: setattr(self._view, p, getattr(self._model, p)) From 33609e8ca2353fa6ae7b8785551e15317a4af692 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Thu, 5 Oct 2023 15:57:44 +0100 Subject: [PATCH 10/33] Added all missing functunality and corrected bugs Devised a possibly over-engineered solution to provide the best experience for the users. This implementation uses two checkboxes and two text fieds to control setting and scaling of fonts. Tested manually on slice and cut plots, with closing and keeping the options window open. The GUI prevents users from selecting scaling and setting simultaneously. Short explanation: When any parameters are changed in the GUI of plot options, they are appended to temporary dictionary. When the OK button is pressed, all changes stored in the temp dict are loaded onto the plot figure. In my imlpementation, when a checkbox changes state, it can send two distinct signals. One of the signals appends the desired value to the temp dict and the other removes from the dict. This way, the user fully controls what changes are made from the two checkboxes provided. --- .../plotting/plot_window/plot_options.py | 63 ++++++++++++++++--- .../plotting/plot_window/plot_options.ui | 10 +-- .../presenters/plot_options_presenter.py | 9 ++- 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index c5ceb9d8..a2e2d7b9 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -20,10 +20,13 @@ class PlotOptionsDialog(QtWidgets.QDialog): yRangeEdited = Signal() xGridEdited = Signal() yGridEdited = Signal() - allFontSizeEdited = Signal() - scaleAllFontsEdited = Signal() ok_clicked = Signal() + allFontSizeIncluded = Signal() + allFontSizeRemoved = Signal() + scaleAllFontsIncluded = Signal() + scaleAllFontsRemoved = Signal() + def __init__(self, parent, redraw_signal=None): QtWidgets.QDialog.__init__(self, parent) load_ui(__file__, 'plot_options.ui', self) @@ -48,8 +51,16 @@ 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.allFntSize.textEdited.connect(self.allFontSizeEdited) - self.sclAllFntSize.valueChanged.connect(self.scaleAllFontsEdited) + + self.chkAllFntSz.setCheckState(False) + self.chkAllFntSz.stateChanged.connect(self._all_fonts_size_state_changed) + self.chkSclAllFntSz.setCheckState(False) + self.chkSclAllFntSz.stateChanged.connect(self._scale_all_fonts_state_changed) + self.allFntSz.setEnabled(False) + self.allFntSz.editingFinished.connect(self.allFontSizeIncluded) + self.sclAllFntSz.setEnabled(False) + self.sclAllFntSz.editingFinished.connect(self.scaleAllFontsIncluded) + self.redraw_signal = redraw_signal def _ok_clicked(self): @@ -58,6 +69,42 @@ def _ok_clicked(self): if not self.is_kept_open: self.accept() + def _all_fonts_size_state_changed(self): + self._chk_box_state_changed( + chk_box=self.chkAllFntSz, + txt_box=self.allFntSz, + include_signal=self.allFontSizeIncluded, + remove_signal=self.allFontSizeRemoved, + other_chk_box=self.chkSclAllFntSz + ) + + def _scale_all_fonts_state_changed(self): + self._chk_box_state_changed( + chk_box=self.chkSclAllFntSz, + txt_box=self.sclAllFntSz, + include_signal=self.scaleAllFontsIncluded, + remove_signal=self.scaleAllFontsRemoved, + other_chk_box=self.chkAllFntSz + ) + + def _chk_box_state_changed(self, chk_box, txt_box, include_signal, remove_signal, other_chk_box): + self._set_txt_to_match_chk(txt_box, chk_box) + self._choose_signal_to_emit(chk_box, include_signal, remove_signal) + self._uncheck_other_chk_box(chk_box, other_chk_box) + + def _set_txt_to_match_chk(self, txt_box, chk_box): + txt_box.setEnabled(chk_box.isChecked()) + + def _choose_signal_to_emit(self, chk_box, include_signal, remove_signal): + if chk_box.isChecked(): + include_signal.emit() + else: + remove_signal.emit() + + def _uncheck_other_chk_box(self, chk_box_current, chk_box_other): + if chk_box_current.isChecked(): + chk_box_other.setCheckState(False) + @property def x_range(self): try: @@ -141,26 +188,26 @@ def is_kept_open(self): @property def all_fonts_size(self): try: - size = float(str(self.allFntSize.text())) + size = float(str(self.allFntSz.text())) except ValueError: return None return size @all_fonts_size.setter def all_fonts_size(self, value): - self.allFntSize.setText(str(value)) + self.allFntSz.setText(str(value)) @property def scale_all_fonts(self): try: - scl_factor = float(self.sclAllFntSize.value()) + scl_factor = float(self.sclAllFntSz.value()) except ValueError: return None return scl_factor @scale_all_fonts.setter def scale_all_fonts(self, value): - self.sclAllFntSize.setValue(value) + self.sclAllFntSz.setValue(value) class SlicePlotOptions(PlotOptionsDialog): diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index cb2d2b4e..9f27d32a 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -238,14 +238,14 @@ - + Set all fonts size - + 16777215 @@ -255,14 +255,14 @@ - + - Scale all fonts by + Scale all fonts - + 50 diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 1f6eeef6..6990a5ec 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -19,8 +19,10 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.yRangeEdited.connect(partial(self._xy_config_modified, 'y_range')) self._view.xGridEdited.connect(partial(self._value_modified, 'x_grid')) self._view.yGridEdited.connect(partial(self._value_modified, 'y_grid')) - self._view.allFontSizeEdited.connect(partial(self._value_modified, 'all_fonts_size')) - self._view.scaleAllFontsEdited.connect(partial(self._value_modified, 'scale_all_fonts')) + self._view.allFontSizeIncluded.connect(partial(self._value_modified, 'all_fonts_size')) + self._view.allFontSizeRemoved.connect(partial(self._remove_value_modified, 'all_fonts_size')) + self._view.scaleAllFontsIncluded.connect(partial(self._value_modified, 'scale_all_fonts')) + self._view.scaleAllFontsRemoved.connect(partial(self._remove_value_modified, 'scale_all_fonts')) def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) @@ -29,6 +31,9 @@ def _xy_config_modified(self, key): getattr(self, '_xy_config')[key] = getattr(self._view, key) self._xy_config['modified'] = True + def _remove_value_modified(self, value_name): + del self._modified_values[value_name] + class SlicePlotOptionsPresenter(PlotOptionsPresenter): From 19605dc61b115177254afbf07472314a186c17c1 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Thu, 5 Oct 2023 16:12:47 +0100 Subject: [PATCH 11/33] Corrected a line from previous commits --- src/mslice/models/workspacemanager/workspace_algorithms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mslice/models/workspacemanager/workspace_algorithms.py b/src/mslice/models/workspacemanager/workspace_algorithms.py index 682ed460..942bb1a3 100644 --- a/src/mslice/models/workspacemanager/workspace_algorithms.py +++ b/src/mslice/models/workspacemanager/workspace_algorithms.py @@ -208,7 +208,7 @@ def subtract(workspaces, background_ws, ssf): InputWorkspace=str(background_ws), Factor=ssf, store=False) try: for ws_name in workspaces: - result = Minus(OutputWorkspace=ws_name + f'_subtracted_by_{ssf:.2f}', LHSWorkspace=ws_name, + result = Minus(OutputWorkspace=ws_name + '_subtracted', LHSWorkspace=ws_name, RHSWorkspace=scaled_bg_ws) propagate_properties(get_workspace_handle(ws_name), result) except ValueError as e: From afa1a9618717a90554af138537ccf0b9bda967a9 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Fri, 6 Oct 2023 09:25:42 +0100 Subject: [PATCH 12/33] Removed unused import --- src/mslice/plotting/plot_window/cut_plot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index 0c882b55..bd760932 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -1,5 +1,4 @@ from functools import partial -from mantid import PropertyManagerDataService from qtpy import QtWidgets From cd1603c28abdee6f1fd6bf430074d1038df9f7d3 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Fri, 6 Oct 2023 12:48:42 +0100 Subject: [PATCH 13/33] Added tests for cut and slice plots, and options presenter --- tests/cut_plot_test.py | 17 ++++++++ tests/plot_options_presenter_test.py | 62 ++++++++++++++++++++++++++++ tests/slice_plot_test.py | 35 ++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/tests/cut_plot_test.py b/tests/cut_plot_test.py index 55ac74dd..7bba200c 100644 --- a/tests/cut_plot_test.py +++ b/tests/cut_plot_test.py @@ -104,3 +104,20 @@ def test_waterfall(self): self.cut_plot.toggle_waterfall() self.cut_plot._apply_offset.assert_called_with(0, 0) self.cut_plot.update_bragg_peaks.assert_called_with(refresh=True) + + def test_all_fonts_size(self): + self.cut_plot.all_fonts_size = 14 + self.assertEqual(self.cut_plot.title_size, 14) + self.assertEqual(self.cut_plot.x_range_font_size, 14) + self.assertEqual(self.cut_plot.y_range_font_size, 14) + self.assertEqual(self.cut_plot.x_label_size, 14) + self.assertEqual(self.cut_plot.y_label_size, 14) + + def test_scale_all_fonts(self): + self.cut_plot.all_fonts_size = 12 + self.cut_plot.scale_all_fonts = 3 + self.assertEqual(self.cut_plot.title_size, 15) + self.assertEqual(self.cut_plot.x_range_font_size, 15) + self.assertEqual(self.cut_plot.y_range_font_size, 15) + self.assertEqual(self.cut_plot.x_label_size, 15) + self.assertEqual(self.cut_plot.y_label_size, 15) diff --git a/tests/plot_options_presenter_test.py b/tests/plot_options_presenter_test.py index 2b86b161..845f6dcc 100644 --- a/tests/plot_options_presenter_test.py +++ b/tests/plot_options_presenter_test.py @@ -216,3 +216,65 @@ def test_remove_line(self): # check line with correct index removed self.presenter.remove_container(9) self.model.remove_line_by_index.assert_called_once_with(9) + + def test_all_fonts_size(self): + model_all_fonts_size = PropertyMock() + view_all_fonts_size = PropertyMock() + type(self.model).all_fonts_size = model_all_fonts_size + type(self.view).all_fonts_size = view_all_fonts_size + + # model -> view + model_all_fonts_size.return_value = 12 + self.presenter = CutPlotOptionsPresenter(self.view, self.model) + model_all_fonts_size.assert_called_once_with() + view_all_fonts_size.assert_called_once_with(12) + + model_all_fonts_size.reset_mock() + view_all_fonts_size.reset_mock() + + # view -> model + view_all_fonts_size.return_value = 20 + self.presenter._value_modified('all_fonts_size') + self.presenter.get_new_config() + view_all_fonts_size.assert_called_once_with() + model_all_fonts_size.assert_called_once_with(20) + + model_all_fonts_size.reset_mock() + view_all_fonts_size.reset_mock() + + self.presenter._remove_value_modified('all_fonts_size') + self.presenter.get_new_config() + view_all_fonts_size.assert_not_called() + model_all_fonts_size.assert_not_called() + + def test_scale_all_fonts(self): + model_scale_all_fonts = PropertyMock() + view_scale_all_fonts = PropertyMock() + type(self.model).scale_all_fonts = model_scale_all_fonts + type(self.view).scale_all_fonts = view_scale_all_fonts + + # model -> view + model_scale_all_fonts.return_value = 12 + self.presenter = CutPlotOptionsPresenter(self.view, self.model) + model_scale_all_fonts.assert_called_once_with() + view_scale_all_fonts.assert_called_once_with(12) + + model_scale_all_fonts.reset_mock() + view_scale_all_fonts.reset_mock() + + # view -> model + view_scale_all_fonts.return_value = 20 + self.presenter._value_modified('scale_all_fonts') + self.presenter.get_new_config() + view_scale_all_fonts.assert_called_once_with() + model_scale_all_fonts.assert_called_once_with(20) + + model_scale_all_fonts.reset_mock() + view_scale_all_fonts.reset_mock() + + self.presenter._remove_value_modified('scale_all_fonts') + self.presenter.get_new_config() + view_scale_all_fonts.assert_not_called() + model_scale_all_fonts.assert_not_called() + + diff --git a/tests/slice_plot_test.py b/tests/slice_plot_test.py index a78eec6c..60cc5c8b 100644 --- a/tests/slice_plot_test.py +++ b/tests/slice_plot_test.py @@ -117,6 +117,41 @@ def test_update_legend_in_slice_plot(self): self.slice_plot.update_legend() mock_add_legend.assert_called_with(self.line, ['some_label'], fontsize=ANY, loc='upper right') + def test_all_fonts_size(self): + slice_plot_colorbar_label_size = PropertyMock() + slice_plot_colorbar_range_font_size = PropertyMock() + type(self.slice_plot).colorbar_label_size = slice_plot_colorbar_label_size + type(self.slice_plot).colorbar_range_font_size = slice_plot_colorbar_range_font_size + + self.slice_plot.all_fonts_size = 14 + + slice_plot_colorbar_range_font_size.assert_called_once_with(14) + slice_plot_colorbar_label_size.assert_called_once_with(14) + + self.assertEqual(self.slice_plot.title_size, 14) + self.assertEqual(self.slice_plot.x_range_font_size, 14) + self.assertEqual(self.slice_plot.y_range_font_size, 14) + self.assertEqual(self.slice_plot.x_label_size, 14) + self.assertEqual(self.slice_plot.y_label_size, 14) + + def test_scale_all_fonts(self): + slice_plot_colorbar_label_size = PropertyMock(return_value=12) + slice_plot_colorbar_range_font_size = PropertyMock(return_value=12) + type(self.slice_plot).colorbar_label_size = slice_plot_colorbar_label_size + type(self.slice_plot).colorbar_range_font_size = slice_plot_colorbar_range_font_size + + self.slice_plot.all_fonts_size = 12 + self.slice_plot.scale_all_fonts = 3 + + slice_plot_colorbar_range_font_size.assert_called_with(15) + slice_plot_colorbar_label_size.assert_called_with(15) + + self.assertEqual(self.slice_plot.title_size, 15) + self.assertEqual(self.slice_plot.x_range_font_size, 15) + self.assertEqual(self.slice_plot.y_range_font_size, 15) + self.assertEqual(self.slice_plot.x_label_size, 15) + self.assertEqual(self.slice_plot.y_label_size, 15) + if __name__ == '__main__': unittest.main() From e8c957e1443f4f2fab7022ef22c724124ad1f461 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Oct 2023 14:48:20 +0000 Subject: [PATCH 14/33] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/mslice/plotting/plot_window/cut_plot.py | 2 +- src/mslice/plotting/plot_window/slice_plot.py | 2 +- tests/plot_options_presenter_test.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index bd760932..84bfbe26 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -843,7 +843,7 @@ def all_fonts_size(self, value): self.x_label_size = value self.y_label_size = value - @property + @property def scale_all_fonts(self): return DEFAULT_SCALE_FONT_SIZE diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index d01c2acb..de1c120c 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -641,7 +641,7 @@ def all_fonts_size(self, value): self.colorbar_label_size = value self.colorbar_range_font_size = value - @property + @property def scale_all_fonts(self): return DEFAULT_SCALE_FONT_SIZE diff --git a/tests/plot_options_presenter_test.py b/tests/plot_options_presenter_test.py index 845f6dcc..61f1c926 100644 --- a/tests/plot_options_presenter_test.py +++ b/tests/plot_options_presenter_test.py @@ -276,5 +276,5 @@ def test_scale_all_fonts(self): self.presenter.get_new_config() view_scale_all_fonts.assert_not_called() model_scale_all_fonts.assert_not_called() - + From eac23b302a893daef087afeb458f83ae2b355ad7 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Mon, 9 Oct 2023 15:52:58 +0100 Subject: [PATCH 15/33] Removed trailing white space --- tests/plot_options_presenter_test.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/plot_options_presenter_test.py b/tests/plot_options_presenter_test.py index 61f1c926..a9609275 100644 --- a/tests/plot_options_presenter_test.py +++ b/tests/plot_options_presenter_test.py @@ -185,7 +185,7 @@ def test_change_xy_log(self): self.presenter._xy_config_modified('y_log') self.presenter.get_new_config() self.model.change_axis_scale.assert_called_once_with({'x_range': (1, 2), 'y_range': (3, 4), 'modified': True, - 'x_log': False, 'y_log': True}) + 'x_log': False, 'y_log': True}) def test_line_options(self): # model -> view @@ -276,5 +276,3 @@ def test_scale_all_fonts(self): self.presenter.get_new_config() view_scale_all_fonts.assert_not_called() model_scale_all_fonts.assert_not_called() - - From f79c27f70f922f835a1b4f7eaddbc12c576810d8 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Mon, 16 Oct 2023 12:11:48 +0100 Subject: [PATCH 16/33] Handled exceptions for very big or small font sizes. --- src/mslice/plotting/plot_window/plot_options.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index a2e2d7b9..2d996fa1 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -39,6 +39,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) + self.all_fonts_size_validator = LineEditDoubleValidator(self.allFntSz, 0.0) + self.allFntSz.setValidator(self.all_fonts_size_validator) + self.sclAllFntSz.setRange(-20, 20) self.lneFigureTitle.editingFinished.connect(self.titleEdited) self.lneXAxisLabel.editingFinished.connect(self.xLabelEdited) @@ -190,7 +193,15 @@ def all_fonts_size(self): try: size = float(str(self.allFntSz.text())) except ValueError: - return None + size = 10 + + if size > 1000: + size = 1000 + + elif size < 1: + size = 1 + + self.all_fonts_size = size return size @all_fonts_size.setter From b8ddf888ef9640926bdde83745ce585926725dd0 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Mon, 16 Oct 2023 12:32:13 +0100 Subject: [PATCH 17/33] Changed naming from 'scale' to 'increment' Changed GUI description + all variable names with new nomenclature --- src/mslice/plotting/plot_window/cut_plot.py | 6 ++-- .../plotting/plot_window/plot_options.py | 36 +++++++++---------- .../plotting/plot_window/plot_options.ui | 6 ++-- src/mslice/plotting/plot_window/slice_plot.py | 6 ++-- .../presenters/plot_options_presenter.py | 8 ++--- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index 84bfbe26..34f46b11 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -844,11 +844,11 @@ def all_fonts_size(self, value): self.y_label_size = value @property - def scale_all_fonts(self): + def increment_all_fonts(self): return DEFAULT_SCALE_FONT_SIZE - @scale_all_fonts.setter - def scale_all_fonts(self, value): + @increment_all_fonts.setter + def increment_all_fonts(self, value): self.title_size += value self.x_range_font_size += value self.y_range_font_size += value diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index 2d996fa1..17d01a0c 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -24,8 +24,8 @@ class PlotOptionsDialog(QtWidgets.QDialog): allFontSizeIncluded = Signal() allFontSizeRemoved = Signal() - scaleAllFontsIncluded = Signal() - scaleAllFontsRemoved = Signal() + incrAllFontsIncluded = Signal() + incrAllFontsRemoved = Signal() def __init__(self, parent, redraw_signal=None): QtWidgets.QDialog.__init__(self, parent) @@ -41,7 +41,7 @@ def __init__(self, parent, redraw_signal=None): self.lneYMax.setValidator(self.y_max_validator) self.all_fonts_size_validator = LineEditDoubleValidator(self.allFntSz, 0.0) self.allFntSz.setValidator(self.all_fonts_size_validator) - self.sclAllFntSz.setRange(-20, 20) + self.incrAllFntSz.setRange(-20, 20) self.lneFigureTitle.editingFinished.connect(self.titleEdited) self.lneXAxisLabel.editingFinished.connect(self.xLabelEdited) @@ -57,12 +57,12 @@ def __init__(self, parent, redraw_signal=None): self.chkAllFntSz.setCheckState(False) self.chkAllFntSz.stateChanged.connect(self._all_fonts_size_state_changed) - self.chkSclAllFntSz.setCheckState(False) - self.chkSclAllFntSz.stateChanged.connect(self._scale_all_fonts_state_changed) + self.chkIncrAllFntSz.setCheckState(False) + self.chkIncrAllFntSz.stateChanged.connect(self._increment_all_fonts_state_changed) self.allFntSz.setEnabled(False) self.allFntSz.editingFinished.connect(self.allFontSizeIncluded) - self.sclAllFntSz.setEnabled(False) - self.sclAllFntSz.editingFinished.connect(self.scaleAllFontsIncluded) + self.incrAllFntSz.setEnabled(False) + self.incrAllFntSz.editingFinished.connect(self.incrAllFontsIncluded) self.redraw_signal = redraw_signal @@ -78,15 +78,15 @@ def _all_fonts_size_state_changed(self): txt_box=self.allFntSz, include_signal=self.allFontSizeIncluded, remove_signal=self.allFontSizeRemoved, - other_chk_box=self.chkSclAllFntSz + other_chk_box=self.chkIncrAllFntSz ) - def _scale_all_fonts_state_changed(self): + def _increment_all_fonts_state_changed(self): self._chk_box_state_changed( - chk_box=self.chkSclAllFntSz, - txt_box=self.sclAllFntSz, - include_signal=self.scaleAllFontsIncluded, - remove_signal=self.scaleAllFontsRemoved, + chk_box=self.chkIncrAllFntSz, + txt_box=self.incrAllFntSz, + include_signal=self.incrAllFontsIncluded, + remove_signal=self.incrAllFontsRemoved, other_chk_box=self.chkAllFntSz ) @@ -209,16 +209,16 @@ def all_fonts_size(self, value): self.allFntSz.setText(str(value)) @property - def scale_all_fonts(self): + def increment_all_fonts(self): try: - scl_factor = float(self.sclAllFntSz.value()) + scl_factor = float(self.incrAllFntSz.value()) except ValueError: return None return scl_factor - @scale_all_fonts.setter - def scale_all_fonts(self, value): - self.sclAllFntSz.setValue(value) + @increment_all_fonts.setter + def increment_all_fonts(self, value): + self.incrAllFntSz.setValue(value) class SlicePlotOptions(PlotOptionsDialog): diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index 9f27d32a..883ecc29 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -255,14 +255,14 @@ - + - Scale all fonts + Increment all fonts size - + 50 diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index de1c120c..880b2905 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -642,11 +642,11 @@ def all_fonts_size(self, value): self.colorbar_range_font_size = value @property - def scale_all_fonts(self): + def increment_all_fonts(self): return DEFAULT_SCALE_FONT_SIZE - @scale_all_fonts.setter - def scale_all_fonts(self, value): + @increment_all_fonts.setter + def increment_all_fonts(self, value): self.title_size += value self.x_range_font_size += value self.y_range_font_size += value diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 6990a5ec..f7d48113 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -21,8 +21,8 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.yGridEdited.connect(partial(self._value_modified, 'y_grid')) self._view.allFontSizeIncluded.connect(partial(self._value_modified, 'all_fonts_size')) self._view.allFontSizeRemoved.connect(partial(self._remove_value_modified, 'all_fonts_size')) - self._view.scaleAllFontsIncluded.connect(partial(self._value_modified, 'scale_all_fonts')) - self._view.scaleAllFontsRemoved.connect(partial(self._remove_value_modified, 'scale_all_fonts')) + self._view.incrAllFontsIncluded.connect(partial(self._value_modified, 'increment_all_fonts')) + self._view.incrAllFontsRemoved.connect(partial(self._remove_value_modified, 'increment_all_fonts')) def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) @@ -49,7 +49,7 @@ def __init__(self, plot_options_dialog, slice_handler): def set_properties(self): properties = ['title', 'x_label', 'y_label', 'x_range', 'y_range', 'x_grid', 'y_grid', - 'colorbar_range', 'colorbar_log', 'all_fonts_size', 'scale_all_fonts'] + 'colorbar_range', 'colorbar_log', 'all_fonts_size', 'increment_all_fonts'] for p in properties: setattr(self._view, p, getattr(self._model, p)) @@ -89,7 +89,7 @@ def __init__(self, plot_options_dialog, cut_handler): def set_properties(self): properties = ['title', 'x_label', 'y_label', 'x_range', 'y_range', 'x_log', 'y_log', - 'x_grid', 'y_grid', 'show_legends', 'all_fonts_size', 'scale_all_fonts'] + 'x_grid', 'y_grid', 'show_legends', 'all_fonts_size', 'increment_all_fonts'] for p in properties: setattr(self._view, p, getattr(self._model, p)) From 2f96b9ba5f33e38e43adcccd3908aa120b21869a Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Mon, 16 Oct 2023 13:37:21 +0100 Subject: [PATCH 18/33] Renamed variables in tests --- tests/cut_plot_test.py | 4 +-- tests/plot_options_presenter_test.py | 38 ++++++++++++++-------------- tests/slice_plot_test.py | 4 +-- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/cut_plot_test.py b/tests/cut_plot_test.py index 7bba200c..a9e85fbb 100644 --- a/tests/cut_plot_test.py +++ b/tests/cut_plot_test.py @@ -113,9 +113,9 @@ def test_all_fonts_size(self): self.assertEqual(self.cut_plot.x_label_size, 14) self.assertEqual(self.cut_plot.y_label_size, 14) - def test_scale_all_fonts(self): + def test_increment_all_fonts(self): self.cut_plot.all_fonts_size = 12 - self.cut_plot.scale_all_fonts = 3 + self.cut_plot.increment_all_fonts = 3 self.assertEqual(self.cut_plot.title_size, 15) self.assertEqual(self.cut_plot.x_range_font_size, 15) self.assertEqual(self.cut_plot.y_range_font_size, 15) diff --git a/tests/plot_options_presenter_test.py b/tests/plot_options_presenter_test.py index a9609275..7f1abb90 100644 --- a/tests/plot_options_presenter_test.py +++ b/tests/plot_options_presenter_test.py @@ -247,32 +247,32 @@ def test_all_fonts_size(self): view_all_fonts_size.assert_not_called() model_all_fonts_size.assert_not_called() - def test_scale_all_fonts(self): - model_scale_all_fonts = PropertyMock() - view_scale_all_fonts = PropertyMock() - type(self.model).scale_all_fonts = model_scale_all_fonts - type(self.view).scale_all_fonts = view_scale_all_fonts + def test_increment_all_fonts(self): + model_increment_all_fonts = PropertyMock() + view_increment_all_fonts = PropertyMock() + type(self.model).increment_all_fonts = model_increment_all_fonts + type(self.view).increment_all_fonts = view_increment_all_fonts # model -> view - model_scale_all_fonts.return_value = 12 + model_increment_all_fonts.return_value = 12 self.presenter = CutPlotOptionsPresenter(self.view, self.model) - model_scale_all_fonts.assert_called_once_with() - view_scale_all_fonts.assert_called_once_with(12) + model_increment_all_fonts.assert_called_once_with() + view_increment_all_fonts.assert_called_once_with(12) - model_scale_all_fonts.reset_mock() - view_scale_all_fonts.reset_mock() + model_increment_all_fonts.reset_mock() + view_increment_all_fonts.reset_mock() # view -> model - view_scale_all_fonts.return_value = 20 - self.presenter._value_modified('scale_all_fonts') + view_increment_all_fonts.return_value = 20 + self.presenter._value_modified('increment_all_fonts') self.presenter.get_new_config() - view_scale_all_fonts.assert_called_once_with() - model_scale_all_fonts.assert_called_once_with(20) + view_increment_all_fonts.assert_called_once_with() + model_increment_all_fonts.assert_called_once_with(20) - model_scale_all_fonts.reset_mock() - view_scale_all_fonts.reset_mock() + model_increment_all_fonts.reset_mock() + view_increment_all_fonts.reset_mock() - self.presenter._remove_value_modified('scale_all_fonts') + self.presenter._remove_value_modified('increment_all_fonts') self.presenter.get_new_config() - view_scale_all_fonts.assert_not_called() - model_scale_all_fonts.assert_not_called() + view_increment_all_fonts.assert_not_called() + model_increment_all_fonts.assert_not_called() diff --git a/tests/slice_plot_test.py b/tests/slice_plot_test.py index 60cc5c8b..ca61162c 100644 --- a/tests/slice_plot_test.py +++ b/tests/slice_plot_test.py @@ -134,14 +134,14 @@ def test_all_fonts_size(self): self.assertEqual(self.slice_plot.x_label_size, 14) self.assertEqual(self.slice_plot.y_label_size, 14) - def test_scale_all_fonts(self): + def test_increment_all_fonts(self): slice_plot_colorbar_label_size = PropertyMock(return_value=12) slice_plot_colorbar_range_font_size = PropertyMock(return_value=12) type(self.slice_plot).colorbar_label_size = slice_plot_colorbar_label_size type(self.slice_plot).colorbar_range_font_size = slice_plot_colorbar_range_font_size self.slice_plot.all_fonts_size = 12 - self.slice_plot.scale_all_fonts = 3 + self.slice_plot.increment_all_fonts = 3 slice_plot_colorbar_range_font_size.assert_called_with(15) slice_plot_colorbar_label_size.assert_called_with(15) From 82b006e41a81a3c37d027e4ece013e10f32ef710 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Thu, 26 Oct 2023 16:14:24 +0100 Subject: [PATCH 19/33] Basic case of real-time updating of plot font sizes --- src/mslice/plotting/plot_window/plot_options.py | 17 ++++++++++++++--- src/mslice/presenters/plot_options_presenter.py | 7 +++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index 17d01a0c..9f5f62cd 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -7,7 +7,8 @@ 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 QDoubleValidator, QRegExpValidator +from qtpy.QtCore import QRegExp from mantidqt.utils.qt.line_edit_double_validator import LineEditDoubleValidator @@ -27,6 +28,8 @@ class PlotOptionsDialog(QtWidgets.QDialog): incrAllFontsIncluded = Signal() incrAllFontsRemoved = Signal() + setAllPlotFonts = Signal() + def __init__(self, parent, redraw_signal=None): QtWidgets.QDialog.__init__(self, parent) load_ui(__file__, 'plot_options.ui', self) @@ -39,10 +42,12 @@ 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) - self.all_fonts_size_validator = LineEditDoubleValidator(self.allFntSz, 0.0) + two_positive_ints_validator = r"^\s*[1-9]?[0-9]?$" + self.all_fonts_size_validator = QRegExpValidator(QRegExp(two_positive_ints_validator)) self.allFntSz.setValidator(self.all_fonts_size_validator) self.incrAllFntSz.setRange(-20, 20) + self.lneFigureTitle.editingFinished.connect(self.titleEdited) self.lneXAxisLabel.editingFinished.connect(self.xLabelEdited) self.lneYAxisLabel.editingFinished.connect(self.yLabelEdited) @@ -64,8 +69,14 @@ def __init__(self, parent, redraw_signal=None): self.incrAllFntSz.setEnabled(False) self.incrAllFntSz.editingFinished.connect(self.incrAllFontsIncluded) + self.allFntSz.textEdited.connect(self._font_sizes_changed) + self.redraw_signal = redraw_signal + def _font_sizes_changed(self): + self.setAllPlotFonts.emit() + self.redraw_signal.emit() + def _ok_clicked(self): self.ok_clicked.emit() self.redraw_signal.emit() @@ -201,7 +212,7 @@ def all_fonts_size(self): elif size < 1: size = 1 - self.all_fonts_size = size + # self.all_fonts_size = size return size @all_fonts_size.setter diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index f7d48113..12825409 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -24,6 +24,12 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.incrAllFontsIncluded.connect(partial(self._value_modified, 'increment_all_fonts')) self._view.incrAllFontsRemoved.connect(partial(self._remove_value_modified, 'increment_all_fonts')) + self._view.setAllPlotFonts.connect(self._set_all_plot_fonts) + + def _set_all_plot_fonts(self): + p = 'all_fonts_size' + setattr(self._model, p, getattr(self._view, p)) + def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) @@ -45,6 +51,7 @@ def __init__(self, plot_options_dialog, slice_handler): self._view.cLogEdited.connect(self._set_colorbar_log) self._view.cRangeEdited.connect(self._set_c_range) self._view.ok_clicked.connect(self.get_new_config) + self._view.show() def set_properties(self): From 5520b5422468be467e3426e1edc60517650c9a33 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Fri, 27 Oct 2023 12:21:00 +0100 Subject: [PATCH 20/33] Removed previous solution and implemented basic real-time font setting Removed checkboxes and increment box. Only the box for setting all fonts remains. Changing the value in this box updates the plot in real time. Leaving box empty reverts any change. --- .../plotting/plot_window/plot_options.py | 86 ++----------------- .../plotting/plot_window/plot_options.ui | 19 +--- src/mslice/plotting/plot_window/slice_plot.py | 20 +++-- .../presenters/plot_options_presenter.py | 23 +++-- 4 files changed, 29 insertions(+), 119 deletions(-) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index 9f5f62cd..305cfaf4 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -21,15 +21,9 @@ class PlotOptionsDialog(QtWidgets.QDialog): yRangeEdited = Signal() xGridEdited = Signal() yGridEdited = Signal() + allFontSizeEdited = Signal() ok_clicked = Signal() - allFontSizeIncluded = Signal() - allFontSizeRemoved = Signal() - incrAllFontsIncluded = Signal() - incrAllFontsRemoved = Signal() - - setAllPlotFonts = Signal() - def __init__(self, parent, redraw_signal=None): QtWidgets.QDialog.__init__(self, parent) load_ui(__file__, 'plot_options.ui', self) @@ -42,11 +36,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_positive_ints_validator = r"^\s*[1-9]?[0-9]?$" - self.all_fonts_size_validator = QRegExpValidator(QRegExp(two_positive_ints_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.incrAllFntSz.setRange(-20, 20) - self.lneFigureTitle.editingFinished.connect(self.titleEdited) self.lneXAxisLabel.editingFinished.connect(self.xLabelEdited) @@ -60,21 +52,12 @@ def __init__(self, parent, redraw_signal=None): self.chkXGrid.stateChanged.connect(self.xGridEdited) self.chkYGrid.stateChanged.connect(self.yGridEdited) - self.chkAllFntSz.setCheckState(False) - self.chkAllFntSz.stateChanged.connect(self._all_fonts_size_state_changed) - self.chkIncrAllFntSz.setCheckState(False) - self.chkIncrAllFntSz.stateChanged.connect(self._increment_all_fonts_state_changed) - self.allFntSz.setEnabled(False) - self.allFntSz.editingFinished.connect(self.allFontSizeIncluded) - self.incrAllFntSz.setEnabled(False) - self.incrAllFntSz.editingFinished.connect(self.incrAllFontsIncluded) - self.allFntSz.textEdited.connect(self._font_sizes_changed) self.redraw_signal = redraw_signal def _font_sizes_changed(self): - self.setAllPlotFonts.emit() + self.allFontSizeEdited.emit() self.redraw_signal.emit() def _ok_clicked(self): @@ -83,42 +66,6 @@ def _ok_clicked(self): if not self.is_kept_open: self.accept() - def _all_fonts_size_state_changed(self): - self._chk_box_state_changed( - chk_box=self.chkAllFntSz, - txt_box=self.allFntSz, - include_signal=self.allFontSizeIncluded, - remove_signal=self.allFontSizeRemoved, - other_chk_box=self.chkIncrAllFntSz - ) - - def _increment_all_fonts_state_changed(self): - self._chk_box_state_changed( - chk_box=self.chkIncrAllFntSz, - txt_box=self.incrAllFntSz, - include_signal=self.incrAllFontsIncluded, - remove_signal=self.incrAllFontsRemoved, - other_chk_box=self.chkAllFntSz - ) - - def _chk_box_state_changed(self, chk_box, txt_box, include_signal, remove_signal, other_chk_box): - self._set_txt_to_match_chk(txt_box, chk_box) - self._choose_signal_to_emit(chk_box, include_signal, remove_signal) - self._uncheck_other_chk_box(chk_box, other_chk_box) - - def _set_txt_to_match_chk(self, txt_box, chk_box): - txt_box.setEnabled(chk_box.isChecked()) - - def _choose_signal_to_emit(self, chk_box, include_signal, remove_signal): - if chk_box.isChecked(): - include_signal.emit() - else: - remove_signal.emit() - - def _uncheck_other_chk_box(self, chk_box_current, chk_box_other): - if chk_box_current.isChecked(): - chk_box_other.setCheckState(False) - @property def x_range(self): try: @@ -202,35 +149,14 @@ def is_kept_open(self): @property def all_fonts_size(self): try: - size = float(str(self.allFntSz.text())) + return float(str(self.allFntSz.text())) except ValueError: - size = 10 - - if size > 1000: - size = 1000 - - elif size < 1: - size = 1 - - # self.all_fonts_size = size - return size + return None @all_fonts_size.setter def all_fonts_size(self, value): self.allFntSz.setText(str(value)) - @property - def increment_all_fonts(self): - try: - scl_factor = float(self.incrAllFntSz.value()) - except ValueError: - return None - return scl_factor - - @increment_all_fonts.setter - def increment_all_fonts(self, value): - self.incrAllFntSz.setValue(value) - class SlicePlotOptions(PlotOptionsDialog): diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index 883ecc29..d16a549c 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -244,7 +244,7 @@ - + @@ -254,23 +254,6 @@ - - - - Increment all fonts size - - - - - - - 50 - - - -50 - - - diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index 880b2905..0626344b 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -629,17 +629,19 @@ def set_cross_cursor(self): @property def all_fonts_size(self): - return DEFAULT_LABEL_SIZE + font_sizes_config = {} + properties_fonts = ['title_size', 'x_range_font_size', 'y_range_font_size', + 'x_label_size', 'y_label_size', 'colorbar_label_size', + 'colorbar_range_font_size'] + for p in properties_fonts: + font_sizes_config[p] = getattr(self, p) + + return font_sizes_config @all_fonts_size.setter - def all_fonts_size(self, value): - self.title_size = value - self.x_range_font_size = value - self.y_range_font_size = value - self.x_label_size = value - self.y_label_size = value - self.colorbar_label_size = value - self.colorbar_range_font_size = value + def all_fonts_size(self, values: dict): + for key in values: + setattr(self, key, values[key]) @property def increment_all_fonts(self): diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 12825409..50f45bdc 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -9,6 +9,7 @@ def __init__(self, plot_options_dialog, plot_handler): self._view = plot_options_dialog self._modified_values = {} self._xy_config = {'x_range': self._model.x_range, 'y_range': self._model.y_range, 'modified': False} + self._font_sizes_config = self._model.all_fonts_size self.set_properties() # propagate dialog with existing data @@ -19,16 +20,17 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.yRangeEdited.connect(partial(self._xy_config_modified, 'y_range')) self._view.xGridEdited.connect(partial(self._value_modified, 'x_grid')) self._view.yGridEdited.connect(partial(self._value_modified, 'y_grid')) - self._view.allFontSizeIncluded.connect(partial(self._value_modified, 'all_fonts_size')) - self._view.allFontSizeRemoved.connect(partial(self._remove_value_modified, 'all_fonts_size')) - self._view.incrAllFontsIncluded.connect(partial(self._value_modified, 'increment_all_fonts')) - self._view.incrAllFontsRemoved.connect(partial(self._remove_value_modified, 'increment_all_fonts')) - - self._view.setAllPlotFonts.connect(self._set_all_plot_fonts) + self._view.allFontSizeEdited.connect(self._set_all_plot_fonts) def _set_all_plot_fonts(self): - p = 'all_fonts_size' - setattr(self._model, p, getattr(self._view, p)) + font_size_view = self._view.all_fonts_size + new_config_dict = self._font_sizes_config.copy() + + if font_size_view is not None: + for key in new_config_dict: + new_config_dict[key] = font_size_view + + self._model.all_fonts_size = new_config_dict def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) @@ -37,9 +39,6 @@ def _xy_config_modified(self, key): getattr(self, '_xy_config')[key] = getattr(self._view, key) self._xy_config['modified'] = True - def _remove_value_modified(self, value_name): - del self._modified_values[value_name] - class SlicePlotOptionsPresenter(PlotOptionsPresenter): @@ -56,7 +55,7 @@ def __init__(self, plot_options_dialog, slice_handler): def set_properties(self): properties = ['title', 'x_label', 'y_label', 'x_range', 'y_range', 'x_grid', 'y_grid', - 'colorbar_range', 'colorbar_log', 'all_fonts_size', 'increment_all_fonts'] + 'colorbar_range', 'colorbar_log'] for p in properties: setattr(self._view, p, getattr(self._model, p)) From 738df42dfe63944350a82c16e6948f49e5db3b8e Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Fri, 27 Oct 2023 14:05:09 +0100 Subject: [PATCH 21/33] Renamed label in ui --- src/mslice/plotting/plot_window/plot_options.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index d16a549c..b80bb3cf 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -238,13 +238,13 @@ - + Set all fonts size - + From ae8a95522e12ffd7a47ea69419740ae4ac087d4a Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Fri, 27 Oct 2023 15:31:14 +0100 Subject: [PATCH 22/33] Included Scale Up and Down buttons All of the functunality present. Scaling up and down butttons seem to be working. The ui needs changing, currently it's ugly. --- .../plotting/plot_window/plot_options.py | 16 +++++++++ .../plotting/plot_window/plot_options.ui | 20 +++++++++++ src/mslice/plotting/plot_window/slice_plot.py | 34 +++++++++---------- .../presenters/plot_options_presenter.py | 2 ++ 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index 305cfaf4..f2628c2d 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -10,6 +10,7 @@ from qtpy.QtGui import QDoubleValidator, 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): @@ -22,12 +23,17 @@ class PlotOptionsDialog(QtWidgets.QDialog): xGridEdited = Signal() yGridEdited = Signal() allFontSizeEdited = Signal() + fontSizeUpClicked = Signal() + fontSizeDownClicked = 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) @@ -53,6 +59,8 @@ def __init__(self, parent, redraw_signal=None): 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 @@ -60,6 +68,14 @@ def _font_sizes_changed(self): 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() diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index b80bb3cf..45ec0870 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -254,6 +254,26 @@ + + + + + 16777215 + 16777215 + + + + + + + + + 16777215 + 16777215 + + + + diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index 0626344b..429e1e8c 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -55,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 = { @@ -630,10 +639,7 @@ def set_cross_cursor(self): @property def all_fonts_size(self): font_sizes_config = {} - properties_fonts = ['title_size', 'x_range_font_size', 'y_range_font_size', - 'x_label_size', 'y_label_size', 'colorbar_label_size', - 'colorbar_range_font_size'] - for p in properties_fonts: + for p in self.plot_fonts_properties: font_sizes_config[p] = getattr(self, p) return font_sizes_config @@ -643,16 +649,10 @@ def all_fonts_size(self, values: dict): for key in values: setattr(self, key, values[key]) - @property - def increment_all_fonts(self): - return DEFAULT_SCALE_FONT_SIZE - - @increment_all_fonts.setter - def increment_all_fonts(self, value): - self.title_size += value - self.x_range_font_size += value - self.y_range_font_size += value - self.x_label_size += value - self.y_label_size += value - self.colorbar_label_size += value - self.colorbar_range_font_size += value + def increase_all_fonts(self): + for p in self.plot_fonts_properties: + setattr(self, p, getattr(self, p) + 0.5) + + def decrease_all_fonts(self): + for p in self.plot_fonts_properties: + setattr(self, p, getattr(self, p) - 0.5) diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 50f45bdc..e2bff01c 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -21,6 +21,8 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.xGridEdited.connect(partial(self._value_modified, 'x_grid')) self._view.yGridEdited.connect(partial(self._value_modified, 'y_grid')) self._view.allFontSizeEdited.connect(self._set_all_plot_fonts) + self._view.fontSizeUpClicked.connect(self._model.increase_all_fonts) + self._view.fontSizeDownClicked.connect(self._model.decrease_all_fonts) def _set_all_plot_fonts(self): font_size_view = self._view.all_fonts_size From ad5b19ea941dd051d363838c50f5e0b0ea01fc1d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:33:14 +0000 Subject: [PATCH 23/33] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/mslice/plotting/plot_window/plot_options.py | 2 +- src/mslice/plotting/plot_window/slice_plot.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index f2628c2d..ed29f316 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -61,7 +61,7 @@ def __init__(self, parent, redraw_signal=None): 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 def _font_sizes_changed(self): diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index 429e1e8c..d5b0e599 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -58,10 +58,10 @@ def __init__(self, figure_manager, slice_plotter_presenter, workspace_name): self.plot_fonts_properties = [ 'title_size', 'x_range_font_size', - 'y_range_font_size', + 'y_range_font_size', 'x_label_size', 'y_label_size', - 'colorbar_label_size', + 'colorbar_label_size', 'colorbar_range_font_size' ] From ef62eab00f29231fde44f037006bcd3cfebdb69b Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Mon, 30 Oct 2023 11:52:36 +0000 Subject: [PATCH 24/33] Fixed scalue up and down UI buttons Improved appearance of buttons for scaling fonts --- src/mslice/plotting/plot_window/plot_options.ui | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/mslice/plotting/plot_window/plot_options.ui b/src/mslice/plotting/plot_window/plot_options.ui index 45ec0870..b26341a7 100644 --- a/src/mslice/plotting/plot_window/plot_options.ui +++ b/src/mslice/plotting/plot_window/plot_options.ui @@ -254,24 +254,12 @@ - + - - - 16777215 - 16777215 - - - + - - - 16777215 - 16777215 - - From e1020a0e7601cb32f944dc2ef1870fe5fbe23be3 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 31 Oct 2023 10:13:36 +0000 Subject: [PATCH 25/33] Completed functunality Added 'pre-view' functunality for setting all plot fonts. When user sets all fonts to a size, changes can be reverted by pressing backspace until line edit is empty again. --- src/mslice/plotting/plot_window/cut_plot.py | 41 +++++++++------- .../plotting/plot_window/plot_options.py | 7 +++ src/mslice/plotting/plot_window/slice_plot.py | 17 +++---- .../presenters/plot_options_presenter.py | 49 +++++++++++++------ 4 files changed, 72 insertions(+), 42 deletions(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index 34f46b11..72ba4cc6 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -29,7 +29,6 @@ DEFAULT_LABEL_SIZE = 10 DEFAULT_TITLE_SIZE = 12 -DEFAULT_SCALE_FONT_SIZE = 0 def get_min(data, absolute_minimum=-np.inf): @@ -66,6 +65,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 = { @@ -833,24 +839,21 @@ def intensity_type(self): @property def all_fonts_size(self): - return DEFAULT_LABEL_SIZE + 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, value): - self.title_size = value - self.x_range_font_size = value - self.y_range_font_size = value - self.x_label_size = value - self.y_label_size = value + def all_fonts_size(self, values: dict): + for key in values: + setattr(self, key, values[key]) - @property - def increment_all_fonts(self): - return DEFAULT_SCALE_FONT_SIZE - - @increment_all_fonts.setter - def increment_all_fonts(self, value): - self.title_size += value - self.x_range_font_size += value - self.y_range_font_size += value - self.x_label_size += value - self.y_label_size += value + def increase_all_fonts(self): + for p in self.plot_fonts_properties: + setattr(self, p, getattr(self, p) + 0.5) + + def decrease_all_fonts(self): + for p in self.plot_fonts_properties: + setattr(self, p, getattr(self, p) - 0.5) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index ed29f316..c0c9acf2 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -25,6 +25,7 @@ class PlotOptionsDialog(QtWidgets.QDialog): allFontSizeEdited = Signal() fontSizeUpClicked = Signal() fontSizeDownClicked = Signal() + allFontSizeFromEmptyToValue = Signal() ok_clicked = Signal() def __init__(self, parent, redraw_signal=None): @@ -64,7 +65,13 @@ def __init__(self, parent, redraw_signal=None): 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() diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index d5b0e599..8770e872 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -27,7 +27,6 @@ DEFAULT_LABEL_SIZE = 10 DEFAULT_TITLE_SIZE = 12 -DEFAULT_SCALE_FONT_SIZE = 0 class SlicePlot(IPlot): @@ -56,14 +55,14 @@ def __init__(self, figure_manager, slice_plotter_presenter, workspace_name): 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' - ] + '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 = { diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index e2bff01c..76bb07a7 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -9,7 +9,7 @@ def __init__(self, plot_options_dialog, plot_handler): self._view = plot_options_dialog self._modified_values = {} self._xy_config = {'x_range': self._model.x_range, 'y_range': self._model.y_range, 'modified': False} - self._font_sizes_config = self._model.all_fonts_size + self._default_font_sizes_config = self._model.all_fonts_size.copy() self.set_properties() # propagate dialog with existing data @@ -20,19 +20,11 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.yRangeEdited.connect(partial(self._xy_config_modified, 'y_range')) self._view.xGridEdited.connect(partial(self._value_modified, 'x_grid')) self._view.yGridEdited.connect(partial(self._value_modified, 'y_grid')) + self._view.allFontSizeFromEmptyToValue.connect(self._update_font_sizes_buffer) self._view.allFontSizeEdited.connect(self._set_all_plot_fonts) - self._view.fontSizeUpClicked.connect(self._model.increase_all_fonts) - self._view.fontSizeDownClicked.connect(self._model.decrease_all_fonts) - - def _set_all_plot_fonts(self): - font_size_view = self._view.all_fonts_size - new_config_dict = self._font_sizes_config.copy() - - if font_size_view is not None: - for key in new_config_dict: - new_config_dict[key] = font_size_view - - self._model.all_fonts_size = new_config_dict + self._view.fontSizeUpClicked.connect(self._increase_all_fonts) + self._view.fontSizeDownClicked.connect(self._decrease_all_fonts) + self._set_font_sizes_tooltip() def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) @@ -41,6 +33,35 @@ def _xy_config_modified(self, key): getattr(self, '_xy_config')[key] = getattr(self._view, key) self._xy_config['modified'] = True + def _update_font_sizes_buffer(self): + self._default_font_sizes_config = self._model.all_fonts_size.copy() + + def _set_all_plot_fonts(self): + new_config_dict = self._default_font_sizes_config.copy() + + fonts_size = self._view.all_fonts_size + if fonts_size is not None: + new_config_dict = {key: fonts_size for key in new_config_dict} + + self._model.all_fonts_size = new_config_dict + self._set_font_sizes_tooltip() + + def _increase_all_fonts(self): + self._model.increase_all_fonts() + self._set_font_sizes_tooltip() + + def _decrease_all_fonts(self): + self._model.decrease_all_fonts() + self._set_font_sizes_tooltip() + + def _set_font_sizes_tooltip(self): + font_size_dict = self._model.all_fonts_size.copy() + tip = str(font_size_dict)[1:-1].replace(', ', '\n').replace('size', '') + tip = tip.replace('_', ' ').replace("'", '').replace('font', '') + self._view.allFntSz.setToolTip(tip) + self._view.sclUpFntSz.setToolTip(tip) + self._view.sclDownFntSz.setToolTip(tip) + class SlicePlotOptionsPresenter(PlotOptionsPresenter): @@ -97,7 +118,7 @@ def __init__(self, plot_options_dialog, cut_handler): def set_properties(self): properties = ['title', 'x_label', 'y_label', 'x_range', 'y_range', 'x_log', 'y_log', - 'x_grid', 'y_grid', 'show_legends', 'all_fonts_size', 'increment_all_fonts'] + 'x_grid', 'y_grid', 'show_legends'] for p in properties: setattr(self._view, p, getattr(self._model, p)) From fc38a962d8e5cc02da9c0be21ca7ba873b8066ec Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 31 Oct 2023 13:25:29 +0000 Subject: [PATCH 26/33] Modified unit tests according to latest changes --- tests/cut_plot_test.py | 30 ++++++++------ tests/plot_options_presenter_test.py | 61 ++++++++-------------------- tests/slice_plot_test.py | 54 +++++++++++++----------- 3 files changed, 64 insertions(+), 81 deletions(-) diff --git a/tests/cut_plot_test.py b/tests/cut_plot_test.py index a9e85fbb..ea7939c9 100644 --- a/tests/cut_plot_test.py +++ b/tests/cut_plot_test.py @@ -106,18 +106,24 @@ def test_waterfall(self): self.cut_plot.update_bragg_peaks.assert_called_with(refresh=True) def test_all_fonts_size(self): - self.cut_plot.all_fonts_size = 14 - self.assertEqual(self.cut_plot.title_size, 14) + fonts_config = {'title_size': 15, 'x_range_font_size': 14, 'y_range_font_size': 13, + 'x_label_size': 12, 'y_label_size': 11} + + self.cut_plot.all_fonts_size = fonts_config + self.assertEqual(self.cut_plot.title_size, 15) self.assertEqual(self.cut_plot.x_range_font_size, 14) - self.assertEqual(self.cut_plot.y_range_font_size, 14) - self.assertEqual(self.cut_plot.x_label_size, 14) - self.assertEqual(self.cut_plot.y_label_size, 14) + self.assertEqual(self.cut_plot.y_range_font_size, 13) + self.assertEqual(self.cut_plot.x_label_size, 12) + self.assertEqual(self.cut_plot.y_label_size, 11) def test_increment_all_fonts(self): - self.cut_plot.all_fonts_size = 12 - self.cut_plot.increment_all_fonts = 3 - self.assertEqual(self.cut_plot.title_size, 15) - self.assertEqual(self.cut_plot.x_range_font_size, 15) - self.assertEqual(self.cut_plot.y_range_font_size, 15) - self.assertEqual(self.cut_plot.x_label_size, 15) - self.assertEqual(self.cut_plot.y_label_size, 15) + fonts_config = {'title_size': 15, 'x_range_font_size': 14, 'y_range_font_size': 13, + 'x_label_size': 12, 'y_label_size': 11} + self.cut_plot.all_fonts_size = fonts_config + + self.cut_plot.increase_all_fonts() + self.assertEqual(self.cut_plot.title_size, 15.5) + self.assertEqual(self.cut_plot.x_range_font_size, 14.5) + self.assertEqual(self.cut_plot.y_range_font_size, 13.5) + self.assertEqual(self.cut_plot.x_label_size, 12.5) + self.assertEqual(self.cut_plot.y_label_size, 11.5) diff --git a/tests/plot_options_presenter_test.py b/tests/plot_options_presenter_test.py index 7f1abb90..3fd93791 100644 --- a/tests/plot_options_presenter_test.py +++ b/tests/plot_options_presenter_test.py @@ -217,62 +217,33 @@ def test_remove_line(self): self.presenter.remove_container(9) self.model.remove_line_by_index.assert_called_once_with(9) - def test_all_fonts_size(self): + def test_set_all_fonts_size(self): model_all_fonts_size = PropertyMock() view_all_fonts_size = PropertyMock() type(self.model).all_fonts_size = model_all_fonts_size type(self.view).all_fonts_size = view_all_fonts_size - # model -> view - model_all_fonts_size.return_value = 12 self.presenter = CutPlotOptionsPresenter(self.view, self.model) - model_all_fonts_size.assert_called_once_with() - view_all_fonts_size.assert_called_once_with(12) - - model_all_fonts_size.reset_mock() - view_all_fonts_size.reset_mock() + fonts_config = {'title_size': 15, 'x_range_font_size': 14, 'y_range_font_size': 13, + 'x_label_size': 12, 'y_label_size': 11} + self.presenter._default_font_sizes_config = fonts_config # view -> model view_all_fonts_size.return_value = 20 - self.presenter._value_modified('all_fonts_size') - self.presenter.get_new_config() - view_all_fonts_size.assert_called_once_with() - model_all_fonts_size.assert_called_once_with(20) + self.presenter._set_all_plot_fonts() - model_all_fonts_size.reset_mock() - view_all_fonts_size.reset_mock() - - self.presenter._remove_value_modified('all_fonts_size') - self.presenter.get_new_config() - view_all_fonts_size.assert_not_called() - model_all_fonts_size.assert_not_called() + view_all_fonts_size.assert_called_once_with() - def test_increment_all_fonts(self): - model_increment_all_fonts = PropertyMock() - view_increment_all_fonts = PropertyMock() - type(self.model).increment_all_fonts = model_increment_all_fonts - type(self.view).increment_all_fonts = view_increment_all_fonts + fonts_updated = {'title_size': 20, 'x_range_font_size': 20, 'y_range_font_size': 20, + 'x_label_size': 20, 'y_label_size': 20} + model_all_fonts_size.assert_any_call(fonts_updated) # Not latest call due to copy() methods - # model -> view - model_increment_all_fonts.return_value = 12 + def test_increase_all_fonts(self): self.presenter = CutPlotOptionsPresenter(self.view, self.model) - model_increment_all_fonts.assert_called_once_with() - view_increment_all_fonts.assert_called_once_with(12) + self.presenter._increase_all_fonts() + self.model.increase_all_fonts.assert_called_once_with() - model_increment_all_fonts.reset_mock() - view_increment_all_fonts.reset_mock() - - # view -> model - view_increment_all_fonts.return_value = 20 - self.presenter._value_modified('increment_all_fonts') - self.presenter.get_new_config() - view_increment_all_fonts.assert_called_once_with() - model_increment_all_fonts.assert_called_once_with(20) - - model_increment_all_fonts.reset_mock() - view_increment_all_fonts.reset_mock() - - self.presenter._remove_value_modified('increment_all_fonts') - self.presenter.get_new_config() - view_increment_all_fonts.assert_not_called() - model_increment_all_fonts.assert_not_called() + def test_decrease_all_fonts(self): + self.presenter = CutPlotOptionsPresenter(self.view, self.model) + self.presenter._decrease_all_fonts() + self.model.decrease_all_fonts.assert_called_once_with() diff --git a/tests/slice_plot_test.py b/tests/slice_plot_test.py index ca61162c..9f6f30a4 100644 --- a/tests/slice_plot_test.py +++ b/tests/slice_plot_test.py @@ -123,34 +123,40 @@ def test_all_fonts_size(self): type(self.slice_plot).colorbar_label_size = slice_plot_colorbar_label_size type(self.slice_plot).colorbar_range_font_size = slice_plot_colorbar_range_font_size - self.slice_plot.all_fonts_size = 14 + fonts_config = {'title_size': 15, 'x_range_font_size': 14, 'y_range_font_size': 13, + 'x_label_size': 12, 'y_label_size': 11, 'colorbar_label_size': 10, + 'colorbar_range_font_size': 9} - slice_plot_colorbar_range_font_size.assert_called_once_with(14) - slice_plot_colorbar_label_size.assert_called_once_with(14) + self.slice_plot.all_fonts_size = fonts_config - self.assertEqual(self.slice_plot.title_size, 14) - self.assertEqual(self.slice_plot.x_range_font_size, 14) - self.assertEqual(self.slice_plot.y_range_font_size, 14) - self.assertEqual(self.slice_plot.x_label_size, 14) - self.assertEqual(self.slice_plot.y_label_size, 14) - - def test_increment_all_fonts(self): - slice_plot_colorbar_label_size = PropertyMock(return_value=12) - slice_plot_colorbar_range_font_size = PropertyMock(return_value=12) - type(self.slice_plot).colorbar_label_size = slice_plot_colorbar_label_size - type(self.slice_plot).colorbar_range_font_size = slice_plot_colorbar_range_font_size - - self.slice_plot.all_fonts_size = 12 - self.slice_plot.increment_all_fonts = 3 - - slice_plot_colorbar_range_font_size.assert_called_with(15) - slice_plot_colorbar_label_size.assert_called_with(15) + slice_plot_colorbar_range_font_size.assert_called_once_with(9) + slice_plot_colorbar_label_size.assert_called_once_with(10) self.assertEqual(self.slice_plot.title_size, 15) - self.assertEqual(self.slice_plot.x_range_font_size, 15) - self.assertEqual(self.slice_plot.y_range_font_size, 15) - self.assertEqual(self.slice_plot.x_label_size, 15) - self.assertEqual(self.slice_plot.y_label_size, 15) + self.assertEqual(self.slice_plot.x_range_font_size, 14) + self.assertEqual(self.slice_plot.y_range_font_size, 13) + self.assertEqual(self.slice_plot.x_label_size, 12) + self.assertEqual(self.slice_plot.y_label_size, 11) + + def test_increase_all_fonts(self): + mock_colorbar_label_size = PropertyMock(return_value=9) + mock_colorbar_range_font_size = PropertyMock(return_value=10) + type(self.slice_plot).colorbar_label_size = mock_colorbar_label_size + type(self.slice_plot).colorbar_range_font_size = mock_colorbar_range_font_size + + fonts_config = {'title_size': 15, 'x_range_font_size': 14, 'y_range_font_size': 13, + 'x_label_size': 12, 'y_label_size': 11} + self.slice_plot.all_fonts_size = fonts_config + + self.slice_plot.increase_all_fonts() + + self.assertEqual(self.slice_plot.title_size, 15.5) + self.assertEqual(self.slice_plot.x_range_font_size, 14.5) + self.assertEqual(self.slice_plot.y_range_font_size, 13.5) + self.assertEqual(self.slice_plot.x_label_size, 12.5) + self.assertEqual(self.slice_plot.y_label_size, 11.5) + mock_colorbar_label_size.assert_called_with(9.5) + mock_colorbar_range_font_size.assert_called_with(10.5) if __name__ == '__main__': From 4479cdc36ea0c5ea741d782758869995d3cfcd50 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 31 Oct 2023 14:16:43 +0000 Subject: [PATCH 27/33] Fixed tooltip for font sizes Tooltip was not working for some fringe cases. Fixed it by tying the update of the tool tip to the redraw signal of the plot. --- .../presenters/plot_options_presenter.py | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 76bb07a7..e3cad86f 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -9,7 +9,7 @@ def __init__(self, plot_options_dialog, plot_handler): self._view = plot_options_dialog self._modified_values = {} self._xy_config = {'x_range': self._model.x_range, 'y_range': self._model.y_range, 'modified': False} - self._default_font_sizes_config = self._model.all_fonts_size.copy() + self._default_font_sizes_config = {} self.set_properties() # propagate dialog with existing data @@ -22,9 +22,9 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.yGridEdited.connect(partial(self._value_modified, 'y_grid')) self._view.allFontSizeFromEmptyToValue.connect(self._update_font_sizes_buffer) self._view.allFontSizeEdited.connect(self._set_all_plot_fonts) - self._view.fontSizeUpClicked.connect(self._increase_all_fonts) - self._view.fontSizeDownClicked.connect(self._decrease_all_fonts) - self._set_font_sizes_tooltip() + self._view.fontSizeUpClicked.connect(self._model.increase_all_fonts) + self._view.fontSizeDownClicked.connect(self._model.decrease_all_fonts) + self._view.redraw_signal.connect(self._set_font_sizes_tooltip) def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) @@ -44,24 +44,20 @@ def _set_all_plot_fonts(self): new_config_dict = {key: fonts_size for key in new_config_dict} self._model.all_fonts_size = new_config_dict - self._set_font_sizes_tooltip() - - def _increase_all_fonts(self): - self._model.increase_all_fonts() - self._set_font_sizes_tooltip() - - def _decrease_all_fonts(self): - self._model.decrease_all_fonts() - self._set_font_sizes_tooltip() def _set_font_sizes_tooltip(self): - font_size_dict = self._model.all_fonts_size.copy() - tip = str(font_size_dict)[1:-1].replace(', ', '\n').replace('size', '') - tip = tip.replace('_', ' ').replace("'", '').replace('font', '') + tip = self._convert_font_config_to_tooltip() self._view.allFntSz.setToolTip(tip) self._view.sclUpFntSz.setToolTip(tip) self._view.sclDownFntSz.setToolTip(tip) + def _convert_font_config_to_tooltip(self): + font_size_dict = self._model.all_fonts_size.copy() + tip = str(font_size_dict)[1:-1].replace(', ', '\n').replace('_', ' ') + for str_to_remove in ['size', 'font', "'"]: + tip = tip.replace(str_to_remove, '') + return tip + class SlicePlotOptionsPresenter(PlotOptionsPresenter): From e66cb1aeb607dd82a4f1db2e6952212b75571113 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:19:10 +0000 Subject: [PATCH 28/33] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/slice_plot_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/slice_plot_test.py b/tests/slice_plot_test.py index 9f6f30a4..b3e6c247 100644 --- a/tests/slice_plot_test.py +++ b/tests/slice_plot_test.py @@ -143,7 +143,7 @@ def test_increase_all_fonts(self): mock_colorbar_range_font_size = PropertyMock(return_value=10) type(self.slice_plot).colorbar_label_size = mock_colorbar_label_size type(self.slice_plot).colorbar_range_font_size = mock_colorbar_range_font_size - + fonts_config = {'title_size': 15, 'x_range_font_size': 14, 'y_range_font_size': 13, 'x_label_size': 12, 'y_label_size': 11} self.slice_plot.all_fonts_size = fonts_config From 33d355c2865d6675e51b9aa166a3f341c691f15c Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 31 Oct 2023 14:25:48 +0000 Subject: [PATCH 29/33] Updated unit tests --- tests/plot_options_presenter_test.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/plot_options_presenter_test.py b/tests/plot_options_presenter_test.py index 3fd93791..7620099a 100644 --- a/tests/plot_options_presenter_test.py +++ b/tests/plot_options_presenter_test.py @@ -237,13 +237,3 @@ def test_set_all_fonts_size(self): fonts_updated = {'title_size': 20, 'x_range_font_size': 20, 'y_range_font_size': 20, 'x_label_size': 20, 'y_label_size': 20} model_all_fonts_size.assert_any_call(fonts_updated) # Not latest call due to copy() methods - - def test_increase_all_fonts(self): - self.presenter = CutPlotOptionsPresenter(self.view, self.model) - self.presenter._increase_all_fonts() - self.model.increase_all_fonts.assert_called_once_with() - - def test_decrease_all_fonts(self): - self.presenter = CutPlotOptionsPresenter(self.view, self.model) - self.presenter._decrease_all_fonts() - self.model.decrease_all_fonts.assert_called_once_with() From 2e73031153d02279584d74da35ae050d6dcb0fbf Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 31 Oct 2023 14:31:04 +0000 Subject: [PATCH 30/33] Removed unused import --- src/mslice/plotting/plot_window/plot_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mslice/plotting/plot_window/plot_options.py b/src/mslice/plotting/plot_window/plot_options.py index c0c9acf2..d795cef9 100644 --- a/src/mslice/plotting/plot_window/plot_options.py +++ b/src/mslice/plotting/plot_window/plot_options.py @@ -7,7 +7,7 @@ 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 QDoubleValidator, QRegExpValidator +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 From 37c7167d4081adff3f6e2e58c66d17079f659be5 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Tue, 31 Oct 2023 14:32:56 +0000 Subject: [PATCH 31/33] Included initialization of tooltip to show on opening of plot options --- src/mslice/presenters/plot_options_presenter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index e3cad86f..36b7222f 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -25,6 +25,7 @@ def __init__(self, plot_options_dialog, plot_handler): self._view.fontSizeUpClicked.connect(self._model.increase_all_fonts) self._view.fontSizeDownClicked.connect(self._model.decrease_all_fonts) self._view.redraw_signal.connect(self._set_font_sizes_tooltip) + self._set_font_sizes_tooltip() def _value_modified(self, value_name): self._modified_values[value_name] = getattr(self._view, value_name) From 56cd64dc1d40c5f1cf5440a5481dd22438c52d57 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Thu, 2 Nov 2023 09:02:22 +0000 Subject: [PATCH 32/33] Changed default increase and decrease to one and updated tool tip. - Added constant for increase and decrease step in font size - Updated up and down arrow buttons tool tip --- src/mslice/plotting/plot_window/cut_plot.py | 5 +++-- src/mslice/plotting/plot_window/slice_plot.py | 5 +++-- src/mslice/presenters/plot_options_presenter.py | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mslice/plotting/plot_window/cut_plot.py b/src/mslice/plotting/plot_window/cut_plot.py index 72ba4cc6..dc78cddd 100644 --- a/src/mslice/plotting/plot_window/cut_plot.py +++ b/src/mslice/plotting/plot_window/cut_plot.py @@ -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): @@ -852,8 +853,8 @@ def all_fonts_size(self, values: dict): def increase_all_fonts(self): for p in self.plot_fonts_properties: - setattr(self, p, getattr(self, p) + 0.5) + 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) - 0.5) + setattr(self, p, getattr(self, p) - DEFAULT_FONT_SIZE_STEP) diff --git a/src/mslice/plotting/plot_window/slice_plot.py b/src/mslice/plotting/plot_window/slice_plot.py index 8770e872..4b67bfab 100644 --- a/src/mslice/plotting/plot_window/slice_plot.py +++ b/src/mslice/plotting/plot_window/slice_plot.py @@ -27,6 +27,7 @@ DEFAULT_LABEL_SIZE = 10 DEFAULT_TITLE_SIZE = 12 +DEFAULT_FONT_SIZE_STEP = 1 class SlicePlot(IPlot): @@ -650,8 +651,8 @@ def all_fonts_size(self, values: dict): def increase_all_fonts(self): for p in self.plot_fonts_properties: - setattr(self, p, getattr(self, p) + 0.5) + 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) - 0.5) + setattr(self, p, getattr(self, p) - DEFAULT_FONT_SIZE_STEP) diff --git a/src/mslice/presenters/plot_options_presenter.py b/src/mslice/presenters/plot_options_presenter.py index 36b7222f..fe1aa4aa 100644 --- a/src/mslice/presenters/plot_options_presenter.py +++ b/src/mslice/presenters/plot_options_presenter.py @@ -49,8 +49,8 @@ def _set_all_plot_fonts(self): def _set_font_sizes_tooltip(self): tip = self._convert_font_config_to_tooltip() self._view.allFntSz.setToolTip(tip) - self._view.sclUpFntSz.setToolTip(tip) - self._view.sclDownFntSz.setToolTip(tip) + self._view.sclUpFntSz.setToolTip("Increase font sizes\n\n" + tip) + self._view.sclDownFntSz.setToolTip("Decrease font sizes\n\n" + tip) def _convert_font_config_to_tooltip(self): font_size_dict = self._model.all_fonts_size.copy() From 4ce48d5ecb7d4b9baaf4549c21833d78d1a36b85 Mon Sep 17 00:00:00 2001 From: GuiMacielPereira Date: Thu, 2 Nov 2023 09:14:22 +0000 Subject: [PATCH 33/33] Updated unit tests --- tests/cut_plot_test.py | 10 +++++----- tests/slice_plot_test.py | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/cut_plot_test.py b/tests/cut_plot_test.py index ea7939c9..6d328784 100644 --- a/tests/cut_plot_test.py +++ b/tests/cut_plot_test.py @@ -122,8 +122,8 @@ def test_increment_all_fonts(self): self.cut_plot.all_fonts_size = fonts_config self.cut_plot.increase_all_fonts() - self.assertEqual(self.cut_plot.title_size, 15.5) - self.assertEqual(self.cut_plot.x_range_font_size, 14.5) - self.assertEqual(self.cut_plot.y_range_font_size, 13.5) - self.assertEqual(self.cut_plot.x_label_size, 12.5) - self.assertEqual(self.cut_plot.y_label_size, 11.5) + self.assertEqual(self.cut_plot.title_size, 16) + self.assertEqual(self.cut_plot.x_range_font_size, 15) + self.assertEqual(self.cut_plot.y_range_font_size, 14) + self.assertEqual(self.cut_plot.x_label_size, 13) + self.assertEqual(self.cut_plot.y_label_size, 12) diff --git a/tests/slice_plot_test.py b/tests/slice_plot_test.py index b3e6c247..9cec1e78 100644 --- a/tests/slice_plot_test.py +++ b/tests/slice_plot_test.py @@ -150,13 +150,13 @@ def test_increase_all_fonts(self): self.slice_plot.increase_all_fonts() - self.assertEqual(self.slice_plot.title_size, 15.5) - self.assertEqual(self.slice_plot.x_range_font_size, 14.5) - self.assertEqual(self.slice_plot.y_range_font_size, 13.5) - self.assertEqual(self.slice_plot.x_label_size, 12.5) - self.assertEqual(self.slice_plot.y_label_size, 11.5) - mock_colorbar_label_size.assert_called_with(9.5) - mock_colorbar_range_font_size.assert_called_with(10.5) + self.assertEqual(self.slice_plot.title_size, 16) + self.assertEqual(self.slice_plot.x_range_font_size, 15) + self.assertEqual(self.slice_plot.y_range_font_size, 14) + self.assertEqual(self.slice_plot.x_label_size, 13) + self.assertEqual(self.slice_plot.y_label_size, 12) + mock_colorbar_label_size.assert_called_with(10) + mock_colorbar_range_font_size.assert_called_with(11) if __name__ == '__main__':