From a36b07e016f14ed568dd16464f19d3d85e45e31b Mon Sep 17 00:00:00 2001
From: Olivier Jossoud <olivier.jossoud@lsce.ipsl.fr>
Date: Thu, 7 Nov 2019 10:06:21 +0100
Subject: [PATCH] Explo. Show time shift between vertical lines.

---
 pyqt/mainwindow.ui      | 24 ++++++++++++++++++++----
 src/gui/uimainwindow.py | 13 +++++++++----
 src/gui/uistabwindow.py |  2 +-
 src/uim/explouim.py     |  7 +++++--
 4 files changed, 35 insertions(+), 11 deletions(-)

diff --git a/pyqt/mainwindow.ui b/pyqt/mainwindow.ui
index dabf59c..07e9834 100644
--- a/pyqt/mainwindow.ui
+++ b/pyqt/mainwindow.ui
@@ -34,9 +34,9 @@
       <property name="geometry">
        <rect>
         <x>20</x>
-        <y>260</y>
+        <y>300</y>
         <width>1321</width>
-        <height>651</height>
+        <height>611</height>
        </rect>
       </property>
      </widget>
@@ -46,7 +46,7 @@
         <x>20</x>
         <y>50</y>
         <width>921</width>
-        <height>201</height>
+        <height>241</height>
        </rect>
       </property>
       <property name="selectionBehavior">
@@ -245,6 +245,22 @@
        <string>Stabilization analysis</string>
       </property>
      </widget>
+     <widget class="QLabel" name="explo_label_timeshift">
+      <property name="geometry">
+       <rect>
+        <x>960</x>
+        <y>270</y>
+        <width>161</width>
+        <height>16</height>
+       </rect>
+      </property>
+      <property name="toolTip">
+       <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Time shift between the yellow vertical line (left click on graph to generate or move) and the current cursor position (dotted white vertical line).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+      </property>
+      <property name="text">
+       <string>Time shift:</string>
+      </property>
+     </widget>
     </widget>
     <widget class="QWidget" name="tab_conductcalib">
      <attribute name="title">
@@ -521,7 +537,7 @@
      <x>0</x>
      <y>0</y>
      <width>1355</width>
-     <height>26</height>
+     <height>21</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuInstrument">
diff --git a/src/gui/uimainwindow.py b/src/gui/uimainwindow.py
index 716cad3..a4b4a05 100644
--- a/src/gui/uimainwindow.py
+++ b/src/gui/uimainwindow.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Form implementation generated from reading ui file '../pyqt/mainwindow.ui'
+# Form implementation generated from reading ui file '..\pyqt\mainwindow.ui'
 #
 # Created by: PyQt5 UI code generator 5.11.3
 #
@@ -20,10 +20,10 @@ class Ui_MainWindow(object):
         self.tab_explo = QtWidgets.QWidget()
         self.tab_explo.setObjectName("tab_explo")
         self.explo_graphicsview_top = PlotWidget(self.tab_explo)
-        self.explo_graphicsview_top.setGeometry(QtCore.QRect(20, 260, 1321, 651))
+        self.explo_graphicsview_top.setGeometry(QtCore.QRect(20, 300, 1321, 611))
         self.explo_graphicsview_top.setObjectName("explo_graphicsview_top")
         self.explo_tablewidget_variables = QtWidgets.QTableWidget(self.tab_explo)
-        self.explo_tablewidget_variables.setGeometry(QtCore.QRect(20, 50, 921, 201))
+        self.explo_tablewidget_variables.setGeometry(QtCore.QRect(20, 50, 921, 241))
         self.explo_tablewidget_variables.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectColumns)
         self.explo_tablewidget_variables.setObjectName("explo_tablewidget_variables")
         self.explo_tablewidget_variables.setColumnCount(9)
@@ -101,6 +101,9 @@ class Ui_MainWindow(object):
         self.explo_pushbutton_stab = QtWidgets.QPushButton(self.tab_explo)
         self.explo_pushbutton_stab.setGeometry(QtCore.QRect(400, 10, 161, 30))
         self.explo_pushbutton_stab.setObjectName("explo_pushbutton_stab")
