feat: Update AI environment labels and preferences for consistency

This commit is contained in:
2026-09-02 12:55:11 +08:00
parent 5a011b3b57
commit 8d279e9ab3
7 changed files with 205 additions and 123 deletions

View File

@@ -690,7 +690,7 @@ class BlenderAddonTest(unittest.TestCase):
status = properties.ai_status()
self.assertFalse(status["ready"])
self.assertEqual(
properties.ai_setup_label(status), "Set Up AI Environment…"
properties.ai_setup_label(status), "Set Up AI Server…"
)
def test_setup_ai_environment_selects_the_needed_install_step(self):
@@ -741,6 +741,10 @@ class BlenderAddonTest(unittest.TestCase):
self.ai_setup.OpenAIEnvironmentSettings,
self.anyimage.CLASSES,
)
self.assertEqual(self.ai_setup.SetupAIEnvironment.bl_label, "Set Up AI Server")
self.assertEqual(
self.ai_setup.OpenAIEnvironmentSettings.bl_label, "Settings"
)
def test_global_ai_input_size_defaults_and_clamps(self):
preference_module = self.anyimage.preferences
@@ -785,7 +789,7 @@ class BlenderAddonTest(unittest.TestCase):
downloads = []
properties = []
labels = []
panels = []
boxes = []
class Layout:
enabled = True
@@ -802,9 +806,15 @@ class BlenderAddonTest(unittest.TestCase):
def row(self, **_options):
return self
def panel(self, panel_id, **options):
panels.append((panel_id, options.get("default_closed")))
return self, self
def split(self, **_options):
return self
def column(self, **_options):
return self
def box(self):
boxes.append(self)
return self
def operator(self, identifier, **_options):
operator = SimpleNamespace(model="")
@@ -815,6 +825,7 @@ class BlenderAddonTest(unittest.TestCase):
preferences = preference_module.AnyImagePreferences()
preferences.layout = Layout()
preferences.geometry_model = "MOGE2_VITS_NORMAL"
preferences.background_model = "BEN2_BASE"
preferences.upscale_model = "SAFMN_REAL_X4"
catalog = tuple(
{
@@ -861,33 +872,24 @@ class BlenderAddonTest(unittest.TestCase):
for label in labels
if label
in {
"Environment",
"Server",
"AI",
"Tools",
"Depth & Normal",
"Cutout",
"Remove Background",
"Upscale",
"Diagnostics",
"Cutout Tool",
}
],
[
"Environment",
"Diagnostics",
"Server",
"AI",
"Tools",
"Depth & Normal",
"Remove Background",
"Upscale",
"Cutout",
],
)
self.assertEqual(
panels,
[
("anyimage_preferences_depth_normal", False),
("anyimage_preferences_remove_background", False),
("anyimage_preferences_upscale", False),
("anyimage_preferences_cutout", False),
"Cutout Tool",
],
)
self.assertEqual(len(boxes), 3)
self.assertNotIn("Normal Model", labels)
self.assertIn("background_model", properties)
self.assertIn("upscale_model", properties)
self.assertIn("max_ai_input_size", properties)
self.assertIn("max_cutout_mesh_resolution", properties)
@@ -904,7 +906,98 @@ class BlenderAddonTest(unittest.TestCase):
preference_module.AnyImagePreferences.__annotations__["upscale_model"][
"name"
],
"Default Upscale Model",
"Upscale Image Model",
)
self.assertEqual(
preference_module.AnyImagePreferences.__annotations__["geometry_model"][
"name"
],
"Generate Depth Map Model",
)
self.assertEqual(
preference_module.AnyImagePreferences.__annotations__["background_model"][
"name"
],
"Remove Background Model",
)
def test_ready_models_show_their_ai_feature(self):
preference_module = importlib.import_module("anyimage.preferences")
labels = []
class Layout:
def row(self, **_options):
return self
def label(self, **options):
labels.append((options.get("text"), options.get("icon")))
preferences = preference_module.AnyImagePreferences()
model = {"ready": True}
for ready_label in (
"AI Generate Depth Map",
"AI Remove Background",
"AI Upscale Image",
):
preferences._draw_model_status(Layout(), model, ready_label)
self.assertEqual(
labels,
[
("AI Generate Depth Map", "CHECKMARK"),
("AI Remove Background", "CHECKMARK"),
("AI Upscale Image", "CHECKMARK"),
],
)
def test_preferences_hide_ai_until_server_is_installed(self):
preference_module = importlib.import_module("anyimage.preferences")
labels = []
operators = []
class Layout:
enabled = True
def box(self):
return self
def label(self, **options):
labels.append(options.get("text"))
def prop(self, *_args, **_options):
return None
def row(self, **_options):
return self
def separator(self, **_options):
return None
def operator(self, identifier, **_options):
operators.append(identifier)
return SimpleNamespace(model="")
preferences = preference_module.AnyImagePreferences()
preferences.layout = Layout()
with (
patch.object(
self.anyimage.properties,
"ai_status",
return_value={
"environment_ready": False,
"missing_models": (),
"ready": False,
},
),
patch.object(self.anyimage.properties, "model_catalog", return_value=()),
patch.object(self.anyimage.runtime, "server_busy", return_value=False),
):
preferences.draw(None)
self.assertEqual(labels, ["Server", "Tools", "Depth & Normal", "Cutout Tool"])
self.assertEqual(
operators,
["anyimage.setup_ai_environment", "anyimage.open_server_log"],
)
def test_semantic_mesh_operators_are_registered_without_dialog_options(self):