From dc56acde9fd9e365b0f9a925f1b0d5716fa09b1d Mon Sep 17 00:00:00 2001 From: Peter Beaucage Date: Tue, 25 Oct 2022 07:24:32 -0300 Subject: [PATCH 1/2] Add persistent legend visibility toggle --- src/sas/qtgui/Plotting/Plotter.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sas/qtgui/Plotting/Plotter.py b/src/sas/qtgui/Plotting/Plotter.py index 357707501c..7f7a8692ae 100644 --- a/src/sas/qtgui/Plotting/Plotter.py +++ b/src/sas/qtgui/Plotting/Plotter.py @@ -88,6 +88,8 @@ def __init__(self, parent=None, manager=None, quickplot=False): self.toolbar._actions['pan'].triggered.connect(self._pan) self.toolbar._actions['zoom'].triggered.connect(self._zoom) + self.legendVisible = True + parent.geometry() @property @@ -250,7 +252,7 @@ def plot(self, data=None, color=None, marker=None, hide_error=False, transform=T self.plot_lines[data.name] = line # Now add the legend with some customizations. - if self.showLegend: + if self.showLegend and self.legendVisible: width=_legendResize(self.canvas.size().width(), self.parent) if width is not None: self.legend = ax.legend(loc='upper right', shadow=True, prop={'size':width}) @@ -303,7 +305,7 @@ def onResize(self, event): """ Resize the legend window/font on canvas resize """ - if not self.showLegend: + if not self.showLegend or not self.legendVisible: return width = _legendResize(event.width, self.parent) # resize the legend to follow the canvas width. @@ -799,8 +801,9 @@ def onToggleLegend(self): if not self.showLegend: return - visible = self.legend.get_visible() - self.legend.set_visible(not visible) + #visible = self.legend.get_visible() + self.legendVisible = not self.legendVisible + self.legend.set_visible(self.legendVisible) self.canvas.draw_idle() def onCusotmizeLabel(self): From c72bbc2db4d4af2802952103780116a2a4c902f2 Mon Sep 17 00:00:00 2001 From: Peter Beaucage Date: Tue, 25 Oct 2022 12:36:21 -0300 Subject: [PATCH 2/2] Change visibility, don't block re-creation. Thanks @krzywon for the suggestion! --- src/sas/qtgui/Plotting/Plotter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sas/qtgui/Plotting/Plotter.py b/src/sas/qtgui/Plotting/Plotter.py index 7f7a8692ae..f9ec588f61 100644 --- a/src/sas/qtgui/Plotting/Plotter.py +++ b/src/sas/qtgui/Plotting/Plotter.py @@ -252,7 +252,7 @@ def plot(self, data=None, color=None, marker=None, hide_error=False, transform=T self.plot_lines[data.name] = line # Now add the legend with some customizations. - if self.showLegend and self.legendVisible: + if self.showLegend: width=_legendResize(self.canvas.size().width(), self.parent) if width is not None: self.legend = ax.legend(loc='upper right', shadow=True, prop={'size':width}) @@ -260,7 +260,7 @@ def plot(self, data=None, color=None, marker=None, hide_error=False, transform=T self.legend = ax.legend(loc='upper right', shadow=True) if self.legend: self.legend.set_picker(True) - + self.legend.set_visible(self.legendVisible) # Current labels for axes if self.yLabel and not is_fit: ax.set_ylabel(self.yLabel)