From 4834fea6adbeb41898c40c0bd96ece61f7846460 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 15 Aug 2025 02:38:58 +0000 Subject: [PATCH] feat: Display variable values in VarListWidget This commit introduces a feature to display the values of each variable in the `VarListWidget` corresponding to the current time, as indicated by the plot cursor. - A "Show values" checkbox has been added to the `DataFileWidget` to toggle this functionality. - The `DataModel` has been extended to track the current tick and whether to display values. The `data()` method now formats the display string to include the variable's value when the feature is enabled. - Signal/slot connections have been added to propagate the cursor's tick from the `PlotManager` to the `DataModel` and to update the view when the cursor moves or the checkbox state changes. --- data_file_widget.py | 14 +++++++++++++- data_model.py | 25 ++++++++++++++++++++++--- main.py | 1 + var_list_widget.py | 8 ++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/data_file_widget.py b/data_file_widget.py index e607fed..17ae106 100644 --- a/data_file_widget.py +++ b/data_file_widget.py @@ -104,7 +104,14 @@ def update_checkbox_state(): # Set callback in the model so it can update the checkbox var_list.model()._checkbox_update_callback = update_checkbox_state - tab_layout.addWidget(derived_checkbox) + checkbox_layout = QHBoxLayout() + checkbox_layout.addWidget(derived_checkbox) + + show_values_checkbox = QCheckBox("Show values") + show_values_checkbox.toggled.connect(var_list.set_show_values) + checkbox_layout.addWidget(show_values_checkbox) + + tab_layout.addLayout(checkbox_layout) tab_layout.addWidget(var_list) tab_name = os.path.basename(filepath) @@ -158,6 +165,11 @@ def get_time(self, idx=0): return None return self.get_data_file(idx).time + def update_tick(self, tick): + active_widget = self.get_active_data_file() + if active_widget: + active_widget.update_tick(tick) + @pyqtSlot(QPoint) def on_context_menu_request(self, pos): # We only want to bring up the context menu when an actual tab is right-clicked. Check that diff --git a/data_model.py b/data_model.py index 9c4f9c8..95be7e1 100644 --- a/data_model.py +++ b/data_model.py @@ -69,6 +69,8 @@ def __init__(self, data_loader, parent=None): logger.info(f"Loaded {data_loader.source} which has a dt of {self._avg_dt:.6f} sec and a sampling rate of {freq} Hz") self._time_offset = 0 + self._current_tick = 0 + self._show_values = False @property def time(self): @@ -103,16 +105,33 @@ def avg_dt(self): def set_time_offset(self, time_offset): self._time_offset = time_offset + def set_current_tick(self, tick): + self._current_tick = tick + + def set_show_values(self, show): + self._show_values = show + def rowCount(self, parent=QModelIndex()): return len(self._data) def data(self, index, role): if role == Qt.DisplayRole: item = self._data[index.row()] - return QVariant(item.var_name) + var_name = item.var_name + + if self._show_values and not isinstance(item, SeparatorItem): + try: + value = item.data[self._current_tick] + if isinstance(value, (float, np.floating)): + display_text = f"{var_name}: {value:.4f}" + else: + display_text = f"{var_name}: {value}" + return QVariant(display_text) + except IndexError: + return QVariant(f"{var_name}: N/A") + + return QVariant(var_name) elif role == Qt.UserRole: - # print(type(index)) - # print(type(index.row())) return self._data[index.row()] elif role == Qt.ForegroundRole: item = self._data[index.row()] diff --git a/main.py b/main.py index 23697b8..31515b7 100755 --- a/main.py +++ b/main.py @@ -107,6 +107,7 @@ def __init__(self): tick_time_indicator = TimeTickWidget() self.plot_manager.tickValueChanged.connect(tick_time_indicator.update_tick) self.plot_manager.timeValueChanged.connect(tick_time_indicator.update_time) + self.plot_manager.tickValueChanged.connect(self.data_file_widget.update_tick) self.statusBar().addPermanentWidget(tick_time_indicator) self._settings = QSettings() diff --git a/var_list_widget.py b/var_list_widget.py index 57c0de6..1dca667 100644 --- a/var_list_widget.py +++ b/var_list_widget.py @@ -59,6 +59,14 @@ def set_time_offset(self, time_offset): self.model().set_time_offset(time_offset) self.timeChanged.emit() + def set_show_values(self, show): + self.model().set_show_values(show) + self.model().layoutChanged.emit() + + def update_tick(self, tick): + self.model().set_current_tick(tick) + self.model().layoutChanged.emit() + def close(self): self.onClose.emit() return super().close()