diff --git a/sohstationviewer/view/select_channels_to_show_dialog.py b/sohstationviewer/view/select_channels_to_show_dialog.py new file mode 100644 index 0000000000000000000000000000000000000000..0d9b787eb1922358c3ad397ec23960a9f81e5794 --- /dev/null +++ b/sohstationviewer/view/select_channels_to_show_dialog.py @@ -0,0 +1,117 @@ +from typing import Dict, List + +from PySide6 import QtWidgets, QtCore +from PySide6.QtWidgets import ( + QDialog, QLabel, QFrame +) + + +def add_separation_line(layout): + """ + Add a line for separation to the given layout. + :param layout: QLayout - the layout that contains the line + """ + label = QLabel() + label.setFrameStyle(QFrame.Shape.HLine | QFrame.Shadow.Sunken) + label.setLineWidth(1) + layout.addWidget(label) + + +class SelectChanelsToShowDialog(QDialog): + def __init__(self, parent): + """ + Dialog allow choosing file format and open file dialog to + save file as + + :param parent: the parent widget + """ + super(SelectChanelsToShowDialog, self).__init__() + self.parent = parent + self.channel_checkboxes1 = self.create_chan_checkboxes( + self.parent.plotting_data1, self.parent.pref_order + ) + + self.channel_checkboxes2 = self.create_chan_checkboxes( + self.parent.plotting_data2, [] + ) + + self.cancel_btn = QtWidgets.QPushButton('CANCEL', self) + self.apply_btn = QtWidgets.QPushButton('APPLY', self) + + self.setup_ui() + self.connect_signals() + + def create_chan_checkboxes(self, channel_dict: Dict, + pref_order: List[str]): + """ + Create a checkbox for each channel in channel_dict with the order + according to pref_order if any and not show the channels that aren't + plotted + + :param channel_dict: dictionary of channel data + :param pref_order: list of preferred order of channels to be plotted + """ + chan_order = channel_dict.keys() + if pref_order: + chan_order = pref_order + channel_checkboxes = [] + for chan_id in chan_order: + chan_db_info = channel_dict[chan_id]['chan_db_info'] + if (chan_db_info['height'] == 0 or + chan_db_info['plotType'] == ''): + continue + chan_chkbox = QtWidgets.QCheckBox(chan_id, self) + if channel_dict[chan_id]['show']: + chan_chkbox.setChecked(True) + channel_checkboxes.append(chan_chkbox) + return channel_checkboxes + + def setup_ui(self) -> None: + self.setWindowTitle("Select Channels to Show") + + main_layout = QtWidgets.QVBoxLayout() + self.setLayout(main_layout) + + for chan_chkbox in self.channel_checkboxes1: + main_layout.addWidget(chan_chkbox) + + add_separation_line(main_layout) + + for chan_chkbox in self.channel_checkboxes2: + main_layout.addWidget(chan_chkbox) + + button_layout = QtWidgets.QHBoxLayout() + main_layout.addLayout(button_layout) + button_layout.addWidget(self.cancel_btn) + button_layout.addWidget(self.apply_btn) + + def connect_signals(self) -> None: + self.cancel_btn.clicked.connect(self.close) + self.apply_btn.clicked.connect(self.apply) + + @QtCore.Slot() + def apply(self) -> None: + """ + Change value of key 'show' according to the selections then replot + channels in parent widget + """ + for chan_chkbox in self.channel_checkboxes1: + chan_id = chan_chkbox.text() + self.parent.plotting_data1[chan_id]['show'] = \ + chan_chkbox.isChecked() + for chan_chkbox in self.channel_checkboxes2: + chan_id = chan_chkbox.text() + self.parent.plotting_data2[chan_id]['show'] = \ + chan_chkbox.isChecked() + + self.parent.clear() + self.parent.plot_channels( + self.parent.data_object, + self.parent.data_set_id, + self.parent.start_tm, + self.parent.end_tm, + self.parent.time_ticks_total, + self.parent.pref_order) + self.parent.draw() + + self.close()