feat(product-suite): compact controls and remember settings
This commit is contained in:
@@ -32,6 +32,15 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertEqual("title", appconfig.shopee_update_config(config)["update_mode"])
|
||||
self.assertNotIn("allow_cover_update", appconfig.shopee_update_config(config))
|
||||
self.assertEqual(1, appconfig.shopee_update_config(config)["max_parallel_accounts"])
|
||||
self.assertEqual(
|
||||
{
|
||||
"platform": "Shopee",
|
||||
"country": "中国台湾",
|
||||
"language": "繁体中文",
|
||||
"ratio": "1:1",
|
||||
},
|
||||
appconfig.product_suite_last_settings(config),
|
||||
)
|
||||
|
||||
updated = appconfig.update_config(
|
||||
{"ai": {"resolution": "2k"}},
|
||||
@@ -66,6 +75,66 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_product_suite_last_settings_are_normalized_and_preserve_other_config(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
config_path = os.path.join(temp_dir, "config.json")
|
||||
with open(config_path, "w", encoding="utf-8") as fh:
|
||||
json.dump(
|
||||
{
|
||||
"chrome_path": "custom-chrome.exe",
|
||||
"custom_section": {"keep": True},
|
||||
"product_suite": {
|
||||
"last_settings": {
|
||||
"platform": "未知平台",
|
||||
"country": "新加坡",
|
||||
"language": "英文",
|
||||
"ratio": "2:3",
|
||||
"unexpected": "ignore",
|
||||
}
|
||||
},
|
||||
},
|
||||
fh,
|
||||
ensure_ascii=False,
|
||||
)
|
||||
|
||||
loaded = appconfig.load_config(config_path)
|
||||
|
||||
self.assertEqual(
|
||||
{
|
||||
"platform": "Shopee",
|
||||
"country": "新加坡",
|
||||
"language": "英文",
|
||||
"ratio": "1:1",
|
||||
},
|
||||
appconfig.product_suite_last_settings(loaded),
|
||||
)
|
||||
|
||||
updated = appconfig.update_config(
|
||||
{
|
||||
"product_suite": {
|
||||
"last_settings": {
|
||||
"platform": "Amazon",
|
||||
"country": "中国台湾",
|
||||
"language": "繁体中文",
|
||||
"ratio": "16:9",
|
||||
}
|
||||
}
|
||||
},
|
||||
path=config_path,
|
||||
)
|
||||
|
||||
self.assertEqual("custom-chrome.exe", updated["chrome_path"])
|
||||
self.assertEqual({"keep": True}, updated["custom_section"])
|
||||
self.assertEqual("16:9", appconfig.product_suite_last_settings(updated)["ratio"])
|
||||
with open(config_path, "r", encoding="utf-8") as fh:
|
||||
persisted = json.load(fh)
|
||||
self.assertEqual(
|
||||
{"platform", "country", "language", "ratio"},
|
||||
set(persisted["product_suite"]["last_settings"]),
|
||||
)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_shopee_update_legacy_parallel_config_is_migrated(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
config_path = os.path.join(temp_dir, "config.json")
|
||||
|
||||
@@ -37,6 +37,38 @@ class ProductSuiteTests(unittest.TestCase):
|
||||
self.assertEqual(["白底图", "场景图", "卖点图", "尺寸图"], product_suite.category_order(settings))
|
||||
self.assertEqual(5, product_suite.suite_total_count(settings, 1))
|
||||
|
||||
def test_recent_settings_only_keep_allowed_dropdown_values(self):
|
||||
self.assertEqual(
|
||||
{
|
||||
"platform": "Shopee",
|
||||
"country": "中国台湾",
|
||||
"language": "繁体中文",
|
||||
"ratio": "1:1",
|
||||
},
|
||||
product_suite.last_suite_settings(
|
||||
{
|
||||
"platform": "未知平台",
|
||||
"country": "未知站点",
|
||||
"language": "未知语言",
|
||||
"ratio": "2:3",
|
||||
"per_image_primary": True,
|
||||
"categories": {"白底图": 9},
|
||||
}
|
||||
),
|
||||
)
|
||||
selected = product_suite.last_suite_settings(
|
||||
{
|
||||
"platform": "Amazon",
|
||||
"country": "新加坡",
|
||||
"language": "英文",
|
||||
"ratio": "4:3",
|
||||
}
|
||||
)
|
||||
self.assertEqual("Amazon", selected["platform"])
|
||||
self.assertEqual("新加坡", selected["country"])
|
||||
self.assertEqual("英文", selected["language"])
|
||||
self.assertEqual("4:3", selected["ratio"])
|
||||
|
||||
def test_job_specs_include_selected_context_and_source_assignment(self):
|
||||
settings = product_suite.default_suite_settings()
|
||||
settings.update(
|
||||
|
||||
@@ -7,7 +7,7 @@ sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from _helpers import TempDirMixin
|
||||
|
||||
from app import accounts, image_studio, image_studio_images
|
||||
from app import accounts, appconfig, image_studio, image_studio_images
|
||||
from app import gui
|
||||
|
||||
if gui.QT_IMPORT_ERROR is not None:
|
||||
@@ -52,6 +52,9 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
|
||||
accounts.create_account("主店", "alias-a", debug_port=9222, config=config)
|
||||
tab = ProductSuiteTab(config=config, db_path=config["db_path"])
|
||||
self.addCleanup(tab.close)
|
||||
tab.resize(1180, 760)
|
||||
tab.show()
|
||||
self.app.processEvents()
|
||||
|
||||
self.assertEqual("productSuiteTab", tab.objectName())
|
||||
self.assertEqual(1, tab.task_tabs.count())
|
||||
@@ -61,6 +64,54 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
|
||||
self.assertEqual("中国台湾", tab.country_combo.currentData())
|
||||
self.assertEqual("繁体中文", tab.language_combo.currentData())
|
||||
self.assertEqual("1:1", tab.ratio_combo.currentData())
|
||||
self.assertEqual("Shopee", tab.platform_combo.currentText())
|
||||
self.assertEqual("中国台湾", tab.country_combo.currentText())
|
||||
self.assertEqual("繁体中文", tab.language_combo.currentText())
|
||||
self.assertEqual("1:1", tab.ratio_combo.currentText())
|
||||
self.assertEqual("平台", tab.platform_label.text())
|
||||
self.assertEqual("站点", tab.country_label.text())
|
||||
self.assertEqual("语言", tab.language_label.text())
|
||||
self.assertEqual("比例", tab.ratio_label.text())
|
||||
for column, combo in enumerate(
|
||||
(
|
||||
tab.platform_combo,
|
||||
tab.country_combo,
|
||||
tab.language_combo,
|
||||
tab.ratio_combo,
|
||||
)
|
||||
):
|
||||
self.assertIs(combo, tab.settings_grid.itemAtPosition(1, column).widget())
|
||||
self.assertEqual(
|
||||
1,
|
||||
len(
|
||||
{
|
||||
tab.platform_combo.width(),
|
||||
tab.country_combo.width(),
|
||||
tab.language_combo.width(),
|
||||
tab.ratio_combo.width(),
|
||||
}
|
||||
),
|
||||
)
|
||||
self.assertLessEqual(tab.task_tabs.maximumHeight(), 36)
|
||||
self.assertEqual(120, tab.account_combo.minimumWidth())
|
||||
self.assertEqual(160, tab.account_combo.maximumWidth())
|
||||
self.assertGreaterEqual(tab.item_id_edit.minimumWidth(), 120)
|
||||
self.assertLessEqual(tab.item_id_edit.maximumWidth(), 140)
|
||||
self.assertLess(
|
||||
tab.context_bar_layout.indexOf(tab.history_button),
|
||||
tab.context_bar_layout.indexOf(tab.account_combo),
|
||||
)
|
||||
self.assertLess(
|
||||
tab.context_bar_layout.indexOf(tab.open_folder_button),
|
||||
tab.context_bar_layout.indexOf(tab.account_combo),
|
||||
)
|
||||
self.assertLess(
|
||||
tab.context_bar_layout.indexOf(tab.add_images_button),
|
||||
tab.context_bar_layout.indexOf(tab.account_combo),
|
||||
)
|
||||
self.assertEqual(-1, tab.results_toolbar_layout.indexOf(tab.history_button))
|
||||
self.assertEqual(-1, tab.results_toolbar_layout.indexOf(tab.open_folder_button))
|
||||
self.assertEqual("打开结果文件夹", tab.open_folder_button.text())
|
||||
self.assertEqual("合计 5 张", tab.category_total_label.text())
|
||||
self.assertEqual("生成套图(5)", tab.generate_button.text())
|
||||
|
||||
@@ -84,6 +135,64 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_recent_dropdown_settings_restore_after_restart_and_project_wins(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
config_path = os.path.join(temp_dir, "config.json")
|
||||
config = appconfig.save_config(self._config(temp_dir), path=config_path)
|
||||
account = accounts.create_account(
|
||||
"主店",
|
||||
"alias-a",
|
||||
debug_port=9222,
|
||||
config=config,
|
||||
)
|
||||
project = image_studio.create_or_get_project(
|
||||
account,
|
||||
item_id="51100639510",
|
||||
path=config["db_path"],
|
||||
)
|
||||
project_settings = image_studio.project_suite_settings(project)
|
||||
project_settings["ratio"] = "4:3"
|
||||
image_studio.update_project_suite_settings(
|
||||
project.id,
|
||||
project_settings,
|
||||
path=config["db_path"],
|
||||
)
|
||||
|
||||
first = ProductSuiteTab(
|
||||
config=config,
|
||||
config_path=config_path,
|
||||
db_path=config["db_path"],
|
||||
)
|
||||
first.ratio_combo.setCurrentIndex(first.ratio_combo.findData("16:9"))
|
||||
self.assertEqual(
|
||||
"16:9",
|
||||
appconfig.product_suite_last_settings(
|
||||
appconfig.load_config(config_path)
|
||||
)["ratio"],
|
||||
)
|
||||
first.close()
|
||||
first.deleteLater()
|
||||
self.app.processEvents()
|
||||
|
||||
reloaded = appconfig.load_config(config_path)
|
||||
second = ProductSuiteTab(
|
||||
config=reloaded,
|
||||
config_path=config_path,
|
||||
db_path=reloaded["db_path"],
|
||||
)
|
||||
self.addCleanup(second.close)
|
||||
self.assertEqual("16:9", second.ratio_combo.currentData())
|
||||
|
||||
state = second._displayed_state
|
||||
state.account_alias = "alias-a"
|
||||
state.item_id = "51100639510"
|
||||
second._bind_project(state, load_existing=True)
|
||||
|
||||
self.assertEqual("4:3", second.ratio_combo.currentData())
|
||||
self.assertEqual("4:3", state.settings["ratio"])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_task_tabs_keep_independent_prompt_and_settings(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
config = self._config(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user