Source code for controllers.control_message_box

"""
This module contains the ControlMessageBox class which provides functionality for displaying various types of message
boxes in the MoilApp application.
"""
from PyQt6 import QtCore, QtWidgets

from PyQt6.QtWidgets import QPushButton


[docs] class ControlMessageBox: """ ControlMessageBox class provides functionality for displaying various types of message boxes in the MoilApp application. """ def __init__(self, main_controller): self._controller = main_controller self._model = main_controller.model self._ui_object = main_controller.ui_object
[docs] def display_ask_confirmation(self, message): """ Display a confirmation message box with the given message. Arg: message (str): The message to display in the confirmation box. Return: bool: True if the user clicks Yes, False if the user clicks No. """ if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: display_ask_confirmation(), " f"Display confirmation ask {message}") reply = QtWidgets.QMessageBox(self._controller) reply.setIcon(QtWidgets.QMessageBox.Icon.Question) reply.setWindowTitle("Question?") reply.setText(message) reply.setStyleSheet("color:black;") reply.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No) # Change button style yes_button = reply.button(QtWidgets.QMessageBox.StandardButton.Yes) yes_button.setText("Yes") yes_button.setMinimumWidth(50) yes_button.setMinimumHeight(25) yes_button.setStyleSheet("QPushButton{\n" " background-color : rgb(25, 200, 72);\n" " color : rgb(0, 0, 0);\n" " border-radius: 3px;}\n" "QPushButton:hover{\n" " background-color : rgb(0, 150, 50);\n" "}") no_button = reply.button(QtWidgets.QMessageBox.StandardButton.No) no_button.setText("No") no_button.setMinimumWidth(50) no_button.setMinimumHeight(25) no_button.setStyleSheet("QPushButton{\n" " background-color : rgb(210, 59, 72);\n" " color : rgb(0, 0, 0);\n" " border-radius: 3px;}\n" "QPushButton:hover{\n" " background-color : rgb(150, 100, 0);\n" "}") x = reply.exec() if x == QtWidgets.QMessageBox.StandardButton.Yes: return True return False
[docs] def display_message_box(self, message="Default Message!", type_mode="information"): """ Display a message box with the given message and type. Args: message (str): The message to display in the message box. Defaults to "Default Message!". type_mode (str): The type of message box to display. Should be either "information" or "warning". Defaults to "information". """ if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: display_message_box(), " f"Display message box about {message}") msg = QtWidgets.QMessageBox(self._controller) if type_mode == "information": msg.setIcon(QtWidgets.QMessageBox.Icon.Information) msg.setWindowTitle("Information!") elif type_mode == "warning": msg.setIcon(QtWidgets.QMessageBox.Icon.Warning) msg.setWindowTitle("Warning!") else: pass msg.setText(message) msg.setStyleSheet("color: black;") msg.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Ok) ok_button = msg.button(QtWidgets.QMessageBox.StandardButton.Ok) ok_button.setMinimumWidth(50) ok_button.setMinimumHeight(25) ok_button.setStyleSheet("QPushButton{\n" " background-color : rgb(25, 200, 72);\n" " color : rgb(0, 0, 0);\n" " border-radius: 3px;}\n" "QPushButton:hover{\n" " background-color : rgb(0, 150, 50);\n" "}") msg.show() def close_msg(): msg.done(0) QtCore.QTimer.singleShot(5000, close_msg)
[docs] def show_update_dialog(self, message): """ Display a message box with options for the user to choose. Arg: message: A string containing the message to be displayed in the message box. Return: An integer representing the user's response to the message box. """ if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: show_update_dialog(), " f"Show update dialog with message {message}") reply = QtWidgets.QMessageBox() reply.setWindowTitle("Update") reply.setText(message) reply.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Yes | QtWidgets.QMessageBox.StandardButton.No) return reply.exec()
[docs] def show_message_box_record(self): """ Display a message box for selecting the recording option (Original or Processed Video). Return: None """ if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: show_message_box_record(), " "Show message box for record video") message_box = QtWidgets.QMessageBox() message_box.setWindowTitle('Select Record') message_box.setText('Please select record option (Original or Processed Video)') message_box.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Cancel) pushbutton_record_ori = QPushButton('Record Original Video') pushbutton_record_ori.clicked.connect(self.record_original_video) message_box.addButton(pushbutton_record_ori, QtWidgets.QMessageBox.ButtonRole.ActionRole) pushbutton_record_pro = QPushButton('Record Processed Video') pushbutton_record_pro.clicked.connect(self.record_processed_video) message_box.addButton(pushbutton_record_pro, QtWidgets.QMessageBox.ButtonRole.ActionRole) cancel_button = message_box.button(QtWidgets.QMessageBox.StandardButton.Cancel) cancel_button.clicked.connect(self.record_cancel) message_box.exec()
[docs] def show_message_box_save_image(self): """ Display a message box for selecting the save option (Original or Processed Video). Return: None """ if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: show_message_box_save_image(), " "Show message box for save image") if self._model.image_result is not None: message_box = QtWidgets.QMessageBox() message_box.setWindowTitle('Select Save Image') message_box.setText('Please select Save option (Original or Processed Video)') message_box.setStandardButtons(QtWidgets.QMessageBox.StandardButton.Cancel) pushbutton_record_ori = QPushButton('Save Original Video') pushbutton_record_ori.clicked.connect(lambda: self._controller.ctrl_save_media.save_image_ori_result(False)) message_box.addButton(pushbutton_record_ori, QtWidgets.QMessageBox.ButtonRole.ActionRole) pushbutton_record_pro = QPushButton('Save Processed Video') pushbutton_record_pro.clicked.connect(lambda: self._controller.ctrl_save_media.save_image_ori_result(True)) message_box.addButton(pushbutton_record_pro, QtWidgets.QMessageBox.ButtonRole.ActionRole) cancel_button = message_box.button(QtWidgets.QMessageBox.StandardButton.Cancel) cancel_button.clicked.connect(self.record_cancel) message_box.exec()
[docs] def record_original_video(self): """ Set the recording option to "Original" and logs the action if debug mode is enabled. Return: None """ self._controller.ctrl_save_media.record_option = "Original" if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: record_original_video(), " "change record video to Original")
[docs] def record_processed_video(self): """ Set the recording option to "Processed" and logs the action if debug mode is enabled. Return: None """ self._controller.ctrl_save_media.record_option = "Processed" if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: record_processed_video(), " "change record video to Processed")
[docs] def record_cancel(self): """ Cancel the recording process by setting the recording option to None and logs the action if debug mode is enabled. Return: None """ self._controller.ctrl_save_media.record_option = None if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: record_cancel(), " "change record video to None")
[docs] def show_information_of_image(self, label): """ Display information about the current image view. Display a message box with information about the current image view, including whether it is a fisheye, anypoint, or panorama view. If the current view has a polygon drawn on it, the message box will indicate that the polygon is being shown and the user can change the ROI by clicking on the image. If the application is in zooming mode to view a specific ROI, a message box will be displayed indicating that the user should close the preview or press 'Esc' on the keyboard to return. Arg: label (str): The label of the current image view. """ if self._model.debug_mode: self._model.activity_logger.info(f"ControlMessageBox: show_information_of_image(), " f"Show information of image in label {label}") if self._model.view_zoom_area.state_rubberband: message = ("You're in zooming mode to see the specific ROI, \n" "close preview or press 'Esc' on the keyboard for return") self.display_message_box(message, "information") return info = "" if label == "label_result": if self._model.mode_view == "FisheyeView": info = "Window result: showing original fisheye image." elif self._model.mode_view == "AnypointView": mode = 1 if self._ui_object.radio_mode_1.isChecked() else 2 info = f"Window result: Showing Anypoint mode {mode} image" elif self._model.mode_view == "PanoramaView": mode = "car" if self._ui_object.radioButton_car.isChecked() else "Tube" info = f"Window result: ShowingPanorama {mode} image" elif label == "label_recenter": if self._model.mode_view == "FisheyeView": info = "Window recenter: Showing Original fisheye image after recenter the optical point" elif self._model.mode_view == "AnypointView": mode = 1 if self._ui_object.radio_mode_1.isChecked() else 2 info = (f"Window recenter: Showing Anypoint mode {mode} image, \n" f"based on recenter image with polygon. \n" "You can change the ROI by clicking this image!! ") elif self._model.mode_view == "PanoramaView": mode = "car" if self._ui_object.radioButton_car.isChecked() else "Tube" info = f"Window recenter: Showing original Panorama {mode} image" else: if self._controller.model.recenter_mode_view: info = ("Window original: showing fisheye image, \n" "You can adjust the optical center by clicking on \n" "the image below to set a new optical center.") else: if self._model.mode_view == "FisheyeView": info = "original fisheye image in label original" elif self._model.mode_view == "AnypointView": mode = 1 if self._ui_object.radio_mode_1.isChecked() else 2 info = (f"Showing original fisheye image with polygon\n" f"for showing anypoint mode {mode}. You can change\n" "the ROI by clicking this image!!") elif self._model.mode_view == "PanoramaView": mode = "car" if self._ui_object.adioButton_car.isChecked() else "tube" info = (f"Showing original fisheye image with polygon\n" f"for showing panorama {mode}. You can change\n" "the ROI by clicking this image!!") self.display_message_box(info, "information")
[docs] def show_accessibility(self): """ Open a prompt displaying accessibility shortcuts for MoilApp. Return: None """ if self._model.debug_mode: self._model.activity_logger.info("ControlMessageBox: show_accessibility(), " "Show accessibility shortcut action") message = ("MoilApp Accessibility\n" "###################\n\n" "Crtl + O\t: Open Image\n" "Ctrl + P\t: Open Camera parameters form\n" "Ctrl + R\t: Record Video\n" "Ctrl + S\t: Save image\n" "+ \t: Zoom In\n" "- \t: Zoom Out\n" "F11 \t: Maximized window\n" "Esc \t: Minimized window\n" "Space\t: play/pause video\n" "0 \t: Stop video\n" "Left\t: Backward video in 5 seconds\n" "Right\t: Forward video in 5 seconds\n" "Ctrl+Up\t\t: Up View in Anypoint Mode\n" "Ctrl+Right\t: Right View in Anypoint Mode\n" "Ctrl+Left\t: Left View in Anypoint Mode\n" "Ctrl+Down\t: Down View in Anypoint Mode\n" "Ctrl + A\t\t: Show Accessibility\n\n") self.display_message_box(message, "information")