"""
This module contains the ControlPanelPage class, which provides methods for handling UI elements
and animations related to the panel page.
"""
from PyQt6 import QtCore
[docs]
class ControlPanelPage:
"""
Class for controlling the panel page of the application.
Attributes:
_ui_object: The UI object.
_theme_mode: The current theme mode of the application.
_active_left: A flag indicating whether the left panel is active.
_animation: Animation object for controlling panel animations.
_group: Group animation object for coordinating multiple animations.
Methods:
__init__(self, controller): Initializes the ControlPanelPage object.
close_setting_window(self): Closes the settings window if it is open.
button_menu(self, max_width, enable): Animates the left-side menu of the application.
button_about_us(self): Animates the "About Us" button and expands the right-hand additional frame.
setting_menu(self): Toggles the visibility of the additional left frame and updates the theme of the settings button.
_start_box_animation(self, left_box_width, right_box_width, direction): Animates the left and right boxes to slide in or out.
"""
[docs]
def __init__(self, controller):
self._ui_object = controller.ui_object
self._theme_mode = controller.model.theme_mode
self._active_left = False
self._animation = None
self._group = None
@property
def active_left(self):
"""
Get the status of the left panel.
Return:
bool: True if the left panel is active, False otherwise.
"""
return self._active_left
@active_left.setter
def active_left(self, value):
"""
Set the status of the left panel.
Arg:
value (bool): The value to set for the left panel status.
Return:
None.
"""
self._active_left = value
[docs]
def close_setting_window(self):
"""
Close the settings window if it is open.
Return:
None
"""
width = self._ui_object.frame_additional_left.width()
if width != 0:
self.setting_menu()
[docs]
def button_about_us(self):
"""
Animate the "About Us" button and expand the right-hand additional frame.
Arg:
theme (str): The current theme ("light" or "dark").
Return:
None
"""
# GET WIDTH
width = self._ui_object.frame_additional_right.width()
width_left_box = self._ui_object.frame_additional_left.width()
style = self._ui_object.btn_setting.styleSheet()
# SET MAX WIDTH
if width_left_box != 0:
color = "background-color: rgb(238, 238, 236);"
color_dark = "background-color: rgb(33, 37, 43);"
self._ui_object.btn_setting.setStyleSheet(style + color)
if self._theme_mode == "dark":
self._ui_object.btn_setting.setStyleSheet(style + color_dark)
self._start_box_animation(width_left_box, width, "right")
[docs]
def _start_box_animation(self, left_box_width, right_box_width, direction):
"""
Animate the left and right boxes to slide in or out.
Args:
left_box_width (int): The current width of the left box.
right_box_width (int): The current width of the right box.
direction (str): The direction in which to animate the boxes, either "left" or "right".
Return:
None
"""
# Check values
if left_box_width == 0 and direction == "left":
left_width = 240
else:
left_width = 0
# Check values
if right_box_width == 0 and direction == "right":
right_width = 240
else:
right_width = 0
# ANIMATION LEFT BOX
left_box = QtCore.QPropertyAnimation(self._ui_object.frame_additional_left, b"minimumWidth")
left_box.setDuration(500)
left_box.setStartValue(left_box_width)
left_box.setEndValue(left_width)
left_box.setEasingCurve(QtCore.QEasingCurve.Type.InOutQuart)
# # ANIMATION RIGHT BOX
right_box = QtCore.QPropertyAnimation(self._ui_object.frame_additional_right, b"minimumWidth")
right_box.setDuration(500)
right_box.setStartValue(right_box_width)
right_box.setEndValue(right_width)
right_box.setEasingCurve(QtCore.QEasingCurve.Type.InOutQuart)
# GROUP ANIMATION
self._group = QtCore.QParallelAnimationGroup()
self._group.addAnimation(left_box)
self._group.addAnimation(right_box)
self._group.start()