Улучшен дизайн кнопок SpinBox: добавлены современные стили, улучшена визуальная обратная связь, добавлены SVG иконки, оптимизированы размеры и отступы, улучшена читаемость значени
This commit is contained in:
1 parent
2b9165771b
commit
29dce906c5
6110 files changed
+775979
No files matched your search
@@ -0,0 +1,65 @@
|
||||
from PyQt6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout,
|
||||
QComboBox, QLabel)
|
||||
from PyQt6.QtCore import pyqtSignal
|
||||
import requests
|
||||
|
||||
class SamplerManager(QWidget):
|
||||
sampler_changed = pyqtSignal(str)
|
||||
|
||||
def __init__(self, api_url, parent=None):
|
||||
super().__init__(parent)
|
||||
self.api_url = api_url
|
||||
self.setup_ui()
|
||||
self.load_samplers()
|
||||
|
||||
def setup_ui(self):
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
|
||||
# Метка
|
||||
label = QLabel("Сэмплер:")
|
||||
layout.addWidget(label)
|
||||
|
||||
# Выпадающий список сэмплеров
|
||||
self.sampler_combo = QComboBox()
|
||||
self.sampler_combo.currentTextChanged.connect(self.on_sampler_changed)
|
||||
layout.addWidget(self.sampler_combo)
|
||||
|
||||
layout.addStretch()
|
||||
|
||||
def load_samplers(self):
|
||||
"""Загрузить список доступных сэмплеров"""
|
||||
try:
|
||||
response = requests.get(f"{self.api_url}/sdapi/v1/samplers")
|
||||
if response.status_code == 200:
|
||||
samplers = response.json()
|
||||
current_sampler = self.sampler_combo.currentText()
|
||||
|
||||
self.sampler_combo.clear()
|
||||
for sampler in samplers:
|
||||
self.sampler_combo.addItem(sampler.get('name', ''))
|
||||
|
||||
# Восстанавливаем выбранный сэмплер, если он всё ещё доступен
|
||||
index = self.sampler_combo.findText(current_sampler)
|
||||
if index >= 0:
|
||||
self.sampler_combo.setCurrentIndex(index)
|
||||
elif self.sampler_combo.count() > 0:
|
||||
# По умолчанию выбираем Euler a
|
||||
default_index = self.sampler_combo.findText("Euler a")
|
||||
if default_index >= 0:
|
||||
self.sampler_combo.setCurrentIndex(default_index)
|
||||
except Exception as e:
|
||||
print(f"Ошибка при загрузке сэмплеров: {str(e)}")
|
||||
|
||||
def on_sampler_changed(self, sampler_name):
|
||||
"""Обработка смены сэмплера"""
|
||||
self.sampler_changed.emit(sampler_name)
|
||||
|
||||
def update_api_url(self, new_url):
|
||||
"""Обновить URL API"""
|
||||
self.api_url = new_url
|
||||
self.load_samplers()
|
||||
|
||||
def get_current_sampler(self):
|
||||
"""Получить текущий выбранный сэмплер"""
|
||||
return self.sampler_combo.currentText()
|
||||
Reference in new issue
Block a user