+        self.explo_label_timeshift = QtWidgets.QLabel(self.tab_explo)
+        self.explo_label_timeshift.setGeometry(QtCore.QRect(960, 270, 161, 16))
+        self.explo_label_timeshift.setObjectName("explo_label_timeshift")
         self.tabWidget.addTab(self.tab_explo, "")
         self.tab_conductcalib = QtWidgets.QWidget()
         self.tab_conductcalib.setObjectName("tab_conductcalib")
@@ -195,7 +198,7 @@ class Ui_MainWindow(object):
         self.tabWidget.addTab(self.tab_pumpcalib, "")
         MainWindow.setCentralWidget(self.centralwidget)
         self.menubar = QtWidgets.QMenuBar(MainWindow)
-        self.menubar.setGeometry(QtCore.QRect(0, 0, 1355, 26))
+        self.menubar.setGeometry(QtCore.QRect(0, 0, 1355, 21))
         self.menubar.setObjectName("menubar")
         self.menuInstrument = QtWidgets.QMenu(self.menubar)
         self.menuInstrument.setObjectName("menuInstrument")
@@ -257,6 +260,8 @@ class Ui_MainWindow(object):
         self.explo_pushbutton_setup_save.setText(_translate("MainWindow", "Save current setup"))
         self.explo_pushbutton_setup_load.setText(_translate("MainWindow", "Load selected"))
         self.explo_pushbutton_stab.setText(_translate("MainWindow", "Stabilization analysis"))
+        self.explo_label_timeshift.setToolTip(_translate("MainWindow", "<html><head/><body><p>Time shift between the yellow vertical line (left click on graph to generate or move) and the current cursor position (dotted white vertical line).</p></body></html>"))
+        self.explo_label_timeshift.setText(_translate("MainWindow", "Time shift:"))
         self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_explo), _translate("MainWindow", "Data exploration"))
         item = self.conduct_tablewidget_set.horizontalHeaderItem(0)
         item.setText(_translate("MainWindow", "Date"))
diff --git a/src/gui/uistabwindow.py b/src/gui/uistabwindow.py
index 99144ac..7592df0 100644
--- a/src/gui/uistabwindow.py
+++ b/src/gui/uistabwindow.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Form implementation generated from reading ui file '../pyqt/stabwindow.ui'
+# Form implementation generated from reading ui file '..\pyqt\stabwindow.ui'
 #
 # Created by: PyQt5 UI code generator 5.11.3
 #
diff --git a/src/uim/explouim.py b/src/uim/explouim.py
index 4c78f10..f323bee 100644
--- a/src/uim/explouim.py
+++ b/src/uim/explouim.py
@@ -391,16 +391,19 @@ class ExploUim:
 
     def __mouse_moved__(self, pos: QPointF) -> None:
         """Function triggered when the user's mouse cursor hovers over the plot. Display a vertical line where the
-        cursor is.
+        cursor is, and update time shift with click-fixed line, if any.
 
         Parameters
         ----------
         pos: PyQt5.QtCore.QPointF
         """
-        # if self.step_curves[0].sceneBoundingRect().contains(pos):
         mouse_point = self.step_curves[0].getViewBox().mapSceneToView(pos)
         self.cursor_vline.setPos(mouse_point.x())
 
+        if self.measure_vline.getPos() != [0, 0]:
+            timeshift_s = abs(self.measure_vline.getPos()[0] - self.cursor_vline.getPos()[0])
+            self.main_ui.explo_label_timeshift.setText("Time shift: " + "{:.2f}".format(timeshift_s) + "s")
+
     def __get_timeseries_x_values__(self, timeseries: pd.DataFrame, timeshift_sec: float = 0) -> list:
         # As it is a _step_ curve, add a last datetime point to determine the end of the last step. This is the datetime
         # of the last available data of the dataset, plus one second.
-- 
GitLab