Skip to content
Snippets Groups Projects
Commit 5aee7150 authored by Lan Dam's avatar Lan Dam
Browse files

Merge branch 'master' into i162_show_GPS_clock_0_when_no_data

parents 8e28e3b8 97d1eb58
No related branches found
No related tags found
1 merge request!180Make GPS Lk/Unlk and GPS Clock Power to plot in the same channel
Pipeline #3059 passed with stage
in 2 minutes and 57 seconds
This commit is part of merge request !180. Comments created here will be created in the context of that merge request.
...@@ -239,5 +239,5 @@ class DataLoader(QtCore.QObject): ...@@ -239,5 +239,5 @@ class DataLoader(QtCore.QObject):
:type button_labels: List[str] :type button_labels: List[str]
""" """
chosen_idx = create_multi_buttons_dialog( chosen_idx = create_multi_buttons_dialog(
msg, button_labels, abort_is_0=True) msg, button_labels, has_abort=False)
self.worker.button_chosen.emit(chosen_idx) self.worker.button_chosen.emit(chosen_idx)
...@@ -266,7 +266,7 @@ class GeneralData(): ...@@ -266,7 +266,7 @@ class GeneralData():
loaded. loaded.
""" """
msg = "Please select one of the following keys:" msg = "Please select one of the following keys:"
ret = create_multi_buttons_dialog(msg, self.keys, abort_is_0=False) ret = create_multi_buttons_dialog(msg, self.keys, has_abort=True)
if ret == -1: if ret == -1:
return False return False
self.selected_key = self.keys[ret] self.selected_key = self.keys[ret]
......
...@@ -4,16 +4,16 @@ from PySide2 import QtWidgets ...@@ -4,16 +4,16 @@ from PySide2 import QtWidgets
def create_multi_buttons_dialog( def create_multi_buttons_dialog(
msg: str, button_labels: List[str], abort_is_0) -> int: msg: str, button_labels: List[str], has_abort) -> int:
""" """
Create a modal dialog with buttons. Show the dialog and send the user's Create a modal dialog with buttons. Show the dialog and send the user's
choice to the data object being created. choice to the data object being created.
:param msg: the instruction shown to the user :param msg: the instruction shown to the user
:param button_labels: the list of labels that are shown on the buttons :param button_labels: the list of labels that are shown on the buttons
:param has_abort: flag to add Abort button or not
:return chosen_idx: index of selected button. If abort_button is selected, :return chosen_idx: index of selected button. If abort_button is selected,
return 0 if abort_is_0=True or -1 otherwise. return -1
""" """
msg_box = QtWidgets.QMessageBox() msg_box = QtWidgets.QMessageBox()
msg_box.setText(msg) msg_box.setText(msg)
...@@ -30,17 +30,14 @@ def create_multi_buttons_dialog( ...@@ -30,17 +30,14 @@ def create_multi_buttons_dialog(
buttons.append( buttons.append(
msg_box.addButton(label, QtWidgets.QMessageBox.ActionRole) msg_box.addButton(label, QtWidgets.QMessageBox.ActionRole)
) )
abort_button = msg_box.addButton(QtWidgets.QMessageBox.Abort) if has_abort:
abort_button = msg_box.addButton(QtWidgets.QMessageBox.Abort)
msg_box.exec_() msg_box.exec_()
if msg_box.clickedButton() == abort_button: try:
if abort_is_0: if msg_box.clickedButton() == abort_button:
# The default choice is the first item, so we default to it if the return -1
# user presses the abort button. An alternative choice is to stop except UnboundLocalError:
# when the user presses the abort button. pass
chosen_idx = 0 chosen_idx = buttons.index(msg_box.clickedButton())
else:
chosen_idx = -1
else:
chosen_idx = buttons.index(msg_box.clickedButton())
return chosen_idx return chosen_idx
...@@ -48,7 +48,7 @@ class SavePlotDialog(QDialog): ...@@ -48,7 +48,7 @@ class SavePlotDialog(QDialog):
if fmt == self.main_window.save_plot_format: if fmt == self.main_window.save_plot_format:
self.format_radio_btns[fmt].setChecked(True) self.format_radio_btns[fmt].setChecked(True)
self.cancel_btn = QtWidgets.QPushButton('CANCEL', self) self.cancel_btn = QtWidgets.QPushButton('CANCEL', self)
self.continue_btn = QtWidgets.QPushButton('SAVE PLOT', self) self.save_plot_btn = QtWidgets.QPushButton('SAVE PLOT', self)
self.setup_ui() self.setup_ui()
self.connect_signals() self.connect_signals()
...@@ -77,12 +77,12 @@ class SavePlotDialog(QDialog): ...@@ -77,12 +77,12 @@ class SavePlotDialog(QDialog):
rowidx += 1 rowidx += 1
main_layout.addWidget(self.cancel_btn, rowidx, 1, 1, 1) main_layout.addWidget(self.cancel_btn, rowidx, 1, 1, 1)
main_layout.addWidget(self.continue_btn, rowidx, 3, 1, 1) main_layout.addWidget(self.save_plot_btn, rowidx, 3, 1, 1)
def connect_signals(self) -> None: def connect_signals(self) -> None:
self.save_dir_btn.clicked.connect(self.change_save_directory) self.save_dir_btn.clicked.connect(self.change_save_directory)
self.cancel_btn.clicked.connect(self.close) self.cancel_btn.clicked.connect(self.close)
self.continue_btn.clicked.connect(self.on_continue) self.save_plot_btn.clicked.connect(self.save_plot)
@QtCore.Slot() @QtCore.Slot()
def change_save_directory(self) -> None: def change_save_directory(self) -> None:
...@@ -96,12 +96,12 @@ class SavePlotDialog(QDialog): ...@@ -96,12 +96,12 @@ class SavePlotDialog(QDialog):
fd.exec() fd.exec()
new_path = fd.selectedFiles()[0] new_path = fd.selectedFiles()[0]
self.save_dir_textbox.setText(new_path) self.save_dir_textbox.setText(new_path)
self.save_dir_path = new_path
self.main_window.save_plot_dir = new_path self.main_window.save_plot_dir = new_path
@QtCore.Slot() @QtCore.Slot()
def on_continue(self): def save_plot(self):
if self.save_dir_textbox.text().strip() == '': self.save_dir_path = self.save_dir_textbox.text().strip()
if self.save_dir_path == '':
QtWidgets.QMessageBox.warning( QtWidgets.QMessageBox.warning(
self, "Add Directory", self, "Add Directory",
"A directory need to be given before continue.") "A directory need to be given before continue.")
...@@ -121,6 +121,17 @@ class SavePlotDialog(QDialog): ...@@ -121,6 +121,17 @@ class SavePlotDialog(QDialog):
self.save_file_path = Path(self.save_dir_path).joinpath( self.save_file_path = Path(self.save_dir_path).joinpath(
f"{self.save_filename_textbox.text()}.{save_format}") f"{self.save_filename_textbox.text()}.{save_format}")
if not os.access(self.save_dir_path, os.W_OK):
self.save_file_path = None
QtWidgets.QMessageBox.information(
self, "No Write Permission",
"The directory to save file to doesn't have Write Permission."
"\n\nPlease change its permission or "
"select another directory."
)
return
self.dpi = self.dpi_line_edit.value() self.dpi = self.dpi_line_edit.value()
self.close() self.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment