"""
The model_view_properties module manages view properties such as zooming and rotation within the MoilApp
"""
[docs]
class ModelViewProperties:
"""
Class responsible for managing view properties such as zooming and rotation.
Attributes:
_model (object): The main model instance of the application.
_current_size (int): Current zoom size.
_rotate_original (int): Rotation degree for the original image.
_rotate_result (int): Rotation degree for the result image.
Methods:
zooming_size: Getter and setter method for the zoom size.
rotate_degree: Getter and setter method for the rotation degree of the result image.
zoom_in(): Increases the current zoom size by 100.
zoom_out(): Decreases the current zoom size by 100.
percentage_zoom(value): Determines the closest zoom percentage to the given value.
rotate_left(): Rotates the result image to the left by 5 degrees.
rotate_right(): Rotates the result image to the right by 5 degrees.
change_rotate_value(value): Changes the rotation degree value for the result image.
change_rotation_original_value(value): Changes the rotation degree value for the original image.
"""
def __init__(self, model):
self._model = model
self._current_size = model.main_config["Zoom_size"]
self._rotate_original = model.main_config["Image_original"]['rotate']
self._rotate_result = model.main_config["Rotate_result"]
@property
def zooming_size(self):
"""
Get the current zooming size.
Return:
The current zooming size.
"""
try:
return self._current_size
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.zooming_size(): Error: {str(e)}")
@zooming_size.setter
def zooming_size(self, value):
"""
Set the zooming size.
Arg:
value: The value to set as the zooming size.
"""
try:
self._current_size = value
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.zooming_size(): Error: {str(e)}")
@property
def rotate_degree(self):
"""
Get the current rotation degree.
Return:
The current rotation degree.
"""
try:
return self._rotate_result
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.rotate_degree(): Error: {str(e)}")
@rotate_degree.setter
def rotate_degree(self, value):
"""
Set the rotation degree.
Arg:
value: The value to set as the rotation degree.
"""
try:
self._rotate_result = value
self._model.main_config["Rotate_result"] = value
self._model.save_main_config_update()
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.rotate_degree(): Error: {str(e)}")
[docs]
def zoom_in(self):
"""
Increase the current size by 100 and returns the new size.
Return:
int: The new size after increasing by 100.
"""
try:
if self.zooming_size > 6000:
pass
else:
self.zooming_size += 100
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewProperties: zoom_in(), "
f"Zoom in image process with value {str(self.zooming_size)}")
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.zoom_in(): Error: {str(e)}")
[docs]
def zoom_out(self):
"""
Decrease the `current_size` by 100, unless it's already below 640.
Return:
int: The new size after decreasing by 100, or the original `current_size` if it's already below 640.
"""
try:
if self.zooming_size < 640:
pass
else:
self.zooming_size -= 100
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewProperties: zoom_out(), "
f"Zoom out image process with value {str(self.zooming_size)}")
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.zoom_out(): Error: {str(e)}")
[docs]
def percentage_zoom(self, value):
"""
Determine the closest zoom percentage to the given value.
This method calculates the closest zoom percentage from a predefined list to the given value.
It updates the current size attribute with the closest zoom percentage.
Arg:
value (int): The desired zoom percentage value.
Return:
None
"""
try:
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewProperties: percentage_zoom(), "
"list zoom percentage available on image ")
list_zoom = [520, 560, 596, 696, 796, 896, 996, 1096, 1196, 1296, 1396, 1496, 1596, 1696, 1796, 1896, 1996,
2096, 2196, 2296, 2396, 2496, 2596, 2596, 2696, 2796, 2896, 3096, 3196, 3296, 3396, 3496, 3596]
if self._model.image_original is not None:
self.zooming_size = min(list_zoom, key=lambda x: abs(x - value))
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.percentage_zoom(): Error: {str(e)}")
[docs]
def rotate_left(self):
"""
Rotate the image to the left by 5 degrees.
Return:
int: The new angle of rotation after rotating left by 5 degrees.
"""
try:
if self.rotate_degree == -180:
pass
else:
self.rotate_degree -= 5
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewProperties: rotate_left(), "
f"rotate left image process with {str(self.zooming_size)} degree")
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.rotate_left(): Error: {str(e)}")
[docs]
def rotate_right(self):
"""
Rotate the given angle to the right by 5 degrees.
Return:
int: The new angle after rotation to the right.
"""
try:
if self.rotate_degree == 180:
pass
else:
self.rotate_degree += 5
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewProperties: rotate_right(), "
f"rotate right image process with {str(self.zooming_size)} degree")
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.rotate_right(): Error: {str(e)}")
[docs]
def change_rotate_value(self, value):
"""
Change the rotate degree value for the result image.
This method updates the rotation degree value for the result image.
Arg:
value (int): The rotation degree value.
Return:
None
"""
try:
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewProperties: change_rotate_value(), "
f"change rotate value with {str(value)} degree")
self.rotate_degree = value
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.change_rotate_value(): Error: {str(e)}")
[docs]
def change_rotation_original_value(self, value):
"""
Change the rotation degree value for the original image.
This method updates the rotation degree value for the original image.
Arg:
value (int): The rotation degree value.
Return:
None
"""
try:
if self._model.debug_mode:
self._model.activity_logger.info("ModelViewProperties: change_rotation_original_value(), "
f"change rotate value image original with {str(value)} degree")
self._rotate_original = value
except Exception as e:
self._model.activity_logger.error(f"ModelViewProperties.change_rotation_original_value(): Error: {str(e)}")