mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
Allow specifying raw JSON custom tools menu for Maya.
This commit is contained in:
parent
9ba450fe8b
commit
dd77f243dd
2 changed files with 51 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import json
|
||||
import logging
|
||||
from functools import partial
|
||||
|
||||
|
|
@ -214,9 +215,18 @@ def install(project_settings):
|
|||
)
|
||||
return
|
||||
|
||||
config = project_settings["maya"]["scriptsmenu"]["definition"]
|
||||
_menu = project_settings["maya"]["scriptsmenu"]["name"]
|
||||
|
||||
config = project_settings["maya"]["scriptsmenu"]["definition"]
|
||||
if project_settings["maya"]["scriptsmenu"].get("use_json_definition"):
|
||||
data = project_settings["maya"]["scriptsmenu"]["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.")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
import json
|
||||
|
||||
from pydantic import validator
|
||||
from ayon_server.exceptions import BadRequestException
|
||||
from ayon_server.settings import BaseSettingsModel, SettingsField
|
||||
|
||||
|
||||
|
|
@ -15,18 +19,52 @@ class ScriptsmenuSubmodel(BaseSettingsModel):
|
|||
|
||||
|
||||
class ScriptsmenuModel(BaseSettingsModel):
|
||||
"""Add a custom scripts menu to Maya"""
|
||||
_isGroup = True
|
||||
|
||||
name: str = SettingsField(title="Menu Name")
|
||||
use_json_definition: bool = SettingsField(
|
||||
title="Use Raw JSON Definition",
|
||||
description="When enabled, the definition field will be ignored. "
|
||||
"Instead the menu will be build from the raw JSON "
|
||||
"definition below it."
|
||||
)
|
||||
definition: list[ScriptsmenuSubmodel] = SettingsField(
|
||||
default_factory=list,
|
||||
title="Menu Definition",
|
||||
description="Scriptmenu Items Definition"
|
||||
)
|
||||
|
||||
definition_json: str = SettingsField(
|
||||
"[]", title="Definition JSON", widget="textarea",
|
||||
description=(
|
||||
"When Use Raw JSON definition is enabled this field will be used "
|
||||
"to put the direct JSON content instead of using the definition "
|
||||
"menu builder UI above. 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",
|
||||
"use_json_definition": False,
|
||||
"definition": [
|
||||
{
|
||||
"type": "action",
|
||||
|
|
@ -39,5 +77,6 @@ DEFAULT_SCRIPTSMENU_SETTINGS = {
|
|||
"shader"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"definition_raw": ""
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue