From 413d45237b0b36903b0f860f74653a558d51b1ba Mon Sep 17 00:00:00 2001 From: kienle <kienle@passcal.nmt.edu> Date: Wed, 29 Mar 2023 16:24:13 -0600 Subject: [PATCH] Show text on top of the ruler --- .../plotting_widget/plotting_widget.py | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py index 8e1d4302e..80fd5b16e 100755 --- a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py @@ -1,8 +1,11 @@ """ Class of which object is used to plot data """ +from typing import Optional + +import matplotlib.text import numpy as np -from PySide2.QtCore import QTimer +from PySide2.QtCore import QTimer, Qt from matplotlib import pyplot as pl from PySide2 import QtCore, QtWidgets @@ -10,7 +13,8 @@ from sohstationviewer.conf import constants from sohstationviewer.view.util.color import set_color_mode from sohstationviewer.view.util.functions import get_total_miny_maxy from sohstationviewer.view.plotting.plotting_widget.plotting_axes import ( - PlottingAxes) + PlottingAxes +) from sohstationviewer.view.plotting.plotting_widget.plotting import Plotting from sohstationviewer.controller.plotting_data import format_time @@ -200,6 +204,10 @@ class PlottingWidget(QtWidgets.QScrollArea): self.plotting = Plotting(self, self.plotting_axes, parent_params=parent) + self.new_min_x = float('-inf') + + self.ruler_text: Optional[matplotlib.text.Text] = None + self.set_colors('B') # ======================================================================= # @@ -254,10 +262,10 @@ class PlottingWidget(QtWidgets.QScrollArea): :param xdata: float - time value in plot """ - if self.min_x == xdata: + if self.new_min_x == xdata: return self.zoom_marker1_shown = False - [self.min_x, self.max_x] = sorted([self.min_x, xdata]) + [self.min_x, self.max_x] = sorted([self.new_min_x, xdata]) self.set_lim() self.zoom_marker1.set_visible(False) self.zoom_marker2.set_visible(False) @@ -332,6 +340,16 @@ 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.ControlModifier, QtCore.Qt.MetaModifier, + Qt.ShiftModifier]: + try: + self.ruler_text.remove() + self.ruler_text = None + except AttributeError: + pass + for w in self.peer_plotting_widgets: if modifiers == QtCore.Qt.ShiftModifier: w.on_shift_click(xdata) @@ -340,6 +358,10 @@ class PlottingWidget(QtWidgets.QScrollArea): w.on_ctrl_cmd_click(xdata) w.draw() + self.parent.show() + self.parent.activateWindow() + self.parent.raise_() + def on_ctrl_cmd_click(self, xdata): """ On ctrl/cmd + left click @@ -356,6 +378,15 @@ class PlottingWidget(QtWidgets.QScrollArea): except AttributeError: pass self.set_ruler_visibled(self.ruler, xdata) + if xdata >= self.min_x: + self.ruler_text = self.plotting_axes.fig.text( + xdata, 75, 'Potato', + verticalalignment='top', + horizontalalignment='center', + transform=self.timestamp_bar_top.transData, + color=self.display_color['basic'], + size=self.timestamp_bar_top.get_xticklabels()[0].get_fontsize() + ) def on_shift_click(self, xdata): """ @@ -373,7 +404,7 @@ class PlottingWidget(QtWidgets.QScrollArea): if not self.zoom_marker1_shown: self.ruler.set_visible(False) self.set_ruler_visibled(self.zoom_marker1, xdata) - self.min_x = xdata + self.new_min_x = xdata self.zoom_marker1_shown = True else: self.set_ruler_visibled(self.zoom_marker2, xdata) -- GitLab