From cb8efaff6f37d0c90952392aee6a68619a2a9279 Mon Sep 17 00:00:00 2001 From: ldam <ldam@passcal.nmt.edu> Date: Mon, 4 Mar 2024 10:26:15 -0700 Subject: [PATCH] add context menu and call SelectChannelToShowDialog so user can decide which channels to be displayed --- .../multi_threaded_plotting_widget.py | 17 ++++++++++++++++- .../view/plotting/state_of_health_widget.py | 5 ++++- .../view/plotting/waveform_dialog.py | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 2 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 486ae6f43..13d86b832 100644 --- a/sohstationviewer/view/plotting/plotting_widget/multi_threaded_plotting_widget.py +++ b/sohstationviewer/view/plotting/plotting_widget/multi_threaded_plotting_widget.py @@ -21,6 +21,9 @@ from sohstationviewer.conf import constants as const from sohstationviewer.database.extract_data import get_chan_plot_info +from sohstationviewer.view.select_channels_to_show_dialog import \ + SelectChanelsToShowDialog + class MultiThreadedPlottingWidget(PlottingWidget): finished = QtCore.Signal() @@ -70,7 +73,6 @@ class MultiThreadedPlottingWidget(PlottingWidget): :param is_waveform: True if this is a WaveformWidget, otherwise False """ self.zoom_marker1_shown = False - self.data_set_id = data_set_id self.processing_log = [] # [(message, type)] self.gaps = d_obj.gaps[data_set_id] self.gap_bar = None @@ -125,6 +127,7 @@ class MultiThreadedPlottingWidget(PlottingWidget): chan_order, list(plotting_data.keys())) chan_order = remove_not_found_chans( chan_order, list(plotting_data.keys()), self.processing_log) + self.pref_order = chan_order not_plot_chans = [] for chan_id in chan_order: @@ -178,6 +181,9 @@ class MultiThreadedPlottingWidget(PlottingWidget): for chan_id in chan_order: if 'chan_db_info' not in plotting_data[chan_id]: continue + if ('show' in plotting_data[chan_id] and + not plotting_data[chan_id]['show']): + continue channel_processor = PlottingChannelProcessor( plotting_data[chan_id], chan_id, self.min_x, self.max_x, @@ -205,6 +211,11 @@ class MultiThreadedPlottingWidget(PlottingWidget): :param time_ticks_total: max number of tick to show on time bar :param pref_order: order of channels to be plotted """ + self.data_object = d_obj + self.data_set_id = data_set_id + self.start_tm = start_tm + self.end_tm = end_tm + self.time_ticks_total = time_ticks_total self.pref_order = pref_order if not self.is_working: self.reset_widget() @@ -341,3 +352,7 @@ class MultiThreadedPlottingWidget(PlottingWidget): f'{self.name} plot stopped', LogType.INFO) self.is_working = False self.stopped.emit() + + def select_channels_to_show(self): + win = SelectChanelsToShowDialog(self) + win.exec() diff --git a/sohstationviewer/view/plotting/state_of_health_widget.py b/sohstationviewer/view/plotting/state_of_health_widget.py index f9743033a..f04074c95 100644 --- a/sohstationviewer/view/plotting/state_of_health_widget.py +++ b/sohstationviewer/view/plotting/state_of_health_widget.py @@ -81,6 +81,10 @@ class SOHWidget(MultiThreadedPlottingWidget): return context_menu = QtWidgets.QMenu(self) + select_channels_to_show_action = context_menu.addAction( + "Select Channels to show") + select_channels_to_show_action.triggered.connect( + self.select_channels_to_show) try: add_edit_chan_action = context_menu.addAction(add_edit_action_str) add_edit_chan_action.triggered.connect(self.add_edit_channel) @@ -106,7 +110,6 @@ class SOHWidget(MultiThreadedPlottingWidget): :param end_tm: requested end time to read :param time_ticks_total: max number of tick to show on time bar """ - self.data_object = d_obj self.plotting_data1 = ( d_obj.soh_data[data_set_id] if data_set_id else {}) self.plotting_data2 = ( diff --git a/sohstationviewer/view/plotting/waveform_dialog.py b/sohstationviewer/view/plotting/waveform_dialog.py index ca0c51ee5..31aebfae3 100755 --- a/sohstationviewer/view/plotting/waveform_dialog.py +++ b/sohstationviewer/view/plotting/waveform_dialog.py @@ -16,6 +16,20 @@ class WaveformWidget(MultiThreadedPlottingWidget): def __init__(self, *args, **kwargs): MultiThreadedPlottingWidget.__init__(self, *args, **kwargs) + def contextMenuEvent(self, event): + """ + Create menu showing up when right click mouse to add/edit channel + """ + + context_menu = QtWidgets.QMenu(self) + select_channels_to_show_action = context_menu.addAction( + "Select Channels to show") + select_channels_to_show_action.triggered.connect( + self.select_channels_to_show) + + context_menu.exec_(self.mapToGlobal(event.pos())) + self.curr_ax = None # to make sure curr_ax is clear + def init_plot(self, d_obj: GeneralData, data_set_id: Union[str, Tuple[str, str]], start_tm: float, end_tm: float, time_ticks_total: int): -- GitLab