"""
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_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")