Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • software_public/passoft/sohstationviewer
1 result
Show changes
Commits on Source (4)
Showing
with 132 additions and 110 deletions
## Plotting different key
There is a chance that the selected data set has more than one key defined by
station id in MSeed data or (network code, serial number) in Reftek.
<br />
Button "Plot Different Key" has been implemented to allow user select a
different key after data from selected files are plotted.
<br />
This button is disabled by default.
<br />
<img alt="Plot Different Key button disabled" src="images/plot_different_key/plot_different_key_button_disabled.png" height="60" />
<br />
After data are loaded, if the data set has more than one keys, user will be
asked to select one key to plot. User will click on one of the key buttons or
click Abort which will trigger plotting the first key by default.
<br />
<img alt="Select One Key to Display dialog" src="images/plot_different_key/select_one_key_to_display_dlg.png" height="120" />
<br />
The button "Plot Different Key" will be enabled.
<br />
<img alt="Plot Different Key button enabled" src="images/plot_different_key/plot_different_key_button_enabled.png" height="60" />
<br />
Now user can click on the button to access a dialog that allows user to select
another key for plotting. User can click on one of the key buttons to plot that
key's data set or click Abort to cancel.
<br />
<img alt="Select a Different Key to Replot" src="images/plot_different_key/select_a_different_key_to_replot_dlg.png" height="110" />
<br />
\ No newline at end of file
documentation/images/plot_different_key/select_one_key_to_display_dlg.png

31.6 KiB

