From 35e5f302a88e44e1cf0d57fcac4648cd6ea4ab34 Mon Sep 17 00:00:00 2001
From: Olivier Jossoud <olivier.jossoud@lsce.ipsl.fr>
Date: Tue, 8 Oct 2019 11:30:49 +0200
Subject: [PATCH] ConductCalib. Highlight selected row of "set" table.

---
 src/uim/conductcalibuim.py |  4 ++++
 src/utils.py               | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/src/uim/conductcalibuim.py b/src/uim/conductcalibuim.py
index 2e1afd8..208e808 100644
--- a/src/uim/conductcalibuim.py
+++ b/src/uim/conductcalibuim.py
@@ -116,6 +116,8 @@ class ConductCalibUim:
         steps_item.setText(str(calib_run.instant_config_df["step"].max()))
         self.main_ui.conduct_tablewidget_set.setItem(row_id, self.STEPS_COL, steps_item)
 
+        utils.highlight_row(self.main_ui.conduct_tablewidget_set, row_id)
+
     def change_selected_run(self, row: int, column: int):
         # Get run identifier (date and time concatenated)
         identifier = self.main_ui.conduct_tablewidget_set.item(row, self.DATE_COL).text() \
@@ -126,6 +128,8 @@ class ConductCalibUim:
 
         self.current_calib_run = calib_run
 
+        utils.highlight_row(self.main_ui.conduct_tablewidget_set, row)
+
         self.__update_run_plot__(calib_run, self.current_channel)
         self.__update_run_table__(calib_run, self.current_channel)
 
diff --git a/src/utils.py b/src/utils.py
index ce47e61..0f234ed 100644
--- a/src/utils.py
+++ b/src/utils.py
@@ -2,6 +2,8 @@ import pyqtgraph as pg
 import datetime
 import pandas as pd
 import numpy as np
+from PyQt5.QtWidgets import QTableWidget
+from PyQt5.QtGui import QColor
 
 
 def pd_time_to_epoch_ms(series: pd.Series) -> list:
@@ -13,8 +15,10 @@ def pd_time_to_epoch_ms(series: pd.Series) -> list:
 def datetime64_to_epoch_ms(datetimes_list: np.ndarray) -> list:
     return [float(instant) / 1e9 for instant in datetimes_list]
 
+
 ####################################################################
 # Graphics
+
 class TimeAxisItem(pg.AxisItem):
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -24,3 +28,31 @@ class TimeAxisItem(pg.AxisItem):
     def tickStrings(self, values, scale, spacing):
         return [datetime.datetime.fromtimestamp(value).strftime("%H:%M:%S") for value in values]
 
+
+def highlight_row(table: QTableWidget, highlighted_row_id: int,
+                  highlighted_row_color: QColor = QColor(173, 216, 230),
+                  other_rows_color: QColor = QColor(255, 255, 255)) -> None:
+    """Highlight a table's row by changing its background color.
+
+    Parameters
+    ----------
+    table: PyQt5.QtWidgets.QTableWidget
+        Table whose row should be highlighted.
+    highlighted_row_id: int
+        Index (first row is 0) of the row which should be highlighted.
+    highlighted_row_color: PyQt5.QtGui.QColor
+        Background color of the highlighted row. Default is light blue.
+    other_rows_color: PyQt5.QtGui.QColor
+        Background color of the other rows of the table. Default is white.
+
+    Returns
+    -------
+        Nothing, modify the input ``table``
+    """
+    for row_id in range(table.rowCount()):
+        if row_id == highlighted_row_id:
+            row_color = highlighted_row_color
+        else:
+            row_color = other_rows_color
+        for column_id in range(table.columnCount()):
+            table.item(row_id, column_id).setBackground(row_color)
\ No newline at end of file
-- 
GitLab