From 553013a32cbaddb4eefcef100a239d4b44badc4d Mon Sep 17 00:00:00 2001
From: ldam <ldam@passcal.nmt.edu>
Date: Mon, 24 Jun 2024 11:14:01 -0600
Subject: [PATCH] leave ruler and its text when zoom in/out

---
 .../plotting_widget/plotting_widget.py        | 32 +++++++------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py
index 54de2d0b..c6bee01a 100644
--- a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py
+++ b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py
@@ -529,16 +529,6 @@ class PlottingWidget(QtWidgets.QScrollArea):
         else:
             xdata = self.get_timestamp(event)
 
-        # We only want to remove the text on the ruler when we start zooming in
-        # or move the ruler to another location.
-        if modifiers in [QtCore.Qt.KeyboardModifier.ControlModifier,
-                         QtCore.Qt.KeyboardModifier.MetaModifier,
-                         QtCore.Qt.KeyboardModifier.ShiftModifier]:
-            try:
-                self.ruler_text.remove()
-                self.ruler_text = None
-            except AttributeError:
-                pass
         if (self.main_window.tps_check_box.isChecked() and
                 modifiers in [QtCore.Qt.KeyboardModifier.ControlModifier,
                               QtCore.Qt.KeyboardModifier.MetaModifier,
@@ -547,14 +537,7 @@ class PlottingWidget(QtWidgets.QScrollArea):
         for w in self.peer_plotting_widgets:
             if not w.has_data:
                 continue
-            if modifiers in [QtCore.Qt.KeyboardModifier.ControlModifier,
-                             QtCore.Qt.KeyboardModifier.MetaModifier,
-                             QtCore.Qt.KeyboardModifier.ShiftModifier]:
-                try:
-                    w.ruler_text.remove()
-                    w.ruler_text = None
-                except AttributeError:
-                    pass
+
             if modifiers == QtCore.Qt.KeyboardModifier.ShiftModifier:
                 if xdata < w.min_x:
                     # click on left of plot
@@ -589,6 +572,7 @@ class PlottingWidget(QtWidgets.QScrollArea):
 
         :param xdata: float - time value of a channel plot
         """
+
         self.zoom_marker1.set_visible(False)
         self.zoom_marker1_shown = False
         try:
@@ -599,6 +583,11 @@ class PlottingWidget(QtWidgets.QScrollArea):
         if xdata >= self.min_x:
             ruler_text_content = format_time(xdata, self.parent.date_format,
                                              'HH:MM:SS')
+            try:
+                # remove ruler_text before creating the new one
+                self.ruler_text.remove()
+            except AttributeError:
+                pass
             self.ruler_text = self.plotting_axes.fig.text(
                 xdata, 5000, ruler_text_content,
                 verticalalignment='top',
@@ -613,17 +602,18 @@ class PlottingWidget(QtWidgets.QScrollArea):
         On shift + left click:
         if click on the left of a plot, do zoom out to the previous range
         if zoom_marker1 not shown yet:
-            + hide ruler
             + connect zoom_marker2 to follow mouse
             + show zoom_marker1
         else:
             + show zoom_marker2
             + zoom data in between 2 zoomMarkers
 
+        Notice that ruler will stay at the same xdata either with zoom in
+        or out.
+
         :param xdata: float - time value of a channel plot
         """
         if not self.zoom_marker1_shown:
-            self.ruler.set_visible(False)
             self.set_ruler_visibled(self.zoom_marker1, xdata)
             self.new_min_x = xdata
             self.zoom_marker1_shown = True
@@ -654,6 +644,8 @@ class PlottingWidget(QtWidgets.QScrollArea):
         When press on Escape key, hide all rulers and set False for
             zoom_marker1_shown on all plotting widgets
 
+        Notice: press Escape is the only way to hide ruler and its text.
+
         :param event: QKeyEvent - event to know what key is pressed
         """
         if event.key() == QtCore.Qt.Key.Key_Escape:
-- 
GitLab