import webbrowser
from PyQt6 import QtCore, QtWidgets
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QCursor, QIcon
[docs]
class MouseEvent:
def __init__(self, controller):
self._controller = controller
self._model = controller.model
self._main_config = controller.model.main_config
self._moildev = controller.model.set_moildev
self._ui_object = self._controller.ui_object
self._rubberband = QtWidgets.QRubberBand(QtWidgets.QRubberBand.Shape.Rectangle, self._ui_object.label_result)
self._ratio_label_ori = [0, 0]
self._connect_signals()
def _connect_signals(self):
self._ui_object.label_logo.mousePressEvent = self.mouse_event_in_moil_logo
self._ui_object.label_image_original.mouseReleaseEvent = self.label_original_mouse_release_event
self._ui_object.label_image_original.mouseMoveEvent = self.label_original_mouse_move_event
self._ui_object.label_image_original.mousePressEvent = self.label_original_mouse_press_event
self._ui_object.label_image_original.leaveEvent = self.label_original_mouse_leave_event
self._ui_object.label_image_original.mouseDoubleClickEvent = self.label_original_mouse_double_click_event
self._ui_object.label_result.mouseDoubleClickEvent = self.label_result_mouse_double_click
self._ui_object.label_result.mousePressEvent = self.label_result_mouse_press_event
self._ui_object.label_result.mouseMoveEvent = self.label_result_mouse_move_event
self._ui_object.label_result.mouseReleaseEvent = self.label_result_mouse_release_event
self._ui_object.label_image_recenter.mouseReleaseEvent = self.label_recenter_mouse_release_event
self._ui_object.label_image_recenter.mousePressEvent = self.label_recenter_mouse_press_event
self._ui_object.label_image_recenter.mouseMoveEvent = self.label_recenter_mouse_move_event
self._ui_object.label_image_recenter.leaveEvent = self.label_recenter_mouse_leave_event
self._ui_object.label_image_recenter.mouseDoubleClickEvent = self.label_original_mouse_double_click_event
[docs]
def calculate_ratio_label_ori(self):
"""
Calculate the ratio of label to original image dimensions.
"""
self._ratio_label_ori[0], self._ratio_label_ori[1] = (
self._model.calculate_ratio_image2label(self._ui_object.label_image_original,
self._model.image_ori_used))
[docs]
def mouse_event_in_moil_logo(self, event):
"""
Handle mouse events in the Moil logo.
Args:
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: mouse_event_in_moil_logo(), "
"Back to Home page")
if event.type() == QtCore.QEvent.Type.MouseButtonPress:
if event.button() == QtCore.Qt.MouseButton.LeftButton:
self._controller.ctrl_panel_page.button_menu(220, True)
self._controller.back_to_home()
elif event.button() == QtCore.Qt.MouseButton.RightButton:
# Create a QMenu for right-click context menu
menu = QtWidgets.QMenu()
doc_action = menu.addAction("Read the documentation")
# Connect triggered action of "Read the doc" menu item
doc_action.triggered.connect(lambda: webbrowser.open(
r'https://perseverance-tech-tw.github.io/moilapp-doc/latest/index.html', new=2))
# Show the context menu at the global position of the event
menu.exec(event.globalPosition().toPoint())
[docs]
def label_original_mouse_release_event(self, event):
"""
Handle mouse release events on the original image label.
Arg:
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_original_mouse_release_event(), "
"Mouse even release for label_original")
if event.button() == QtCore.Qt.MouseButton.RightButton:
self.menu_mouse_event(event, "label_original")
[docs]
def label_original_mouse_move_event(self, event):
"""
Handle mouse move events on the original image label.
Arg:
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_original_mouse_move_event(), "
"Mouse event move for label_original")
if self._model.image_original is None or self._model.view_zoom_area.state_rubberband or self._model.saving_media.load_saved_image:
return
self.calculate_ratio_label_ori()
x = round(int(event.position().x()) * self._ratio_label_ori[0])
y = round(int(event.position().y()) * self._ratio_label_ori[1])
self.set_value_coordinate_image_original(x, y)
if event.buttons() == Qt.MouseButton.NoButton:
if self._controller.model.source_usable and self._moildev.moildev_main is not None:
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y)
else:
alpha, beta = 0, 0
self._main_config["Image_original"]["pointer"] = [x, y]
if self._model.mode_view == "AnypointView":
self._controller.ui_object.label_image_original.setCursor(
QCursor(Qt.CursorShape.PointingHandCursor))
if self._controller.model.source_usable and self._moildev.moildev_main is not None:
if self._model.view_anypoint.anypoint_mode == "mode_1":
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 1)
else:
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 2)
else:
alpha, beta = 0, 0
self.show_alpha_beta_label_original(alpha, beta)
self._controller.ctrl_img_ori.create_image_original()
elif event.buttons() == Qt.MouseButton.LeftButton:
if self._model.mode_view == "AnypointView":
self._controller.ui_object.label_image_original.setCursor(QCursor(Qt.CursorShape.ClosedHandCursor))
if self._model.view_anypoint.anypoint_mode == "mode_1":
self._main_config["Mode_1"]["coord"] = x, y
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 1)
if alpha is not None:
self._main_config["Mode_1"]["alpha"] = round(alpha, 2)
self._main_config["Mode_1"]["beta"] = round(beta, 2)
self.show_alpha_beta_label_original(alpha, beta)
self._model.view_anypoint.create_maps_anypoint_mode_1()
else:
self._main_config["Mode_2"]["coord"] = x, y
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 2)
if alpha is not None:
self._main_config["Mode_2"]["pitch"] = round(alpha, 2)
self._main_config["Mode_2"]["yaw"] = round(beta, 2)
self.show_alpha_beta_label_original(alpha, beta)
self._model.view_anypoint.create_maps_anypoint_mode_2()
self._controller.model.save_main_config_update()
self.show_alpha_beta_label_original(alpha, beta)
self._controller.display_image_to_ui()
[docs]
def label_original_mouse_press_event(self, event):
"""
Handle mouse press events on the original image label.
Arg:
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_original_mouse_press_event(), "
"Mouse press for label_original")
if event.buttons() == QtCore.Qt.MouseButton.LeftButton:
if self._model.image_original is not None:
self.calculate_ratio_label_ori()
pos_x = round(int(event.position().x()) * self._ratio_label_ori[0])
pos_y = round(int(event.position().y()) * self._ratio_label_ori[1])
if self._controller.model.recenter_mode_view:
self._main_config["Image_recenter"]["Recenter_coordinate"] = [pos_x, pos_y]
self._model.view_recenter.create_maps_recenter()
self._controller.view_recenter.create_image_recenter()
if self._model.mode_view == "AnypointView":
self._controller.view_anypoint.change_mode_anypoint()
else:
if self._model.mode_view == "AnypointView":
if self._model.view_anypoint.anypoint_mode == "mode_1":
self._main_config["Mode_1"]["coord"] = [pos_x, pos_y]
alpha, beta = self._moildev.moildev_main.get_alpha_beta(pos_x,pos_y, 1)
if alpha is not None:
self._main_config["Mode_1"]["alpha"] = round(alpha, 1)
self._main_config["Mode_1"]["beta"] = round(beta, 1)
self._model.view_anypoint.create_maps_anypoint_mode_1()
self._controller.view_anypoint.showing_config_mode_1()
else:
self._main_config["Mode_2"]["coord"] = pos_x, pos_y
alpha, beta = self._moildev.moildev_main.get_alpha_beta(pos_x, pos_y, 2)
if alpha is not None:
self._main_config["Mode_2"]["pitch"] = round(alpha, 2)
self._main_config["Mode_2"]["yaw"] = round(beta, 2)
self._model.view_anypoint.create_maps_anypoint_mode_2()
self._controller.view_anypoint.showing_config_mode_2()
elif self._model.mode_view == "PanoramaView":
if self._controller.ui_object.radioButton_car.isChecked():
self._main_config["Pano_car"]["coord"] = pos_x, pos_y
alpha, beta = self._moildev.moildev_main.get_alpha_beta(pos_x, pos_y, 1)
if alpha is not None:
self._main_config["Pano_car"]["alpha"] = round(alpha, 2)
self._main_config["Pano_car"]["beta"] = round(beta, 2)
self._model.view_panorama.create_maps_panorama_car()
self._controller.view_panorama.showing_config_panorama_car()
self._model.save_main_config_update()
self._controller.display_image_to_ui()
[docs]
def label_original_mouse_leave_event(self, event):
"""
Handle the mouse leave event on the original image label.
This method is called when the mouse leaves the original image label in the
UI. It delegates the handling of the event to the model_apps instance of the
Model class.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_original_mouse_leave_event(), "
"Mouse leave even for label_original")
if self._model.image_original is None: # original is image resize
return
if self._model.view_zoom_area.state_rubberband:
return
if self._model.saving_media.load_saved_image:
return
if self._controller.model.recenter_mode_view:
if self._model.mode_view == "FisheyeView":
self.set_value_coordinate_image_original(
self._model.main_config["Image_original"]["center_coord"][0],
self._model.main_config["Image_original"]["center_coord"][1])
else:
self.set_value_coordinate_image_original(
self._model.main_config["Image_recenter"]["Recenter_coordinate"][0],
self._model.main_config["Image_recenter"]["Recenter_coordinate"][1])
icx, icy = self._model.main_config["Image_recenter"]["Recenter_coordinate"]
alpha, beta = self._moildev.moildev_recenter.get_alpha_beta(icx, icy)
self.show_alpha_beta_label_original(alpha, beta)
else:
if self._model.mode_view == "AnypointView":
if self._controller.ui_object.radio_mode_1.isChecked():
alpha = self._model.main_config["Mode_1"]["alpha"]
beta = self._model.main_config["Mode_1"]["beta"]
self.set_value_coordinate_image_original(self._model.main_config["Mode_1"]["coord"][0],
self._model.main_config["Mode_1"]["coord"][1])
else:
alpha = self._model.main_config["Mode_2"]["pitch"]
beta = self._model.main_config["Mode_2"]["yaw"]
self.set_value_coordinate_image_original(self._model.main_config["Mode_2"]["coord"][0],
self._model.main_config["Mode_2"]["coord"][1])
self.show_alpha_beta_label_original(alpha, beta)
elif self._model.mode_view == "PanoramaView":
if self._controller.ui_object.radioButton_car.isChecked():
alpha = self._model.main_config["Pano_car"]["alpha"]
beta = self._model.main_config["Pano_car"]["beta"]
self.set_value_coordinate_image_original(self._model.main_config["Pano_car"]["coord"][0],
self._model.main_config["Pano_car"]["coord"][1])
self.show_alpha_beta_label_original(alpha, beta)
else:
alpha, beta = 0, 0
self.set_value_coordinate_image_original(self._model.main_config["Image_original"]["center_coord"][0],
self._model.main_config["Image_original"]["center_coord"][1])
self.show_alpha_beta_label_original(alpha, beta)
self._main_config["Image_original"]["pointer"] = [None, None]
self._controller.ctrl_img_ori.create_image_original()
[docs]
def label_original_mouse_double_click_event(self, event):
"""
Handle the mouse double-click event for the `label_original` widget, which displays the original fisheye image.
If the current view mode is `AnypointView`, calls the corresponding `model_apps` method and displays the
corresponding `view_anypoint` UI widget.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_original_mouse_double_click_event(), "
"Mouse double click even for label_original")
if self._model.image_original is not None:
if self._model.mode_view == "AnypointView":
if self._controller.ui_object.radio_mode_1.isChecked():
self._main_config["Mode_1"]["alpha"] = 0
self._main_config["Mode_1"]["beta"] = 0
# self._main_config["Mode_1"]["zoom"] = 4
self._main_config["Mode_1"]["coord"] = self._main_config["Image_original"]["center_coord"]
self._model.view_anypoint.create_maps_anypoint_mode_1()
self._controller.view_anypoint.showing_config_mode_1()
else:
self._main_config["Mode_2"]["pitch"] = 0
self._main_config["Mode_2"]["roll"] = 0
self._main_config["Mode_2"]["yaw"] = 0
# self._main_config["Mode_2"]["zoom"] = 4
self._main_config["Mode_2"]["coord"] = self._main_config["Image_original"]["center_coord"]
self._model.view_anypoint.create_maps_anypoint_mode_2()
self._controller.view_anypoint.showing_config_mode_2()
elif self._model.mode_view == "PanoramaView":
if self._controller.ui_object.radioButton_car.isChecked():
self._main_config["Pano_car"]["alpha"] = 0
self._main_config["Pano_car"]["beta"] = 0
self._main_config["Pano_car"]["coord"] = self._main_config["Image_original"]["center_coord"]
self._model.view_panorama.create_maps_panorama_car()
self._controller.view_panorama.showing_config_panorama_car()
self._controller.model.save_main_config_update()
self._controller.display_image_to_ui()
# label result controller begin here ##############################
[docs]
def label_result_mouse_double_click(self, event):
"""
Handle mouse double-click events on the result label.
Arg:
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_result_mouse_double_click(), "
"Mouse double click even for label_result")
if self._model.image_original is not None:
if self._model.view_zoom_area.state_rubberband:
self._controller.ctrl_img_result.create_image_result()
self._model.view_zoom_area.state_rubberband = False
self._controller.display_image_to_ui()
else:
# self._model.view_panorama.create_maps_fov()
self._controller.showing_new_window_full_screen()
[docs]
def label_result_mouse_press_event(self, event):
"""
Handle the mouse press event on the result image label.
Arg:
event: A `QMouseEvent` object representing the mouse press event.
Return:
None.
Note:
This function is responsible for creating and showing a rubberband when the left mouse button is pressed on
the result image label. The rubberband is used to select a specific region of interest (ROI) in the image.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_result_mouse_press_event(), "
"Mouse press even for label_result")
if event.button() == QtCore.Qt.MouseButton.LeftButton:
if self._model.image_original is not None:
self._rubberband.hide()
self._controller.origin = event.pos()
self._rubberband.setGeometry(QtCore.QRect(self._controller.origin, QtCore.QSize()))
self._rubberband.show()
[docs]
def label_result_mouse_move_event(self, event):
"""
Handle mouse move events on the result label.
Arg:
event: A `QMouseEvent` instance representing the mouse move event.
Return:
None.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_result_mouse_press_event(), "
"Mouse move even for label_result")
if event.buttons() == QtCore.Qt.MouseButton.LeftButton:
if self._model.image_original is not None:
if self._rubberband.isVisible():
self._rubberband.setGeometry(QtCore.QRect(self._controller.origin, event.pos()))
[docs]
def label_result_mouse_release_event(self, event):
"""
Handle the mouse release event on the label_result widget.
If the left mouse button was released and an image is loaded, the size of the rubberband is checked.
If it has a width and height greater than 20 pixels and the state of the rubberband is False, the size of
the rubberband is stored in the model's size_rubberband attribute, the state of the rubberband is set to
True, and a new image result is created. The rubberband is then hidden. If the right mouse button is
released, the menu_mouse_event method is called with the event object and the string "label_result" as
arguments.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_result_mouse_release_event(), "
"Mouse release even for label_result")
if event.button() == QtCore.Qt.MouseButton.LeftButton:
if self._model.image_original is not None:
size_rubberband = self._rubberband.geometry()
if size_rubberband.width() > 20 and size_rubberband.height() > 20:
if self._model.view_zoom_area.state_rubberband is False:
self._model.view_zoom_area.size_rubberband = size_rubberband
self._controller.model.view_zoom_area.size_zoom = self._model.view_properties.zooming_size
self._model.view_zoom_area.state_rubberband = True
self._controller.display_image_to_ui()
self._rubberband.hide()
elif event.button() == QtCore.Qt.MouseButton.RightButton:
self.menu_mouse_event(event, "label_result")
[docs]
def label_recenter_mouse_press_event(self, event):
"""
Handle mouse press events on the recenter label.
Arg:
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_recenter_mouse_press_event(), "
"Mouse press even for recenter label")
self.calculate_ratio_label_ori()
pos_x = round(int(event.position().x()) * self._ratio_label_ori[0])
pos_y = round(int(event.position().y()) * self._ratio_label_ori[1])
if event.buttons() == QtCore.Qt.MouseButton.LeftButton:
if self._model.view_zoom_area.state_rubberband:
print("under developing")
else:
if self._model.mode_view == "AnypointView":
if self._model.view_anypoint.anypoint_mode == "mode_1":
self._main_config["Mode_1"]["coord"] = pos_x, pos_y
alpha, beta = self._moildev.moildev_main.get_alpha_beta(pos_x, pos_y, 1)
if alpha is not None:
self._main_config["Mode_1"]["alpha"] = round(alpha, 1)
self._main_config["Mode_1"]["beta"] = round(beta, 1)
self._model.view_anypoint.create_maps_anypoint_mode_1()
self._controller.view_anypoint.showing_config_mode_1()
else:
self._main_config["Mode_2"]["coord"] = pos_x, pos_y
alpha, beta = self._moildev.moildev_main.get_alpha_beta(pos_x, pos_y, 2)
if alpha is not None:
self._main_config["Mode_2"]["pitch"] = round(alpha, 2)
self._main_config["Mode_2"]["yaw"] = round(beta, 2)
self._model.view_anypoint.create_maps_anypoint_mode_2()
self._controller.view_anypoint.showing_config_mode_2()
elif self._model.mode_view == "PanoramaView":
if self._controller.ui_object.radioButton_car.isChecked():
self._main_config["Pano_car"]["coord"] = pos_x, pos_y
alpha, beta = self._moildev.moildev_main.get_alpha_beta(pos_x, pos_y, 1)
if alpha is not None:
self._main_config["Pano_car"]["alpha"] = round(alpha, 2)
self._main_config["Pano_car"]["beta"] = round(beta, 2)
self._model.view_panorama.create_maps_panorama_car()
self._controller.view_panorama.showing_config_panorama_car()
self._controller.model.save_main_config_update()
self._controller.display_image_to_ui()
[docs]
def label_recenter_mouse_move_event(self, event):
"""
Handle mouse move events on the recenter label.
Arg:
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_recenter_mouse_move_event(), "
"Mouse move even for recenter label")
self.update_label_recenter_mouse_move_event(
self._controller.ui_object.label_image_recenter, event)
[docs]
def update_label_recenter_mouse_move_event(self, label, event):
"""
Update the mouse move event for the recenter label.
Args:
label: The label to update.
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: update_label_recenter_mouse_move_event(), "
"Update Mouse move even for label recenter")
if self._model.image_original is None: # original is image resize
return
if self._model.view_zoom_area.state_rubberband:
return
if self._model.saving_media.load_saved_image:
return
self._model.ratio_x, self._model.ratio_y = (
self._model.calculate_ratio_image2label(label, self._model.image_ori_used)) # original is image resize))
x = round(int(event.position().x()) * self._model.ratio_x)
y = round(int(event.position().y()) * self._model.ratio_y)
self.set_value_coordinate_image_recenter(x, y)
if event.buttons() == Qt.MouseButton.NoButton:
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 1)
self._main_config["Image_recenter"]["pointer"] = [x, y]
if self._model.mode_view == "AnypointView":
self._controller.ui_object.label_image_original.setCursor(
QCursor(Qt.CursorShape.PointingHandCursor))
if self._model.view_anypoint.anypoint_mode == "mode_1":
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 1)
else:
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 2)
self.show_alpha_beta_label_recenter(alpha, beta)
self._controller.ctrl_img_ori.create_image_original()
elif event.buttons() == Qt.MouseButton.LeftButton:
if self._model.mode_view == "AnypointView":
self._controller.ui_object.label_image_original.setCursor(QCursor(Qt.CursorShape.ClosedHandCursor))
if self._model.view_anypoint.anypoint_mode == "mode_1":
self._main_config["Mode_1"]["coord"] = [x, y]
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 1)
if alpha is not None:
self._main_config["Mode_1"]["alpha"] = round(alpha, 2)
self._main_config["Mode_1"]["beta"] = round(beta, 2)
self.show_alpha_beta_label_recenter(alpha, beta)
self._model.view_anypoint.create_maps_anypoint_mode_1()
else:
self._main_config["Mode_2"]["coord"] = [x, y]
alpha, beta = self._moildev.moildev_main.get_alpha_beta(x, y, 2)
if alpha is not None:
self._main_config["Mode_2"]["pitch"] = round(alpha, 2)
self._main_config["Mode_2"]["yaw"] = round(beta, 2)
self.show_alpha_beta_label_original(alpha, beta)
self._model.view_anypoint.create_maps_anypoint_mode_2()
self._controller.model.save_main_config_update()
self.show_alpha_beta_label_recenter(alpha, beta)
self._controller.display_image_to_ui()
[docs]
def label_recenter_mouse_leave_event(self, event):
"""
Handle the mouse leave event for the recenter label.
Arg:
event: The mouse event.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_recenter_mouse_leave_event(), "
"Mouse leave even for label recenter")
if self._model.image_original is None: # original is image resize
return
if self._model.view_zoom_area.state_rubberband:
return
if self._model.saving_media.load_saved_image:
return
if self._controller.model.recenter_mode_view:
if self._model.mode_view == "FisheyeView":
icx = self._model.main_config["Image_original"]["center_coord"][0]
icy = self._model.main_config["Image_original"]["center_coord"][1]
else:
icx = self._model.main_config["Image_recenter"]["Recenter_coordinate"][0]
icy = self._model.main_config["Image_recenter"]["Recenter_coordinate"][1]
self.set_value_coordinate_image_recenter(icx, icy)
alpha, beta = self._moildev.moildev_recenter.get_alpha_beta(icx, icy)
self.show_alpha_beta_label_recenter(alpha, beta)
else:
if self._model.mode_view == "AnypointView":
if self._controller.ui_object.radio_mode_1.isChecked():
alpha = self._model.main_config["Mode_1"]["alpha"]
beta = self._model.main_config["Mode_1"]["beta"]
self.set_value_coordinate_image_recenter(self._model.main_config["Mode_1"]["coord"][0],
self._model.main_config["Mode_1"]["coord"][1])
else:
alpha = self._model.main_config["Mode_2"]["pitch"]
beta = self._model.main_config["Mode_2"]["yaw"]
self.set_value_coordinate_image_recenter(self._model.main_config["Mode_2"]["coord"][0],
self._model.main_config["Mode_2"]["coord"][1])
self.show_alpha_beta_label_original(alpha, beta)
elif self._model.mode_view == "PanoramaView":
if self._controller.ui_object.radioButton_car.isChecked():
alpha = self._model.main_config["Pano_car"]["alpha"]
beta = self._model.main_config["Pano_car"]["beta"]
self.set_value_coordinate_image_recenter(self._model.main_config["Pano_car"]["coord"][0],
self._model.main_config["Pano_car"]["coord"][1])
self.show_alpha_beta_label_recenter(alpha, beta)
else:
alpha, beta = 0, 0
self.set_value_coordinate_image_recenter(self._model.main_config["Image_original"]["center_coord"][0],
self._model.main_config["Image_original"]["center_coord"][0])
self.show_alpha_beta_label_recenter(alpha, beta)
self._main_config["Image_recenter"]["pointer"] = [None, None]
self._controller.ctrl_img_ori.create_image_original()
[docs]
def update_label_recenter_mouse_leave_event(self):
"""
Update the mouse leave event for the label recenter.
This method updates the mouse leave event for the label recenter based on the current mode view.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: update_label_recenter_mouse_leave_event(), "
"Update Mouse leave even for label recenter")
if self._model.image_original is None: # original is image resize
return
if self._model.view_zoom_area.state_rubberband:
return
if self._model.saving_media.load_saved_image:
return
if self._model.mode_view == "AnypointView":
if self._model.view_anypoint.anypoint_mode == "mode_1":
if self._main_config["Mode_1"]["coord"][0] is None:
alpha, beta = 0, 0
else:
alpha = self._main_config["Mode_1"]["alpha"]
beta = self._main_config["Mode_1"]["beta"]
self.set_value_coordinate_image_recenter(self._main_config["Mode_1"]["coord"][0],
self._main_config["Mode_1"]["coord"][1])
else:
if self._main_config["Mode_2"]["coord"][0] is None:
alpha, beta = 0, 0
else:
alpha = self._main_config["Mode_2"]["pitch"]
beta = self._main_config["Mode_2"]["yaw"]
self.set_value_coordinate_image_recenter(self._main_config["Mode_2"]["coord"][0],
self._main_config["Mode_2"]["coord"][1])
self.show_alpha_beta_label_recenter(alpha, beta)
elif self._model.mode_view == "PanoramaView":
if self._model.change_panorama_mode == "car":
if self._main_config["Pano_car"]["coord"][0] is None:
alpha, beta = 0, 0
else:
alpha = self._main_config["Pano_car"]["alpha"]
beta = self._main_config["Pano_car"]["beta"]
self.set_value_coordinate_image_recenter(self._main_config["Pano_car"]["coord"][0],
self._main_config["Pano_car"]["coord"][1])
else:
alpha, beta = 0, 0
self.show_alpha_beta_label_recenter(alpha, beta)
[docs]
def label_recenter_mouse_release_event(self, event):
"""
Handle the mouse release event for the label recenter.
This method handles the mouse release event for the label recenter and triggers a menu mouse event if
the right mouse button is clicked.
Arg:
event (QMouseEvent): The mouse event object.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: label_original_mouse_release_event(), "
"Mouse even release for label_original")
if event.button() == QtCore.Qt.MouseButton.RightButton:
self.menu_mouse_event(event, "label_recenter")
[docs]
def set_value_coordinate_image_original(self, cor_x, cor_y):
"""
Set the coordinate values for the original image label in the user interface.
This method sets the coordinate values for the original image label in the user interface based on the
given x and y coordinates.
Args:
cor_x (int): The x-coordinate value.
cor_y (int): The y-coordinate value.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: set_value_coordinate_image_original(), "
"Set value coordinate to user interface")
self._ui_object.spinBox_icx.blockSignals(True)
self._ui_object.spinBox_icy.blockSignals(True)
self._ui_object.spinBox_icx.setValue(cor_x)
self._ui_object.spinBox_icy.setValue(cor_y)
self._ui_object.spinBox_icx.blockSignals(False)
self._ui_object.spinBox_icy.blockSignals(False)
[docs]
def set_value_coordinate_image_recenter(self, cor_x, cor_y):
"""
Set the coordinate values for the recenter image label in the user interface.
This method sets the coordinate values for the recenter image label in the user interface based on the
given x and y coordinates.
Args:
cor_x (int): The x-coordinate value.
cor_y (int): The y-coordinate value.
"""
if self._model.debug_mode:
self._model.activity_logger.info("Mouseevent(): set_value_coordinate_image_recenter(), "
"Show value coordinate recenter to user interface")
self._ui_object.label_pos_x.setText(str(cor_x))
self._ui_object.label_pos_y.setText(str(cor_y))
[docs]
def show_alpha_beta_label_original(self, alpha, beta):
"""
Set the alpha and beta values based on the given coordinate.
This method sets the alpha and beta values for the original image label in the user interface based on the given
coordinates. If either value is None, then both alpha and beta are set to 0.0. Otherwise, the alpha and beta
values are rounded to two decimal places before being set.
Args:
alpha (float): The alpha value.
beta (float): The beta value.
"""
if self._model.debug_mode:
self._model.activity_logger.info("MouseEvent: set_alpha_beta_coordinate_to_ui(), "
"Set value alpha beta to user interface")
self._ui_object.doubleSpinBox_alpha_rec.blockSignals(True)
self._ui_object.doubleSpinBox_beta_rec.blockSignals(True)
if any(elem is None for elem in [alpha, beta]):
self._ui_object.doubleSpinBox_alpha_rec.setValue(0)
self._ui_object.doubleSpinBox_beta_rec.setValue(0)
else:
self._ui_object.doubleSpinBox_alpha_rec.setValue(round(alpha, 2))
self._ui_object.doubleSpinBox_beta_rec.setValue(round(beta, 2))
self._ui_object.doubleSpinBox_alpha_rec.blockSignals(False)
self._ui_object.doubleSpinBox_beta_rec.blockSignals(False)
[docs]
def show_alpha_beta_label_recenter(self, alpha, beta):
"""
Set the alpha and beta values for recentered image label in the user interface.
This method sets the alpha and beta values for the recentered image label in the user interface based on
the given coordinates. If either value is None, then both alpha and beta are set to 0.0.
Otherwise, the alpha and beta values are rounded to two decimal places before being displayed.
Args:
alpha (float): The alpha value.
beta (float): The beta value.
"""
if self._model.debug_mode:
self._model.activity_logger.info("RecenterConfig: show_alpha_beta_label_recenter(), "
"Show alpha beta coordinate recenter to user interface")
if alpha is None or beta is None:
self._ui_object.label_alpha.setText(str(0))
self._ui_object.label_beta.setText(str(0))
else:
self._ui_object.label_alpha.setText(str(round(alpha, 2)))
self._ui_object.label_beta.setText(str(round(beta, 2)))