From 8f2c122312c7f556507251f7d3c79eeb027fe634 Mon Sep 17 00:00:00 2001 From: ldam <ldam@passcal.nmt.edu> Date: Thu, 7 Mar 2024 16:36:06 -0700 Subject: [PATCH] use number_channel_found to decide opening contextMenu or not --- .../multi_threaded_plotting_widget.py | 10 ++++++---- .../view/plotting/state_of_health_widget.py | 18 +++++++++++------- .../view/plotting/waveform_dialog.py | 3 ++- 3 files changed, 19 insertions(+), 12 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 397361e17..19f0e158d 100644 --- a/sohstationviewer/view/plotting/plotting_widget/multi_threaded_plotting_widget.py +++ b/sohstationviewer/view/plotting/plotting_widget/multi_threaded_plotting_widget.py @@ -33,6 +33,8 @@ class MultiThreadedPlottingWidget(PlottingWidget): def __init__(self, *args, **kwargs): PlottingWidget.__init__(self, *args, **kwargs) self.data_processors: List[PlottingChannelProcessor] = [] + # total number of channels found + self.number_channel_found = 0 # order of channels to be plotted self.pref_order: List[str] = [] # object of data to be plotted @@ -89,12 +91,12 @@ class MultiThreadedPlottingWidget(PlottingWidget): self.min_x = max(data_time[0], start_tm) self.max_x = min(data_time[1], end_tm) self.plot_total = len(self.plotting_data1) + len(self.plotting_data2) - number_channel_found = len(self.plotting_data1) + self.number_channel_found = len(self.plotting_data1) name = self.name if not is_waveform: - number_channel_found += len(self.plotting_data2) + self.number_channel_found += len(self.plotting_data2) name += " DATA OR MASS POSITION" - if number_channel_found == 0: + if self.number_channel_found == 0: self.title = f"NO {name} DATA TO DISPLAY." self.processing_log.append( (f"No {name} data to display.", LogType.INFO)) @@ -106,7 +108,7 @@ class MultiThreadedPlottingWidget(PlottingWidget): self.plotting_bot = const.BOTTOM self.axes = [] - if number_channel_found == 0: + if self.number_channel_found == 0: # set_size and plot timestamp_bar for the title's position self.set_size() self.timestamp_bar_top = self.plotting_axes.add_timestamp_bar( diff --git a/sohstationviewer/view/plotting/state_of_health_widget.py b/sohstationviewer/view/plotting/state_of_health_widget.py index 0858a7f56..965818e1d 100644 --- a/sohstationviewer/view/plotting/state_of_health_widget.py +++ b/sohstationviewer/view/plotting/state_of_health_widget.py @@ -65,6 +65,15 @@ class SOHWidget(MultiThreadedPlottingWidget): """ Create menu showing up when right click mouse to add/edit channel """ + if self.number_channel_found == 0: + 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: if '?' in self.curr_ax.chan_db_info['dbChannel']: warning_action_str = ( @@ -78,13 +87,8 @@ class SOHWidget(MultiThreadedPlottingWidget): else: add_edit_action_str = f"Edit channel {self.curr_ax.chan}" except AttributeError: - return + pass - 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) @@ -97,7 +101,7 @@ class SOHWidget(MultiThreadedPlottingWidget): context_menu.exec_(self.mapToGlobal(event.pos())) self.curr_ax = None # to make sure curr_ax is clear - return super(SOHWidget, self).resizeEvent(event) + return super(SOHWidget, self).contextMenuEvent(event) def init_plot(self, d_obj: GeneralData, data_set_id: Union[str, Tuple[str, str]], diff --git a/sohstationviewer/view/plotting/waveform_dialog.py b/sohstationviewer/view/plotting/waveform_dialog.py index 21782e308..c0a4ca31e 100755 --- a/sohstationviewer/view/plotting/waveform_dialog.py +++ b/sohstationviewer/view/plotting/waveform_dialog.py @@ -20,7 +20,8 @@ class WaveformWidget(MultiThreadedPlottingWidget): """ Create menu showing up when right click mouse to add/edit channel """ - + if self.number_channel_found == 0: + return context_menu = QtWidgets.QMenu(self) select_channels_to_show_action = context_menu.addAction( "Select Channels to show") -- GitLab