Воркед
This commit is contained in:
1 parent
ac32c55ab9
commit
ee94d8e529
1138 files changed
+55771
-77901
No files matched your search
+45
-18
@@ -2,15 +2,17 @@ from PyQt6.QtWidgets import QWidget, QStackedWidget, QVBoxLayout
|
||||
from PyQt6.QtCore import QPropertyAnimation, QParallelAnimationGroup, QEasingCurve, Qt, QPoint
|
||||
from .theme import Theme, Colors
|
||||
from .theme_manager import ThemeManager
|
||||
from .style_constants import StyleConstants
|
||||
|
||||
class BasePage(QWidget):
|
||||
"""Базовый класс для страниц"""
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.theme_manager = ThemeManager.get_instance()
|
||||
self.setup_ui()
|
||||
self.setup_base_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
"""Базовая настройка страницы"""
|
||||
def setup_base_ui(self):
|
||||
"""Настройка базового UI"""
|
||||
colors = self.theme_manager.current_theme.get_colors()
|
||||
self.setStyleSheet(f"""
|
||||
QWidget {{
|
||||
@@ -18,11 +20,19 @@ class BasePage(QWidget):
|
||||
}}
|
||||
""")
|
||||
|
||||
# Основной layout
|
||||
self.layout = QVBoxLayout(self)
|
||||
self.layout.setContentsMargins(24, 24, 24, 24)
|
||||
self.layout.setSpacing(16)
|
||||
self.layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout.setSpacing(0)
|
||||
|
||||
# Создаем анимации
|
||||
self.enter_animation = QPropertyAnimation(self, b"pos")
|
||||
self.enter_animation.setDuration(250)
|
||||
self.enter_animation.setEasingCurve(QEasingCurve.Type.OutCubic)
|
||||
|
||||
self.exit_animation = QPropertyAnimation(self, b"pos")
|
||||
self.exit_animation.setDuration(250)
|
||||
self.exit_animation.setEasingCurve(QEasingCurve.Type.OutCubic)
|
||||
|
||||
def enter_animation(self):
|
||||
"""Анимация появления страницы"""
|
||||
# Создаем группу анимаций
|
||||
@@ -78,26 +88,43 @@ class BasePage(QWidget):
|
||||
self.anim_group.start()
|
||||
|
||||
class PageContainer(QStackedWidget):
|
||||
"""Контейнер для страниц с анимацией переходов"""
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.pages = {}
|
||||
self.current_page = None
|
||||
|
||||
def add_page(self, name: str, page: BasePage):
|
||||
"""Добавление новой страницы"""
|
||||
"""Добавить страницу"""
|
||||
self.pages[name] = page
|
||||
self.addWidget(page)
|
||||
|
||||
def show_page(self, name: str):
|
||||
"""Показ страницы по имени"""
|
||||
if name in self.pages:
|
||||
# Запускаем анимацию исчезновения текущей страницы
|
||||
current_page = self.currentWidget()
|
||||
if isinstance(current_page, BasePage):
|
||||
current_page.leave_animation()
|
||||
"""Показать страницу с анимацией"""
|
||||
if name not in self.pages:
|
||||
return
|
||||
|
||||
# Показываем новую страницу
|
||||
new_page = self.pages[name]
|
||||
self.setCurrentWidget(new_page)
|
||||
next_page = self.pages[name]
|
||||
|
||||
if self.current_page == next_page:
|
||||
return
|
||||
|
||||
# Запускаем анимацию появления новой страницы
|
||||
new_page.enter_animation()
|
||||
# Получаем размеры виджета
|
||||
width = self.width()
|
||||
|
||||
# Настраиваем анимации
|
||||
if self.current_page:
|
||||
# Анимация выхода текущей страницы
|
||||
self.current_page.exit_animation.setStartValue(QPoint(0, 0))
|
||||
self.current_page.exit_animation.setEndValue(QPoint(-width, 0))
|
||||
self.current_page.exit_animation.start()
|
||||
|
||||
# Анимация входа следующей страницы
|
||||
next_page.move(width, 0)
|
||||
next_page.enter_animation.setStartValue(QPoint(width, 0))
|
||||
next_page.enter_animation.setEndValue(QPoint(0, 0))
|
||||
next_page.enter_animation.start()
|
||||
|
||||
# Показываем страницу
|
||||
self.setCurrentWidget(next_page)
|
||||
self.current_page = next_page
|
||||
Reference in new issue
Block a user