145 lines
5.5 KiB
Python
145 lines
5.5 KiB
Python
from PyQt6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout,
|
|
QLabel, QPushButton, QLineEdit, QSpinBox,
|
|
QComboBox, QProgressBar, QScrollArea, QFrame)
|
|
from PyQt6.QtCore import Qt
|
|
from ..styles.style_constants import StyleConstants
|
|
from ..styles.icons import IconManager, IconType
|
|
from ..styles.page import BasePage
|
|
|
|
class ModelCard(QFrame):
|
|
"""Карточка модели"""
|
|
def __init__(self, model, parent=None):
|
|
super().__init__(parent)
|
|
self.model = model
|
|
self.setup_ui()
|
|
|
|
def setup_ui(self):
|
|
self.setStyleSheet(f"""
|
|
QFrame {{
|
|
background-color: {StyleConstants.COLORS['dark']['surface']};
|
|
border-radius: {StyleConstants.RADIUS['md']}px;
|
|
padding: {StyleConstants.SPACING['md']}px;
|
|
margin-bottom: {StyleConstants.SPACING['md']}px;
|
|
}}
|
|
QLabel {{
|
|
color: {StyleConstants.COLORS['dark']['text']};
|
|
}}
|
|
QPushButton {{
|
|
background-color: {StyleConstants.COLORS['primary']};
|
|
color: white;
|
|
border: none;
|
|
border-radius: {StyleConstants.RADIUS['sm']}px;
|
|
padding: {StyleConstants.SPACING['sm']}px {StyleConstants.SPACING['md']}px;
|
|
}}
|
|
QPushButton:hover {{
|
|
background-color: {StyleConstants.COLORS['secondary']};
|
|
}}
|
|
""")
|
|
|
|
layout = QVBoxLayout(self)
|
|
layout.setSpacing(StyleConstants.SPACING['sm'])
|
|
|
|
# Название модели
|
|
title = QLabel(self.model.title)
|
|
title.setStyleSheet(f"""
|
|
font-size: {StyleConstants.FONTS['size']['lg']};
|
|
font-weight: {StyleConstants.FONTS['weight']['bold']};
|
|
""")
|
|
layout.addWidget(title)
|
|
|
|
# Имя файла модели
|
|
name = QLabel(self.model.name)
|
|
name.setStyleSheet(f"""
|
|
font-size: {StyleConstants.FONTS['size']['sm']};
|
|
color: {StyleConstants.COLORS['dark']['text_secondary']};
|
|
""")
|
|
layout.addWidget(name)
|
|
|
|
# Кнопки управления
|
|
buttons_layout = QHBoxLayout()
|
|
|
|
select_btn = QPushButton("Выбрать")
|
|
select_btn.setIcon(IconManager.get_instance().get_icon(IconType.SUCCESS))
|
|
buttons_layout.addWidget(select_btn)
|
|
|
|
delete_btn = QPushButton("Удалить")
|
|
delete_btn.setIcon(IconManager.get_instance().get_icon(IconType.DELETE))
|
|
buttons_layout.addWidget(delete_btn)
|
|
|
|
buttons_layout.addStretch()
|
|
layout.addLayout(buttons_layout)
|
|
|
|
class ModelsPage(BasePage):
|
|
"""Страница управления моделями"""
|
|
def __init__(self, model_manager, parent=None):
|
|
super().__init__(parent)
|
|
self.model_manager = model_manager
|
|
self.setup_ui()
|
|
|
|
def setup_ui(self):
|
|
# Верхняя панель
|
|
top_panel = QHBoxLayout()
|
|
top_panel.setContentsMargins(
|
|
StyleConstants.SPACING['lg'],
|
|
StyleConstants.SPACING['lg'],
|
|
StyleConstants.SPACING['lg'],
|
|
StyleConstants.SPACING['lg']
|
|
)
|
|
top_panel.setSpacing(StyleConstants.SPACING['md'])
|
|
|
|
# Поиск
|
|
self.search_edit = QLineEdit()
|
|
self.search_edit.setPlaceholderText("Поиск моделей...")
|
|
top_panel.addWidget(self.search_edit)
|
|
|
|
# Кнопка обновления
|
|
refresh_btn = QPushButton("Обновить")
|
|
refresh_btn.setIcon(IconManager.get_instance().get_icon(IconType.REFRESH))
|
|
refresh_btn.clicked.connect(self.update_ui)
|
|
top_panel.addWidget(refresh_btn)
|
|
|
|
# Кнопка добавления
|
|
add_btn = QPushButton("Добавить")
|
|
add_btn.setIcon(IconManager.get_instance().get_icon(IconType.ADD))
|
|
top_panel.addWidget(add_btn)
|
|
|
|
top_panel.addStretch()
|
|
self.layout.addLayout(top_panel)
|
|
|
|
# Область прокрутки для моделей
|
|
scroll_area = QScrollArea()
|
|
scroll_area.setWidgetResizable(True)
|
|
scroll_area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
|
|
|
# Контейнер для карточек моделей
|
|
self.models_container = QWidget()
|
|
self.models_layout = QVBoxLayout(self.models_container)
|
|
self.models_layout.setContentsMargins(
|
|
StyleConstants.SPACING['lg'],
|
|
0,
|
|
StyleConstants.SPACING['lg'],
|
|
StyleConstants.SPACING['lg']
|
|
)
|
|
self.models_layout.setSpacing(0)
|
|
|
|
scroll_area.setWidget(self.models_container)
|
|
self.layout.addWidget(scroll_area)
|
|
|
|
# Обновляем UI
|
|
self.update_ui()
|
|
|
|
def update_ui(self):
|
|
"""Обновление списка моделей"""
|
|
# Очищаем контейнер
|
|
for i in reversed(range(self.models_layout.count())):
|
|
widget = self.models_layout.itemAt(i).widget()
|
|
if widget:
|
|
widget.deleteLater()
|
|
|
|
# Добавляем карточки моделей
|
|
for model in self.model_manager.get_models():
|
|
card = ModelCard(model)
|
|
self.models_layout.addWidget(card)
|
|
|
|
# Добавляем растягивающийся элемент в конец
|
|
self.models_layout.addStretch() |