Skip to content

Commit

Permalink
Adding testing variable to main_window to avoid opening popups
Browse files Browse the repository at this point in the history
  • Loading branch information
fedesemeraro committed Mar 11, 2024
1 parent 017b249 commit 61d7f50
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
74 changes: 43 additions & 31 deletions arcjetCV/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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())}
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))
1 change: 1 addition & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 61d7f50

Please sign in to comment.