mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merge pull request #356 from BigRoy/enhancement/maya_settings_add_json_menu_option
Maya: Allow specifying raw JSON custom tools menu for Maya.
This commit is contained in:
commit
b3d7a233e4
3 changed files with 63 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import json
|
||||
import logging
|
||||
from functools import partial
|
||||
|
||||
|
|
@ -214,8 +215,18 @@ def install(project_settings):
|
|||
)
|
||||
return
|
||||
|
||||
config = project_settings["maya"]["scriptsmenu"]["definition"]
|
||||
_menu = project_settings["maya"]["scriptsmenu"]["name"]
|
||||
menu_settings = project_settings["maya"]["scriptsmenu"]
|
||||
menu_name = menu_settings["name"]
|
||||
config = menu_settings["definition"]
|
||||
|
||||
if menu_settings.get("definition_type") == "definition_json":
|
||||
data = menu_settings["definition_json"]
|
||||
try:
|
||||
config = json.loads(data)
|
||||
except json.JSONDecodeError as exc:
|
||||
print("Skipping studio menu, error decoding JSON definition.")
|
||||
log.error(exc)
|
||||
return
|
||||
|
||||
if not config:
|
||||
log.warning("Skipping studio menu, no definition found.")
|
||||
|
|
@ -223,8 +234,8 @@ def install(project_settings):
|
|||
|
||||
# run the launcher for Maya menu
|
||||
studio_menu = launchformaya.main(
|
||||
title=_menu.title(),
|
||||
objectName=_menu.title().lower().replace(" ", "_")
|
||||
title=menu_name.title(),
|
||||
objectName=menu_name.title().lower().replace(" ", "_")
|
||||
)
|
||||
|
||||
# apply configuration
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
import json
|
||||
|
||||
from pydantic import validator
|
||||
from ayon_server.exceptions import BadRequestException
|
||||
from ayon_server.settings import BaseSettingsModel, SettingsField
|
||||
|
||||
|
||||
|
|
@ -14,19 +18,60 @@ class ScriptsmenuSubmodel(BaseSettingsModel):
|
|||
)
|
||||
|
||||
|
||||
_definition_mode_type = [
|
||||
{"value": "definition", "label": "Menu Builder"},
|
||||
{"value": "definition_json", "label": "Raw JSON (advanced)"}
|
||||
]
|
||||
|
||||
|
||||
class ScriptsmenuModel(BaseSettingsModel):
|
||||
"""Add a custom scripts menu to Maya"""
|
||||
_isGroup = True
|
||||
|
||||
name: str = SettingsField(title="Menu Name")
|
||||
|
||||
definition_type: str = SettingsField(
|
||||
title="Define menu using",
|
||||
description="Choose the way to define the custom scripts menu "
|
||||
"via settings",
|
||||
enum_resolver=lambda: _definition_mode_type,
|
||||
conditionalEnum=True,
|
||||
default="definition"
|
||||
)
|
||||
definition: list[ScriptsmenuSubmodel] = SettingsField(
|
||||
default_factory=list,
|
||||
title="Menu Definition",
|
||||
description="Scriptmenu Items Definition"
|
||||
)
|
||||
definition_json: str = SettingsField(
|
||||
"[]", title="Menu Definition JSON", widget="textarea",
|
||||
description=(
|
||||
"Define the custom tools menu using a JSON list. "
|
||||
"For more details on the JSON format, see "
|
||||
"[here](https://github.com/Colorbleed/scriptsmenu?tab=readme-ov-file#configuration)." # noqa: E501
|
||||
)
|
||||
)
|
||||
|
||||
@validator("definition_json")
|
||||
def validate_json(cls, value):
|
||||
if not value.strip():
|
||||
return "[]"
|
||||
try:
|
||||
converted_value = json.loads(value)
|
||||
success = isinstance(converted_value, list)
|
||||
except json.JSONDecodeError:
|
||||
success = False
|
||||
|
||||
if not success:
|
||||
raise BadRequestException(
|
||||
"The definition can't be parsed as json list object"
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
DEFAULT_SCRIPTSMENU_SETTINGS = {
|
||||
"name": "Custom Tools",
|
||||
"definition_type": "definition",
|
||||
"definition": [
|
||||
{
|
||||
"type": "action",
|
||||
|
|
@ -39,5 +84,6 @@ DEFAULT_SCRIPTSMENU_SETTINGS = {
|
|||
"shader"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"definition_json": "[]"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Package declaring addon version."""
|
||||
__version__ = "0.1.14"
|
||||
__version__ = "0.1.15"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue