Воркед
This commit is contained in:
1 parent
ac32c55ab9
commit
ee94d8e529
1138 files changed
+55771
-77901
No files matched your search
+124
-157
@@ -1,178 +1,145 @@
|
||||
from PyQt6.QtWidgets import (QLabel, QPushButton, QHBoxLayout,
|
||||
QVBoxLayout, QLineEdit, QListWidget,
|
||||
QListWidgetItem, QFrame)
|
||||
from PyQt6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout,
|
||||
QLabel, QPushButton, QLineEdit, QSpinBox,
|
||||
QComboBox, QProgressBar, QScrollArea, QFrame)
|
||||
from PyQt6.QtCore import Qt
|
||||
from modules.styles.page import BasePage
|
||||
from modules.styles.theme import Colors
|
||||
from modules.styles.theme_manager import ThemeManager
|
||||
from ..styles.style_constants import StyleConstants
|
||||
from ..styles.icons import IconManager, IconType
|
||||
from ..styles.page import BasePage
|
||||
|
||||
class ModelItem(QFrame):
|
||||
def __init__(self, model_name: str, parent=None):
|
||||
class ModelCard(QFrame):
|
||||
"""Карточка модели"""
|
||||
def __init__(self, model, parent=None):
|
||||
super().__init__(parent)
|
||||
self.model_name = model_name
|
||||
self.theme_manager = ThemeManager.get_instance()
|
||||
self.model = model
|
||||
self.setup_ui()
|
||||
|
||||
def setup_ui(self):
|
||||
"""Настройка UI элемента модели"""
|
||||
colors = self.theme_manager.current_theme.get_colors()
|
||||
spacing = self.theme_manager.current_theme.get_spacing()
|
||||
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(8, 8, 8, 8)
|
||||
|
||||
# Название модели
|
||||
name_label = QLabel(self.model_name)
|
||||
name_label.setStyleSheet(f"color: {colors['text']};")
|
||||
layout.addWidget(name_label)
|
||||
|
||||
# Растягиваем пространство
|
||||
layout.addStretch()
|
||||
|
||||
# Кнопки управления
|
||||
select_btn = QPushButton("Выбрать")
|
||||
select_btn.setMinimumWidth(100)
|
||||
select_btn.setStyleSheet(f"""
|
||||
QPushButton {{
|
||||
background-color: {colors['primary']};
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: {spacing.TINY}px;
|
||||
padding: {spacing.SMALL}px {spacing.MEDIUM}px;
|
||||
}}
|
||||
|
||||
QPushButton:hover {{
|
||||
background-color: {colors['hover']};
|
||||
}}
|
||||
|
||||
QPushButton:pressed {{
|
||||
background-color: {colors['active']};
|
||||
}}
|
||||
""")
|
||||
layout.addWidget(select_btn)
|
||||
|
||||
delete_btn = QPushButton("Удалить")
|
||||
delete_btn.setMinimumWidth(100)
|
||||
delete_btn.setStyleSheet(f"""
|
||||
QPushButton {{
|
||||
background-color: {colors['error']};
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: {spacing.TINY}px;
|
||||
padding: {spacing.SMALL}px {spacing.MEDIUM}px;
|
||||
}}
|
||||
|
||||
QPushButton:hover {{
|
||||
background-color: {colors['hover']};
|
||||
}}
|
||||
|
||||
QPushButton:pressed {{
|
||||
background-color: {colors['active']};
|
||||
}}
|
||||
""")
|
||||
layout.addWidget(delete_btn)
|
||||
|
||||
# Стили
|
||||
self.setStyleSheet(f"""
|
||||
QFrame {{
|
||||
background-color: {colors['surface']};
|
||||
border: 1px solid {colors['border']};
|
||||
border-radius: {spacing.TINY}px;
|
||||
background-color: {StyleConstants.COLORS['dark']['surface']};
|
||||
border-radius: {StyleConstants.RADIUS['md']}px;
|
||||
padding: {StyleConstants.SPACING['md']}px;
|
||||
margin-bottom: {StyleConstants.SPACING['md']}px;
|
||||
}}
|
||||
""")
|
||||
|
||||
class ModelsPage(BasePage):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.theme_manager = ThemeManager.get_instance()
|
||||
self.setup_content()
|
||||
|
||||
def setup_content(self):
|
||||
"""Настройка содержимого страницы"""
|
||||
colors = self.theme_manager.current_theme.get_colors()
|
||||
spacing = self.theme_manager.current_theme.get_spacing()
|
||||
|
||||
# Заголовок
|
||||
header = QLabel("Модели")
|
||||
header.setStyleSheet(f"""
|
||||
QLabel {{
|
||||
color: {colors['text']};
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
color: {StyleConstants.COLORS['dark']['text']};
|
||||
}}
|
||||
""")
|
||||
self.layout.addWidget(header)
|
||||
|
||||
# Поиск и добавление
|
||||
search_layout = QHBoxLayout()
|
||||
|
||||
self.search_input = QLineEdit()
|
||||
self.search_input.setPlaceholderText("Поиск моделей...")
|
||||
self.search_input.setStyleSheet(f"""
|
||||
QLineEdit {{
|
||||
background-color: {colors['surface']};
|
||||
color: {colors['text']};
|
||||
border: 1px solid {colors['border']};
|
||||
border-radius: {spacing.TINY}px;
|
||||
padding: {spacing.SMALL}px;
|
||||
}}
|
||||
|
||||
QLineEdit:focus {{
|
||||
border: 1px solid {colors['primary']};
|
||||
}}
|
||||
""")
|
||||
search_layout.addWidget(self.search_input)
|
||||
|
||||
self.add_btn = QPushButton("Добавить модель")
|
||||
self.add_btn.setMinimumWidth(150)
|
||||
self.add_btn.setStyleSheet(f"""
|
||||
QPushButton {{
|
||||
background-color: {colors['primary']};
|
||||
background-color: {StyleConstants.COLORS['primary']};
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: {spacing.TINY}px;
|
||||
padding: {spacing.SMALL}px {spacing.MEDIUM}px;
|
||||
border-radius: {StyleConstants.RADIUS['sm']}px;
|
||||
padding: {StyleConstants.SPACING['sm']}px {StyleConstants.SPACING['md']}px;
|
||||
}}
|
||||
|
||||
QPushButton:hover {{
|
||||
background-color: {colors['hover']};
|
||||
}}
|
||||
|
||||
QPushButton:pressed {{
|
||||
background-color: {colors['active']};
|
||||
}}
|
||||
""")
|
||||
search_layout.addWidget(self.add_btn)
|
||||
|
||||
self.layout.addLayout(search_layout)
|
||||
|
||||
# Список моделей
|
||||
self.models_list = QListWidget()
|
||||
self.models_list.setSpacing(8)
|
||||
self.models_list.setStyleSheet(f"""
|
||||
QListWidget {{
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
}}
|
||||
|
||||
QListWidget::item {{
|
||||
padding: 0;
|
||||
background-color: transparent;
|
||||
background-color: {StyleConstants.COLORS['secondary']};
|
||||
}}
|
||||
""")
|
||||
|
||||
# Добавляем тестовые модели
|
||||
test_models = [
|
||||
"stable-diffusion-v1-5",
|
||||
"stable-diffusion-v2-1",
|
||||
"stable-diffusion-xl-base-1.0"
|
||||
]
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setSpacing(StyleConstants.SPACING['sm'])
|
||||
|
||||
for model in test_models:
|
||||
item = QListWidgetItem(self.models_list)
|
||||
model_widget = ModelItem(model)
|
||||
item.setSizeHint(model_widget.sizeHint())
|
||||
self.models_list.addItem(item)
|
||||
self.models_list.setItemWidget(item, model_widget)
|
||||
# Название модели
|
||||
title = QLabel(self.model.title)
|
||||
title.setStyleSheet(f"""
|
||||
font-size: {StyleConstants.FONTS['size']['lg']};
|
||||
font-weight: {StyleConstants.FONTS['weight']['bold']};
|
||||
""")
|
||||
layout.addWidget(title)
|
||||
|
||||
self.layout.addWidget(self.models_list)
|
||||
# Имя файла модели
|
||||
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()
|
||||
Reference in new issue
Block a user