diff --git a/arcjetCV/gui/main_window.py b/arcjetCV/gui/main_window.py index c422f53..6593b97 100644 --- a/arcjetCV/gui/main_window.py +++ b/arcjetCV/gui/main_window.py @@ -8,7 +8,7 @@ from PySide6 import QtWidgets from PySide6.QtWidgets import QMessageBox from PySide6.QtCore import Signal -from PySide6.QtGui import QPixmap, QIcon +from PySide6.QtGui import QIcon import matplotlib.pyplot as plt from matplotlib.colors import rgb_to_hsv from matplotlib.widgets import RectangleSelector @@ -32,6 +32,8 @@ def __init__(self): # Initialize the user interface self.ui = Ui_MainWindow() self.ui.setupUi(self) + + self.testing = False # Set the application icon self.logo_path = os.path.join( @@ -403,12 +405,14 @@ def load_video(self): self.NEW_VIDEO = False except Exception as e: - print("Could not load video") - msg = QMessageBox() - msg.setWindowTitle("arcjetCV Warning") - msg.setText("! Could not load video !:\n" + str(e)) - msg.setIcon(QMessageBox.Critical) - msg.exec() + if self.testing: + print("Could not load video") + else: + msg = QMessageBox() + msg.setWindowTitle("arcjetCV Warning") + msg.setText("! Could not load video !:\n" + str(e)) + msg.setIcon(QMessageBox.Critical) + msg.exec() def plot_location(self, reset=False): n = self.ui.spinBox_FrameIndex.value() @@ -467,11 +471,14 @@ def process_all(self): ) # Create a message box - self.msg_box = QMessageBox() - self.msg_box.setWindowTitle("Video Processed") - self.msg_box.setText("The video has been processed.") - self.msg_box.setIcon(QMessageBox.Information) - self.msg_box.exec() # Display the message box + if self.testing: + print("The video has been processed.") + else: + self.msg_box = QMessageBox() + self.msg_box.setWindowTitle("Video Processed") + self.msg_box.setText("The video has been processed.") + self.msg_box.setIcon(QMessageBox.Information) + self.msg_box.exec() # Display the message box def grab_ui_values(self): inputdict = {"SEGMENT_METHOD": str(self.ui.comboBox_filterType.currentText())} @@ -539,9 +546,10 @@ def load_outputs(self): self.ui.basebar.setText("Finished loading files") except Exception as e: - QMessageBox.warning( - None, "Warning", "!!! File loading failed !!!:\n" + str(e) - ) + if self.testing: + print("!!! File loading failed !!!:\n" + str(e)) + else: + QMessageBox.warning(None, "Warning", "!!! File loading failed !!!:\n" + str(e)) self.plot_outputs() @@ -797,16 +805,17 @@ def plot_outputs(self): self.ui.basebar.setText("Finished plotting data") else: self.ui.basebar.setText("Not enough data to plot") - QMessageBox.warning( - None, - "Warning", - "!!! Not enough data to plot !!!: only %i points" - % len(self.raw_outputs), - ) + if self.testing: + print("Not enough data to plot") + else: + QMessageBox.warning(None, "Warning", "!!! Not enough data to plot !!!: only %i points" % len(self.raw_outputs)) except Exception as e: self.ui.basebar.setText("!!! Plotting failed !!!") - QMessageBox.warning(None, "Warning", "!!! Plotting failed !!!:\n" + str(e)) + if self.testing: + print("Warning", "!!! Plotting failed !!!:\n" + str(e)) + else: + QMessageBox.warning(None, "Warning", "!!! Plotting failed !!!:\n" + str(e)) self.ui.Window1.repaint() self.ui.Window2.repaint() @@ -853,9 +862,10 @@ def save_plots(self, name): except Exception as e: self.ui.basebar.setText("!!! Plot saving failed !!!") - QMessageBox.warning( - None, "Warning", "!!! Plot saving failed !!!:\n" + str(e) - ) + if self.testing: + print("Warning", "!!! Plot saving failed !!!:\n" + str(e)) + else: + QMessageBox.warning(None, "Warning", "!!! Plot saving failed !!!:\n" + str(e)) def export_to_csv(self): if self.time_series is not None: @@ -909,9 +919,10 @@ def export_to_csv(self): except Exception as e: self.ui.basebar.setText("!!! CSV export failed !!!") - QMessageBox.warning( - None, "Warning", "!!! CSV export failed !!!:\n" + str(e) - ) + if self.testing: + print("Warning", "!!! CSV export failed !!!:\n" + str(e)) + else: + QMessageBox.warning(None, "Warning", "!!! CSV export failed !!!:\n" + str(e)) def fit_data(self): if self.time_series is not None: @@ -969,6 +980,7 @@ def fit_data(self): except Exception as e: self.ui.basebar.setText("!!! Fitting failed !!!") - QMessageBox.warning( - None, "Warning", "!!! Fitting failed !!!:\n" + str(e) - ) + if self.testing: + print("Warning", "!!! Fitting failed !!!:\n" + str(e)) + else: + QMessageBox.warning(None, "Warning", "!!! Fitting failed !!!:\n" + str(e)) diff --git a/tests/test_gui.py b/tests/test_gui.py index 8c0af28..1175e0b 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -19,6 +19,7 @@ def find_test_video_path(): def app(qtbot): test_app = QApplication.instance() if QApplication.instance() else QApplication([]) window = MainWindow() + window.testing = True qtbot.addWidget(window) window.hide() return window