No preview for this file type
......@@ -12,6 +12,8 @@ from sohstationviewer.controller.util import display_tracking_info
from sohstationviewer.model.general_data.general_data import (
GeneralData, ThreadStopped, ProcessingDataError)
from sohstationviewer.view.util.enums import LogType
from sohstationviewer.view.create_muti_buttons_dialog import (
create_multi_buttons_dialog)
class DataLoaderWorker(QtCore.QObject):
......@@ -223,31 +225,6 @@ class DataLoader(QtCore.QObject):
:param button_labels: the list of labels that are shown on the buttons
:type button_labels: List[str]
"""
msg_box = QtWidgets.QMessageBox()
msg_box.setText(msg)
buttons = []
for label in button_labels:
# RT130's labels have type Tuple[str, int], so we need to convert
# them to strings.
if not isinstance(label, str):
# When we convert a tuple to a string, any strings in the tuple
# will be surrounded by quotes in the result string. We remove
# those quotes before displaying them to the user for aesthetic
# reasons.
label = str(label).replace("'", '').replace('"', '')
buttons.append(
msg_box.addButton(label, QtWidgets.QMessageBox.ActionRole)
)
abort_button = msg_box.addButton(QtWidgets.QMessageBox.Abort)
msg_box.exec()
if msg_box.clickedButton() == abort_button:
# The default choice is the first item, so we default to it if the
# user presses the abort button. An alternative choice is to stop
# when the user presses the abort button.
chosen_idx = 0
else:
chosen_idx = buttons.index(msg_box.clickedButton())
chosen_idx = create_multi_buttons_dialog(
msg, button_labels, abort_is_0=True)
self.worker.button_chosen.emit(chosen_idx)
......@@ -19,6 +19,8 @@ from sohstationviewer.model.general_data.general_data_helper import \
retrieve_data_time_from_data_dict, retrieve_gaps_from_data_dict, \
combine_data, sort_data, squash_gaps, apply_convert_factor_to_data_dict, \
reset_data
from sohstationviewer.view.create_muti_buttons_dialog import (
create_multi_buttons_dialog)
class ProcessingDataError(Exception):
......@@ -232,13 +234,10 @@ class GeneralData():
def finalize_data(self):
"""
This function should be called after all folders finish reading to
+ Filling an empty_dict into station with no data added in
data_dicts
+ Sort all data traces in time order
+ Combine traces in data and split at gaps > gap_minimum
+ Apply convert_factor to avoid using flags to prevent double
applying convert factor when plotting
+ Check not found channels
+ Retrieve gaps from data_dicts
+ Retrieve data_time from data_dicts
+ Change data time with default value that are invalid for plotting
......@@ -259,6 +258,20 @@ class GeneralData():
self.data_time[self.selected_key] = \
[self.read_start, self.read_end]
def select_diff_key(self):
"""
The pop up allow user to choose one of the available keys for different
data set. This function is based on the assumption that
finalizing_data() has been performed for all data sets after they are
loaded.
"""
msg = "Please select one of the following keys:"
ret = create_multi_buttons_dialog(msg, self.keys, abort_is_0=False)
if ret == -1:
return False
self.selected_key = self.keys[ret]
return True
def __del__(self):
print("delete dataType Object")
try:
......
......@@ -375,8 +375,9 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
(soh_list_name_item, data_type_combobox,
soh_list_item, clear_widget) = self.get_row(row_idx)
if soh_list_item.text().strip() != "":
msg = ("Are you sure you want to delete the SOH channel list of "
"row #%s?" % (row_idx + 1))
msg = ("Are you sure you want to delete the SOH channel list "
f"{soh_list_name_item.text()} at soh_list_name_item row "
f"#{row_idx + 1}?")
result = QtWidgets.QMessageBox.question(
self, "Confirmation", msg,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
......@@ -561,7 +562,6 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
self.parent.pref_soh_list = []
self.parent.pref_soh_list_name = ''
self.parent.pref_soh_list_data_type = 'Unknown'
return True
ret = trunc_add_db('ChannelPrefer', sql_list)
if ret is not True:
......
from typing import List
from PySide6 import QtWidgets
def create_multi_buttons_dialog(
msg: str, button_labels: List[str], abort_is_0) -> int:
"""
Create a modal dialog with buttons. Show the dialog and send the user's
choice to the data object being created.
:param msg: the instruction shown to the user
:param button_labels: the list of labels that are shown on the buttons
:return chosen_idx: index of selected button. If abort_button is selected,
return 0 if abort_is_0=True or -1 otherwise.
"""
msg_box = QtWidgets.QMessageBox()
msg_box.setText(msg)
buttons = []
for label in button_labels:
# RT130's labels have type Tuple[str, int], so we need to convert
# them to strings.
if not isinstance(label, str):
# When we convert a tuple to a string, any strings in the tuple
# will be surrounded by quotes in the result string. We remove
# those quotes before displaying them to the user for aesthetic
# reasons.
label = str(label).replace("'", '').replace('"', '')
buttons.append(
msg_box.addButton(label, QtWidgets.QMessageBox.ActionRole)
)
abort_button = msg_box.addButton(QtWidgets.QMessageBox.Abort)
msg_box.exec_()
if msg_box.clickedButton() == abort_button:
if abort_is_0:
# The default choice is the first item, so we default to it if the
# user presses the abort button. An alternative choice is to stop
# when the user presses the abort button.
chosen_idx = 0
else:
chosen_idx = -1
else:
chosen_idx = buttons.index(msg_box.clickedButton())
return chosen_idx
......@@ -399,6 +399,13 @@ class MainWindow(QtWidgets.QMainWindow, UIMainWindow):
except IndexError:
pass
@QtCore.Slot()
def plot_diff_key(self):
if not self.data_object.select_diff_key():
return
self.clear_plots()
self.replot_loaded_data()
def get_requested_wf_chans(self) -> List[Union[str, int]]:
"""
Getting requested data stream for RT130 data or mseed wildcards for
......@@ -533,6 +540,7 @@ class MainWindow(QtWidgets.QMainWindow, UIMainWindow):
Read data from selected files/directories, process and plot channels
read from those according to current options set on the GUI
"""
self.plot_diff_key_button.setEnabled(False)
display_tracking_info(self.tracking_info_text_browser,
"Loading started",
LogType.INFO)
......@@ -887,6 +895,8 @@ class MainWindow(QtWidgets.QMainWindow, UIMainWindow):
self.is_plotting_waveform = False
self.is_plotting_tps = False
self.is_stopping = False
if len(self.data_object.keys) > 1:
self.plot_diff_key_button.setEnabled(True)
@QtCore.Slot()
def reset_is_plotting_waveform(self):
......
import sys
import platform
import os
from PySide6 import QtWidgets, QtCore
from functools import partial
class SelectButtonDialog(QtWidgets.QDialog):
def __init__(self, parent=None, message='',
button_labels=['test1', 'test2']):
"""
Create dialog that have buttons from the given labels and show the
given message.
Click on a button will close the dialog and the index of the clicked
button can be retrieved in obj.ret
:param parent: QMainWindow/QWidget - the parent widget
:param message: str - Instruction for user
:param button_labels: [str,] - list of buttons' labels
"""
super(SelectButtonDialog, self).__init__(parent)
self.ret = -1
height = int(50 * (1 + len(button_labels) / 3))
self.setGeometry(100, 100, 900, height)
main_layout = QtWidgets.QVBoxLayout()
self.setLayout(main_layout)
label = QtWidgets.QLabel(message)
main_layout.addWidget(label, 0)
buttons_layout = QtWidgets.QGridLayout()
main_layout.addLayout(buttons_layout)
buttons = []
r = -1
for idx, label in enumerate(button_labels):
c = idx % 3
if c == 0:
r += 1
buttons.append(QtWidgets.QPushButton(label))
buttons[idx].clicked.connect(partial(self.button_click, idx))
buttons_layout.addWidget(buttons[idx], r, c)
@QtCore.Slot()
def button_click(self, idx):
"""
When a button is clicked, assign self.ret to the index of the button.
and close the dialog
:param idx: int - index of the button
"""
self.ret = idx
self.close()
if __name__ == '__main__':
os_name, version, *_ = platform.platform().split('-')
if os_name == 'macOS':
os.environ['QT_MAC_WANTS_LAYER'] = '1'
app = QtWidgets.QApplication(sys.argv)
test = SelectButtonDialog(None, "Testing result from buttons",
['test01', 'test02', 'test03',
'test11', 'test12', 'test13'])
test.exec()
print("return Code:", test.ret)
sys.exit(app.exec())
......@@ -529,19 +529,27 @@ class UIMainWindow(object):
self.curr_pref_soh_list_name_txtbox.setReadOnly(True)
chan_layout.addWidget(self.curr_pref_soh_list_name_txtbox)
submit_layout = QHBoxLayout()
submit_layout = QGridLayout()
submit_layout.setSpacing(5)
left_layout.addLayout(submit_layout)
self.read_button = QPushButton('Read', self.central_widget)
self.read_button = QPushButton('Read Files', self.central_widget)
self.read_button.setToolTip('Read selected files')
submit_layout.addWidget(self.read_button)
submit_layout.addWidget(self.read_button, 0, 0)
self.plot_diff_key_button = QPushButton(
'Plot Different Key', self.central_widget)
self.plot_diff_key_button.setToolTip('Plot different key of data set')
self.plot_diff_key_button.setEnabled(False)
submit_layout.addWidget(self.plot_diff_key_button, 0, 1)
self.stop_button = QPushButton('Stop', self.central_widget)
self.stop_button.setToolTip('Halt ongoing read')
submit_layout.addWidget(self.stop_button)
submit_layout.addWidget(self.stop_button, 1, 0)
self.save_plot_button = QPushButton(
'Save plot', self.central_widget)
self.save_plot_button.setToolTip('Save plots to disk')
submit_layout.addWidget(self.save_plot_button)
submit_layout.addWidget(self.save_plot_button, 1, 1)
self.info_list_widget = FileInfoWidget(self.central_widget)
self.info_list_widget.setSelectionMode(
......@@ -790,7 +798,9 @@ class UIMainWindow(object):
self.select_pref_soh_list_button.clicked.connect(
main_window.open_channel_preferences)
self.read_button.clicked.connect(main_window.read_selected_files)
self.plot_diff_key_button.clicked.connect(main_window.plot_diff_key)
self.stop_button.clicked.connect(main_window.stop)
......@@ -805,14 +815,14 @@ class UIMainWindow(object):
from_data_card = False
data = False
sdata = False
[ColorMode]
black = True
white = False
[Gap]
min_gap_length =
[Channels]
mp123zne = False
mp456uvw = False
......@@ -828,7 +838,7 @@ class UIMainWindow(object):
mseed_wildcard =
plot_tps = False
plot_raw = False
[ChannelsPreference]
all_soh = True
pref_code =
......