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 e787c89e49495d520ef90f10c028bf7a56fe8e56..229544d77488a53b07c49a8a6b7254d969a92e22 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_window.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 13ac3e189d604468d98852f2a03c99b47a4cf074..ec2ab8e8a7b6c12a7cddc176caf44bb4e6df2271 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting.py @@ -10,16 +10,17 @@ 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_window): """ :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_window: QApplication - Main Window to access user's + setting parameters """ super().__init__() self.parent = parent - self.params = parent_params + self.main_window = main_window self.plotting_axes = plotting_axes def plot_none(self): @@ -334,7 +335,7 @@ class Plotting: :return ax: matplotlib.axes.Axes - axes of the channel """ value_colors = get_masspos_value_colors( - self.params.mass_pos_volt_range_opt, chan_id, + self.main_window.mass_pos_volt_range_opt, chan_id, self.parent.c_mode, self.parent.processing_log, ret_type='tupleList') diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py b/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py index 8bc3e6427199553b8b74fba0cb534091d77ea4f3..940110dc3391f55ec682ff855975c427a9e40d01 100644 --- a/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py +++ b/sohstationviewer/view/plotting/plotting_widget/plotting_axes.py @@ -17,12 +17,13 @@ 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_window): """ :param parent: PlottingWidget - widget to plot channels - :param parent_params: Object - object that includes needed parameters + :param main_window: QApplication - Main Window to access user's + setting parameters """ - self.params = parent_params + self.main_window = main_window self.parent = parent # gaps: list of gaps which is a list of min and max of gaps self.gaps: List[List[float]] = [] @@ -275,7 +276,7 @@ class PlottingAxes: ax.spines['top'].set_visible(True) ax.spines['bottom'].set_visible(True) ax.unit_bw = get_unit_bitweight( - chan_db_info, self.params.bit_weight_opt + chan_db_info, self.main_window.bit_weight_opt ) self.set_axes_ylim(ax, min_y, max_y) @@ -310,15 +311,15 @@ class PlottingAxes: :param gaps: [[float, float], ] - list of [min, max] of gaps """ - if self.params.min_gap is None: + if self.main_window.min_gap is None: return - self.gaps = gaps = get_gaps(gaps, self.params.min_gap) + self.gaps = gaps = get_gaps(gaps, self.main_window.min_gap) self.parent.plotting_bot -= 0.003 self.parent.gap_bar = self.create_axes(self.parent.plotting_bot, 0.001, has_min_max_lines=False) - gap_label = f"GAP({self.params.min_gap}min)" + gap_label = f"GAP({self.main_window.min_gap}min)" h = 0.001 # height of rectangle represent gap self.set_axes_info(self.parent.gap_bar, [len(gaps)], label=gap_label) diff --git a/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py b/sohstationviewer/view/plotting/plotting_widget/plotting_widget.py index 6c3fd6eb8b7bd5a16e537ba9094701afda57befe..9cc7a78fbcbd701deedda58b3b3f1b1d912900aa 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_window: 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_window: Main window that keep all parameters set by user """ self.parent = parent + self.main_window = main_window 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_window) 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_window) """ 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 7e7435304e05dc3bee18bfa5a5b99afeae0496dd..4269c0e292b59538526941741200f679efbd0d19 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 8caef189bd178944d28719509201d33c5231ac1b..2705be48bf646ee3beb1622ad3f480a77b69265d 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_window.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 6361a28addc7e20d002d771e99892cae0dfabd69..ba9a2a2cd66f18d3658bacd72751b834901ff404 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 24702e91bfbc1e1eed45854df68e959cd6b4d698..005029668262238706fc02f0bf176aa25995df5e 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)