ui: 调整设置页AI模型布局
This commit is contained in:
+122
-76
@@ -19,6 +19,7 @@ try:
|
||||
QDialogButtonBox,
|
||||
QFileDialog,
|
||||
QFormLayout,
|
||||
QGridLayout,
|
||||
QHBoxLayout,
|
||||
QHeaderView,
|
||||
QInputDialog,
|
||||
@@ -2857,18 +2858,6 @@ if QT_IMPORT_ERROR is None:
|
||||
self.add_model_button = QPushButton("新增")
|
||||
self.delete_model_button = QPushButton("删除")
|
||||
|
||||
left_panel = QWidget()
|
||||
left_layout = QVBoxLayout(left_panel)
|
||||
left_layout.setContentsMargins(0, 0, 12, 0)
|
||||
left_layout.addWidget(QLabel("AI 模型"))
|
||||
left_layout.addWidget(self.model_combo)
|
||||
left_toolbar = QHBoxLayout()
|
||||
left_toolbar.addWidget(self.add_model_button)
|
||||
left_toolbar.addWidget(self.delete_model_button)
|
||||
left_toolbar.addStretch(1)
|
||||
left_layout.addLayout(left_toolbar)
|
||||
left_layout.addStretch(1)
|
||||
|
||||
self.enabled_checkbox = QCheckBox("启用")
|
||||
self.name_edit = QLineEdit()
|
||||
self.name_edit.setObjectName("modelNameEdit")
|
||||
@@ -2956,88 +2945,104 @@ if QT_IMPORT_ERROR is None:
|
||||
self.max_parallel_accounts_spin.setObjectName("maxParallelAccountsSpin")
|
||||
self.max_parallel_accounts_spin.setRange(1, 16)
|
||||
|
||||
form = QFormLayout()
|
||||
form.addRow("", self.enabled_checkbox)
|
||||
form.addRow("服务商名", self.name_edit)
|
||||
form.addRow("类别", self.category_combo)
|
||||
form.addRow("api_type", self.api_type_combo)
|
||||
form.addRow("模型ID", self.model_id_edit)
|
||||
form.addRow("网址", self.url_edit)
|
||||
form.addRow("密钥", self.api_key_edit)
|
||||
form.addRow("连接超时(秒)", self.connect_timeout_spin)
|
||||
model_picker_layout = QHBoxLayout()
|
||||
model_picker_layout.addWidget(self.model_combo, 1)
|
||||
model_picker_layout.addWidget(self.add_model_button)
|
||||
model_picker_layout.addWidget(self.delete_model_button)
|
||||
|
||||
action_layout = QHBoxLayout()
|
||||
action_layout.addWidget(self.save_model_button)
|
||||
action_layout.addWidget(self.test_connection_button)
|
||||
action_layout.addStretch(1)
|
||||
|
||||
ai_form = QFormLayout()
|
||||
ai_form.addRow("标题大模型", self.default_text_model_combo)
|
||||
ai_form.addRow("图片大模型", self.default_image_model_combo)
|
||||
ai_form.addRow("标题并发数", self.title_concurrency_spin)
|
||||
ai_form.addRow("图片并发数", self.image_concurrency_spin)
|
||||
ai_form.addRow("失败重试次数", self.retry_spin)
|
||||
ai_form.addRow("分辨率", self.resolution_combo)
|
||||
ai_form.addRow("返回超时", self.response_timeout_label)
|
||||
ai_form.addRow("jpg质量", self.jpg_quality_spin)
|
||||
form = self._two_column_form(
|
||||
[
|
||||
("状态", self.enabled_checkbox),
|
||||
("服务商名", self.name_edit),
|
||||
("类别", self.category_combo),
|
||||
("api_type", self.api_type_combo),
|
||||
("模型ID", self.model_id_edit),
|
||||
("连接超时(秒)", self.connect_timeout_spin),
|
||||
("网址", self.url_edit, True),
|
||||
("密钥", self.api_key_edit, True),
|
||||
]
|
||||
)
|
||||
|
||||
ai_form = self._two_column_form(
|
||||
[
|
||||
("标题大模型", self.default_text_model_combo),
|
||||
("图片大模型", self.default_image_model_combo),
|
||||
("标题并发数", self.title_concurrency_spin),
|
||||
("图片并发数", self.image_concurrency_spin),
|
||||
("失败重试次数", self.retry_spin),
|
||||
("分辨率", self.resolution_combo),
|
||||
("返回超时", self.response_timeout_label),
|
||||
("jpg质量", self.jpg_quality_spin),
|
||||
]
|
||||
)
|
||||
|
||||
port_range_layout = QHBoxLayout()
|
||||
port_range_layout.setContentsMargins(0, 0, 0, 0)
|
||||
port_range_layout.addWidget(self.debug_port_start_spin)
|
||||
port_range_layout.addWidget(QLabel("到"))
|
||||
port_range_layout.addWidget(self.debug_port_end_spin)
|
||||
port_range_widget = QWidget()
|
||||
port_range_widget.setLayout(port_range_layout)
|
||||
|
||||
path_form = QFormLayout()
|
||||
path_form.addRow("Chrome路径", self.chrome_path_edit)
|
||||
path_form.addRow("账号数据根目录", self.user_data_root_edit)
|
||||
path_form.addRow("图片目录", self.image_dir_edit)
|
||||
path_form.addRow("DB路径", self.db_path_edit)
|
||||
path_form.addRow("默认调试端口", self.default_debug_port_spin)
|
||||
path_form.addRow("调试端口范围", port_range_layout)
|
||||
path_form.addRow("CDP就绪超时(秒)", self.cdp_ready_timeout_spin)
|
||||
path_form = self._two_column_form(
|
||||
[
|
||||
("Chrome路径", self.chrome_path_edit, True),
|
||||
("账号数据根目录", self.user_data_root_edit),
|
||||
("图片目录", self.image_dir_edit),
|
||||
("DB路径", self.db_path_edit),
|
||||
("默认调试端口", self.default_debug_port_spin),
|
||||
("调试端口范围", port_range_widget),
|
||||
("CDP就绪超时(秒)", self.cdp_ready_timeout_spin),
|
||||
]
|
||||
)
|
||||
|
||||
update_form = QFormLayout()
|
||||
update_form.addRow("测试商品ID", self.test_item_id_edit)
|
||||
update_form.addRow("", self.allow_real_submit_checkbox)
|
||||
update_form.addRow("", self.allow_cover_update_checkbox)
|
||||
update_form.addRow("单次最大更新条数", self.max_items_per_run_spin)
|
||||
update_form.addRow("", self.close_success_tab_checkbox)
|
||||
update_form.addRow("", self.dry_run_checkbox)
|
||||
update_form.addRow("", self.parallel_accounts_checkbox)
|
||||
update_form.addRow("最大并行账号数", self.max_parallel_accounts_spin)
|
||||
update_form = self._two_column_form(
|
||||
[
|
||||
("测试商品ID", self.test_item_id_edit),
|
||||
("单次最大更新条数", self.max_items_per_run_spin),
|
||||
("", self.allow_real_submit_checkbox),
|
||||
("", self.allow_cover_update_checkbox),
|
||||
("", self.close_success_tab_checkbox),
|
||||
("", self.dry_run_checkbox),
|
||||
("", self.parallel_accounts_checkbox),
|
||||
("最大并行账号数", self.max_parallel_accounts_spin),
|
||||
]
|
||||
)
|
||||
|
||||
right_panel = QWidget()
|
||||
right_layout = QVBoxLayout(right_panel)
|
||||
right_layout.setContentsMargins(12, 0, 0, 0)
|
||||
right_layout.addWidget(QLabel("模型详情"))
|
||||
right_layout.addLayout(form)
|
||||
right_layout.addLayout(action_layout)
|
||||
right_layout.addWidget(self.test_result_label)
|
||||
right_layout.addSpacing(18)
|
||||
right_layout.addWidget(QLabel("角色与生成参数"))
|
||||
right_layout.addLayout(ai_form)
|
||||
right_layout.addSpacing(18)
|
||||
right_layout.addWidget(QLabel("路径与端口"))
|
||||
right_layout.addLayout(path_form)
|
||||
right_layout.addSpacing(18)
|
||||
right_layout.addWidget(QLabel("Shopee 更新安全"))
|
||||
right_layout.addLayout(update_form)
|
||||
right_layout.addWidget(self.save_config_button)
|
||||
right_layout.addStretch(1)
|
||||
panel = QWidget()
|
||||
panel_layout = QVBoxLayout(panel)
|
||||
panel_layout.setContentsMargins(0, 0, 0, 0)
|
||||
panel_layout.addWidget(QLabel("AI 模型"))
|
||||
panel_layout.addLayout(model_picker_layout)
|
||||
panel_layout.addSpacing(14)
|
||||
panel_layout.addWidget(QLabel("模型详情"))
|
||||
panel_layout.addLayout(form)
|
||||
panel_layout.addLayout(action_layout)
|
||||
panel_layout.addWidget(self.test_result_label)
|
||||
panel_layout.addSpacing(18)
|
||||
panel_layout.addWidget(QLabel("角色与生成参数"))
|
||||
panel_layout.addLayout(ai_form)
|
||||
panel_layout.addSpacing(18)
|
||||
panel_layout.addWidget(QLabel("路径与端口"))
|
||||
panel_layout.addLayout(path_form)
|
||||
panel_layout.addSpacing(18)
|
||||
panel_layout.addWidget(QLabel("Shopee 更新安全"))
|
||||
panel_layout.addLayout(update_form)
|
||||
panel_layout.addWidget(self.save_config_button)
|
||||
panel_layout.addStretch(1)
|
||||
|
||||
right_scroll = QScrollArea()
|
||||
right_scroll.setWidgetResizable(True)
|
||||
right_scroll.setWidget(right_panel)
|
||||
|
||||
self.splitter = QSplitter(Qt.Horizontal)
|
||||
self.splitter.addWidget(left_panel)
|
||||
self.splitter.addWidget(right_scroll)
|
||||
self.splitter.setStretchFactor(0, 1)
|
||||
self.splitter.setStretchFactor(1, 3)
|
||||
self.splitter.setSizes([280, 860])
|
||||
scroll = QScrollArea()
|
||||
scroll.setWidgetResizable(True)
|
||||
scroll.setWidget(panel)
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
layout.setContentsMargins(18, 18, 18, 18)
|
||||
layout.addWidget(self.splitter, 1)
|
||||
layout.addWidget(scroll, 1)
|
||||
|
||||
self.model_combo.currentIndexChanged.connect(self.load_selected_model)
|
||||
self.add_model_button.clicked.connect(self.add_model)
|
||||
@@ -3052,6 +3057,47 @@ if QT_IMPORT_ERROR is None:
|
||||
self.refresh_models()
|
||||
self._populate_app_settings()
|
||||
|
||||
def _two_column_form(self, fields):
|
||||
layout = QGridLayout()
|
||||
layout.setHorizontalSpacing(18)
|
||||
layout.setVerticalSpacing(8)
|
||||
layout.setColumnStretch(1, 1)
|
||||
layout.setColumnStretch(3, 1)
|
||||
row = 0
|
||||
column_pair = 0
|
||||
for field in fields:
|
||||
label = field[0]
|
||||
widget = field[1]
|
||||
full_width = len(field) > 2 and bool(field[2])
|
||||
if full_width and column_pair:
|
||||
row += 1
|
||||
column_pair = 0
|
||||
column = column_pair * 2
|
||||
self._add_form_field(layout, row, column, label, widget, full_width)
|
||||
if full_width:
|
||||
row += 1
|
||||
column_pair = 0
|
||||
elif column_pair == 0:
|
||||
column_pair = 1
|
||||
else:
|
||||
row += 1
|
||||
column_pair = 0
|
||||
return layout
|
||||
|
||||
def _add_form_field(self, layout, row, column, label, widget, full_width):
|
||||
if full_width:
|
||||
if label:
|
||||
layout.addWidget(QLabel(label), row, 0)
|
||||
layout.addWidget(widget, row, 1, 1, 3)
|
||||
else:
|
||||
layout.addWidget(widget, row, 0, 1, 4)
|
||||
return
|
||||
if label:
|
||||
layout.addWidget(QLabel(label), row, column)
|
||||
layout.addWidget(widget, row, column + 1)
|
||||
else:
|
||||
layout.addWidget(widget, row, column, 1, 2)
|
||||
|
||||
def _set_status(self, message):
|
||||
if self.status_callback is not None:
|
||||
self.status_callback(message)
|
||||
|
||||
Reference in New Issue
Block a user