From 378b3e3456ea71d726e5008606f43f85a8f6dbe8 Mon Sep 17 00:00:00 2001 From: ldam <ldam@passcal.nmt.edu> Date: Thu, 27 Apr 2023 09:55:18 -0600 Subject: [PATCH] use main_window for params in plotting_widget rather than assign variables to dialog than access params from parent dialog; call add_gap_bar() inside MultiThreadedPlottingWidget instead onf inside # Drawing State-Of-Health channels and mass position --- .../multi_threaded_plotting_widget.py | 12 ++++++---- .../view/plotting/plotting_widget/plotting.py | 6 ++--- .../plotting/plotting_widget/plotting_axes.py | 6 ++--- .../plotting_widget/plotting_widget.py | 21 +++++++++++------- .../view/plotting/state_of_health_widget.py | 7 +++--- .../plotting/time_power_squared_dialog.py | 8 ++----- .../view/plotting/waveform_dialog.py | 22 ++++--------------- sohstationviewer/view/ui/main_ui.py | 3 ++- 8 files changed, 38 insertions(+), 47 deletions(-) diff --git a/sohstationviewer/view/plotting/plotting_widget/multi_threaded_plotting_widget.py b/sohstationviewer/view/plotting/plotting_widget/multi_threaded_plotting_widget.py index e787c89e4..9dd714920 100644 --- a/sohstationviewer/view/plotting/plotting_widget/multi_threaded_plotting_widget.py +++ b/sohstationviewer/view/plotting/plotting_widget/multi_threaded_plotting_widget.py @@ -4,6 +4,8 @@ from typing import Tuple, Union, Dict, Callable, List, Optional from PySide2 import QtCore +from sohstationviewer.model.data_type_model import DataTypeModel + from sohstationviewer.view.plotting.plotting_widget.plotting_processor import ( PlottingChannelProcessor) from sohstationviewer.view.plotting.plotting_widget.plotting_widget import ( @@ -23,9 +25,8 @@ class MultiThreadedPlottingWidget(PlottingWidget): stopped = QtCore.Signal() notification = QtCore.Signal(str) - def __init__(self, parent, tracking_box, name): - PlottingWidget.__init__( - self, parent, tracking_box, name) + def __init__(self, *args, **kwargs): + PlottingWidget.__init__(self, *args, **kwargs) self.data_processors: List[PlottingChannelProcessor] = [] # Only one data processor can run at a time, so it is not a big problem @@ -54,6 +55,7 @@ class MultiThreadedPlottingWidget(PlottingWidget): self.is_working = False def init_plot(self, + d_obj: DataTypeModel, data_time: List[float], key: Union[str, Tuple[str, str]], start_tm: float, end_tm: float, @@ -61,6 +63,7 @@ class MultiThreadedPlottingWidget(PlottingWidget): """ Initiate plotting with gaps, top time bar + :param d_obj: object of data :param data_time: start and end time of data :param key: data set's key :param start_tm: requested start time to plot @@ -72,7 +75,7 @@ class MultiThreadedPlottingWidget(PlottingWidget): self.key = key self.processing_log = [] # [(message, type)] self.gap_bar = None - self.date_mode = self.parent.date_format.upper() + self.date_mode = self.main_params.date_format.upper() self.time_ticks_total = time_ticks_total self.min_x = max(data_time[0], start_tm) self.max_x = min(data_time[1], end_tm) @@ -98,6 +101,7 @@ class MultiThreadedPlottingWidget(PlottingWidget): self.draw() return False else: + self.plotting_axes.add_gap_bar(d_obj.gaps[key]) return True def create_plotting_channel_processors( diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting.py b/sohstationviewer/view/plotting/plotting_widget/plotting.py index 13ac3e189..33f98bb92 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting.py @@ -10,16 +10,16 @@ class Plotting: """ Class that includes different methods to plot channels on a figure. """ - def __init__(self, parent, plotting_axes, parent_params): + def __init__(self, parent, plotting_axes, main_params): """ :param parent: PlottingWidget - widget to plot channels :param plotting_axes: PlottingAxes - widget that includes a figure and methods related to create axes - :param parent_params: Object - object that includes needed parameters + :param main_params: Object - object that includes needed parameters """ super().__init__() self.parent = parent - self.params = parent_params + self.params = main_params self.plotting_axes = plotting_axes def plot_none(self): diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py b/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py index 8bc3e6427..22d3e07d5 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py @@ -17,12 +17,12 @@ class PlottingAxes: Class that includes a figure to add axes for plotting and all methods related to create axes, ruler, title. """ - def __init__(self, parent, parent_params): + def __init__(self, parent, main_params): """ :param parent: PlottingWidget - widget to plot channels - :param parent_params: Object - object that includes needed parameters + :param main_params: Object - object that includes needed parameters """ - self.params = parent_params + self.params = main_params self.parent = parent # gaps: list of gaps which is a list of min and max of gaps self.gaps: List[List[float]] = [] diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py index 296fc32bb..9c6c9e544 100755 --- a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py @@ -1,12 +1,13 @@ """ Class of which object is used to plot data """ -from typing import List, Optional +from typing import List, Optional, Union import matplotlib.text from PySide2.QtCore import QTimer, Qt from matplotlib import pyplot as pl from PySide2 import QtCore, QtWidgets +from PySide2.QtWidgets import QWidget, QApplication, QTextBrowser from sohstationviewer.conf import constants from sohstationviewer.view.util.color import set_color_mode @@ -28,15 +29,20 @@ class PlottingWidget(QtWidgets.QScrollArea): events to serve user's purpose. """ - def __init__(self, parent, tracking_box, name): + def __init__(self, parent: Union[QWidget, QApplication], + tracking_box: QTextBrowser, + name: str, + main_params: QApplication) -> None: """ - :param parent: QWidget/QMainWindow - widget that contains this plotting + :param parent: widget that contains this plotting widget - :param tracking_box: QTextBrowser - widget to display tracking info - :param name: str - name of the plotting widget to keep track of what + :param tracking_box: widget to display tracking info + :param name: name of the plotting widget to keep track of what widget the program is working on + :param main_params: Main window that keep all parameters set by user """ self.parent = parent + self.main_params = main_params self.name = name self.tracking_box = tracking_box # =============== declare attributes ======================= @@ -194,7 +200,7 @@ class PlottingWidget(QtWidgets.QScrollArea): """ plotting_axes: object that helps creating axes for plotting """ - self.plotting_axes = PlottingAxes(self, parent_params=parent) + self.plotting_axes = PlottingAxes(self, main_params) self.plotting_axes.canvas.setParent(self.main_widget) self.setWidget(self.main_widget) @@ -202,8 +208,7 @@ class PlottingWidget(QtWidgets.QScrollArea): """ plotting: object that helps with different types of plotting channels """ - self.plotting = Plotting(self, self.plotting_axes, - parent_params=parent) + self.plotting = Plotting(self, self.plotting_axes, main_params) """ new_min_x: store the new minimum time for zooming; used to fix a problem where after the first zoom marker is chosen, any ruler that is diff --git a/sohstationviewer/view/plotting/state_of_health_widget.py b/sohstationviewer/view/plotting/state_of_health_widget.py index 7e7435304..4269c0e29 100644 --- a/sohstationviewer/view/plotting/state_of_health_widget.py +++ b/sohstationviewer/view/plotting/state_of_health_widget.py @@ -20,8 +20,8 @@ class SOHWidget(MultiThreadedPlottingWidget): Widget to display soh and mass position data. """ - def __init__(self, parent, tracking_box, name): - MultiThreadedPlottingWidget.__init__(self, parent, tracking_box, name) + def __init__(self, *args, **kwargs): + MultiThreadedPlottingWidget.__init__(self, *args, **kwargs) def init_plot(self, d_obj: DataTypeModel, key: Union[str, Tuple[str, str]], start_tm: float, end_tm: float, time_ticks_total: int): @@ -39,12 +39,11 @@ class SOHWidget(MultiThreadedPlottingWidget): self.plotting_data2 = d_obj.mass_pos_data[key] channel_list = d_obj.soh_data[key].keys() data_time = d_obj.data_time[key] - ret = super().init_plot(data_time, key, start_tm, end_tm, + ret = super().init_plot(d_obj, data_time, key, start_tm, end_tm, time_ticks_total, is_waveform=False) if not ret: return False - self.plotting_axes.add_gap_bar(d_obj.gaps[key]) not_found_chan = [c for c in channel_list if c not in self.plotting_data1.keys()] if len(not_found_chan) > 0: diff --git a/sohstationviewer/view/plotting/time_power_squared_dialog.py b/sohstationviewer/view/plotting/time_power_squared_dialog.py index 8caef189b..e443d1bad 100755 --- a/sohstationviewer/view/plotting/time_power_squared_dialog.py +++ b/sohstationviewer/view/plotting/time_power_squared_dialog.py @@ -102,7 +102,7 @@ class TimePowerSquaredWidget(plotting_widget.PlottingWidget): self.min_x = max(d_obj.data_time[key][0], start_tm) self.max_x = min(d_obj.data_time[key][1], end_tm) - self.date_mode = self.parent.date_format.upper() + self.date_mode = self.main_params.date_format.upper() if self.plotting_data1 == {}: title = "NO WAVEFORM DATA TO DISPLAY TPS." self.processing_log.append( @@ -488,10 +488,6 @@ class TimePowerSquaredDialog(QtWidgets.QWidget): super().__init__() self.parent = parent """ - date_format: str - format to display date/time - """ - self.date_format = self.parent.date_format - """ data_type: str - type of data being plotted """ self.data_type = None @@ -512,7 +508,7 @@ class TimePowerSquaredDialog(QtWidgets.QWidget): for each 5-minute of data """ self.plotting_widget = TimePowerSquaredWidget( - self, self.info_text_browser, "TPS") + self, self.info_text_browser, "TPS", self.parent) main_layout.addWidget(self.plotting_widget, 2) bottom_layout = QtWidgets.QHBoxLayout() diff --git a/sohstationviewer/view/plotting/waveform_dialog.py b/sohstationviewer/view/plotting/waveform_dialog.py index 6361a28ad..ba9a2a2cd 100755 --- a/sohstationviewer/view/plotting/waveform_dialog.py +++ b/sohstationviewer/view/plotting/waveform_dialog.py @@ -18,8 +18,8 @@ class WaveformWidget(MultiThreadedPlottingWidget): """ Widget to display waveform and mass position data. """ - def __init__(self, parent, tracking_box, name): - MultiThreadedPlottingWidget.__init__(self, parent, tracking_box, name) + def __init__(self, *args, **kwargs): + MultiThreadedPlottingWidget.__init__(self, *args, **kwargs) def init_plot(self, d_obj: DataTypeModel, key: Union[str, Tuple[str, str]], start_tm: float, end_tm: float, time_ticks_total: int): @@ -36,7 +36,7 @@ class WaveformWidget(MultiThreadedPlottingWidget): self.plotting_data1 = d_obj.waveform_data[key] self.plotting_data2 = d_obj.mass_pos_data[key] data_time = d_obj.data_time[key] - return super().init_plot(data_time, key, start_tm, end_tm, + return super().init_plot(d_obj, data_time, key, start_tm, end_tm, time_ticks_total, is_waveform=True) def get_plot_info(self, *args, **kwargs): @@ -90,20 +90,6 @@ class WaveformDialog(QtWidgets.QWidget): """ self.parent = parent """ - date_format: str - format to display date/time - """ - self.date_format = self.parent.date_format - """ - bit_weight_opt: str - option for bit weight ('', 'low', 'high') - (Menu Options - Q330 Gain) - """ - self.bit_weight_opt = self.parent.bit_weight_opt - """ - mass_pos_volt_range_opt: str - ('regular'/'trilium'): define how to map - values and colors when plotting - """ - self.mass_pos_volt_range_opt = self.parent.mass_pos_volt_range_opt - """ data_type: str - type of data being plotted """ self.data_type = None @@ -124,7 +110,7 @@ class WaveformDialog(QtWidgets.QWidget): mass position channel """ self.plotting_widget = WaveformWidget( - self, self.info_text_browser, 'WAVEFORM') + self, self.info_text_browser, 'WAVEFORM', self.parent) self.plotting_widget.finished.connect(self.plot_finished) main_layout.addWidget(self.plotting_widget, 2) diff --git a/sohstationviewer/view/ui/main_ui.py b/sohstationviewer/view/ui/main_ui.py index 24702e91b..005029668 100755 --- a/sohstationviewer/view/ui/main_ui.py +++ b/sohstationviewer/view/ui/main_ui.py @@ -356,7 +356,8 @@ class UIMainWindow(object): self.plotting_widget = SOHWidget(self.main_window, self.tracking_info_text_browser, - 'SOH') + 'SOH', + self.main_window) h_layout.addWidget(self.plotting_widget, 2) -- GitLab