feat(product-suite): remove fixed original image placeholders
This commit is contained in:
@@ -153,6 +153,7 @@ class ProductOriginalDelegate(QStyledItemDelegate):
|
||||
|
||||
class ProductOriginalList(QListWidget):
|
||||
MAX_VISIBLE_ASSETS = 16
|
||||
EMPTY_STATE_TEXT = "暂无商品原图"
|
||||
|
||||
filesDropped = Signal(list)
|
||||
clipboardImage = Signal(bytes)
|
||||
@@ -191,7 +192,20 @@ class ProductOriginalList(QListWidget):
|
||||
self._hover_remove_button.setFixedSize(28, 28)
|
||||
self._hover_remove_button.clicked.connect(self._remove_hovered)
|
||||
self._hover_remove_button.hide()
|
||||
self.setToolTip("点击添加图片;也可拖入图片、粘贴图片或拖动缩略图排序")
|
||||
self.setToolTip("可拖入或粘贴图片;已有缩略图可拖动排序")
|
||||
|
||||
def paintEvent(self, event):
|
||||
super().paintEvent(event)
|
||||
if self.count() != 0:
|
||||
return
|
||||
painter = QPainter(self.viewport())
|
||||
painter.setPen(QColor("#6b7280"))
|
||||
painter.drawText(
|
||||
self.viewport().rect().adjusted(12, 8, -12, -8),
|
||||
Qt.AlignCenter,
|
||||
self.EMPTY_STATE_TEXT,
|
||||
)
|
||||
painter.end()
|
||||
|
||||
def dragEnterEvent(self, event):
|
||||
if event.mimeData().hasUrls():
|
||||
@@ -319,9 +333,11 @@ class ProductOriginalList(QListWidget):
|
||||
return max(1, (available + self.spacing()) // step)
|
||||
|
||||
def content_row_count(self):
|
||||
count = min(self.MAX_VISIBLE_ASSETS, max(1, self.count()))
|
||||
count = min(self.MAX_VISIBLE_ASSETS, self.count())
|
||||
if count == 0:
|
||||
return 1
|
||||
columns = self.content_column_count()
|
||||
return max(1, (count + columns - 1) // columns)
|
||||
return (count + columns - 1) // columns
|
||||
|
||||
def update_content_height(self):
|
||||
rows = self.content_row_count()
|
||||
@@ -741,6 +757,19 @@ class ProductSuiteTab(QWidget):
|
||||
layout.addWidget(self.open_folder_button)
|
||||
self.add_images_button = QPushButton("添加图片")
|
||||
self.add_images_button.setObjectName("suiteAddImagesButton")
|
||||
self.add_images_button.setAccessibleName("添加商品原图")
|
||||
self.add_images_button.setToolTip("添加本地商品原图")
|
||||
self.add_images_button.setStyleSheet(
|
||||
"QPushButton#suiteAddImagesButton { "
|
||||
"color: #0969da; border: 1px solid #0969da; "
|
||||
"background-color: #eef4ff; font-weight: 600; "
|
||||
"}"
|
||||
"QPushButton#suiteAddImagesButton:hover { background-color: #dbeafe; }"
|
||||
"QPushButton#suiteAddImagesButton:pressed { background-color: #c7ddff; }"
|
||||
"QPushButton#suiteAddImagesButton:disabled { "
|
||||
"color: #8c959f; border-color: #d8dee4; background-color: #f6f8fa; "
|
||||
"}"
|
||||
)
|
||||
layout.addWidget(self.add_images_button)
|
||||
layout.addStretch(1)
|
||||
layout.addWidget(QLabel("账号"))
|
||||
@@ -1396,6 +1425,25 @@ class ProductSuiteTab(QWidget):
|
||||
self.pull_button.setEnabled(
|
||||
self._valid_context(state, show_message=False) and state.pull_worker is None
|
||||
)
|
||||
self._refresh_add_images_action(state)
|
||||
|
||||
def _refresh_add_images_action(self, state):
|
||||
asset_count = len(self._original_assets(state, include_missing=True)) if state else 0
|
||||
full = asset_count >= image_studio_images.MAX_ORIGINAL_ASSETS
|
||||
generation_running = bool(state and state.generation_running())
|
||||
importing = bool(state and state.import_worker is not None)
|
||||
self.add_images_button.setEnabled(
|
||||
state is not None and not full and not generation_running and not importing
|
||||
)
|
||||
if full:
|
||||
tooltip = "已达到16张商品原图上限"
|
||||
elif generation_running:
|
||||
tooltip = "生成中不能添加商品原图"
|
||||
elif importing:
|
||||
tooltip = "正在添加商品原图"
|
||||
else:
|
||||
tooltip = "添加本地商品原图"
|
||||
self.add_images_button.setToolTip(tooltip)
|
||||
|
||||
def _start_thread(self, worker, name):
|
||||
thread = run_worker(worker, thread_name=name, start=False)
|
||||
@@ -1431,14 +1479,6 @@ class ProductSuiteTab(QWidget):
|
||||
item.setIcon(QIcon(_placeholder_pixmap("待下载", QSize(82, 64))))
|
||||
item.setToolTip("%s尚未下载;勾选可批量删除,单击缩略图后台拉取" % label)
|
||||
self.original_list.addItem(item)
|
||||
for index in range(len(assets) + 1, 7):
|
||||
label = "主图" if index == 1 else "参考%d" % (index - 1)
|
||||
item = QListWidgetItem(label)
|
||||
item.setData(Qt.UserRole, None)
|
||||
item.setIcon(QIcon(_placeholder_pixmap("添加", QSize(82, 64))))
|
||||
item.setToolTip("点击添加%s" % label)
|
||||
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
|
||||
self.original_list.addItem(item)
|
||||
finally:
|
||||
self.original_list.blockSignals(previous)
|
||||
self._original_list_context = context
|
||||
@@ -1446,6 +1486,7 @@ class ProductSuiteTab(QWidget):
|
||||
self.original_list.viewport().update()
|
||||
self.original_count_label.setText("%d/16" % len(assets))
|
||||
self._refresh_original_selection_controls()
|
||||
self._refresh_add_images_action(state)
|
||||
self._refresh_totals(state)
|
||||
|
||||
def _on_original_checks_changed(self, asset_ids):
|
||||
@@ -1512,6 +1553,8 @@ class ProductSuiteTab(QWidget):
|
||||
config=self.config,
|
||||
)
|
||||
state.import_worker = worker
|
||||
if state is self._displayed_state:
|
||||
self._refresh_add_images_action(state)
|
||||
worker.finished.connect(lambda result, state=state: self._on_import_finished(state, result))
|
||||
worker.cancelled.connect(lambda result, state=state: self._on_import_finished(state, result))
|
||||
worker.failed.connect(lambda row, error, state=state: self._on_import_failed(state, error))
|
||||
@@ -1519,7 +1562,11 @@ class ProductSuiteTab(QWidget):
|
||||
self._status("正在后台添加商品原图", "info")
|
||||
|
||||
def _on_import_failed(self, state, error):
|
||||
state.import_worker = None
|
||||
state.import_thread = None
|
||||
self._status("添加商品原图失败:%s" % _user_error(error), "danger")
|
||||
if state is self._displayed_state:
|
||||
self._refresh_add_images_action(state)
|
||||
|
||||
def _on_import_finished(self, state, result):
|
||||
state.import_worker = None
|
||||
@@ -1622,9 +1669,6 @@ class ProductSuiteTab(QWidget):
|
||||
|
||||
def _on_original_clicked(self, item):
|
||||
asset = self._asset_for_item(item)
|
||||
if asset is None and item.data(Qt.UserRole) is None:
|
||||
self.choose_images()
|
||||
return
|
||||
if asset is not None and not _asset_usable(asset) and asset.remote_url:
|
||||
self._queue_original_downloads(self._displayed_state, [asset])
|
||||
|
||||
@@ -2107,7 +2151,7 @@ class ProductSuiteTab(QWidget):
|
||||
self.pull_button.setText("正在拉取..." if state.pull_worker is not None else "拉取蝦皮主图")
|
||||
self.account_combo.setEnabled(not generation_running and state.pull_worker is None)
|
||||
self.item_id_edit.setEnabled(not generation_running and state.pull_worker is None)
|
||||
self.add_images_button.setEnabled(not generation_running and state.import_worker is None)
|
||||
self._refresh_add_images_action(state)
|
||||
self.original_list.setEnabled(not generation_running)
|
||||
self._refresh_original_selection_controls()
|
||||
for widget in (
|
||||
|
||||
Reference in New Issue
Block a user