From c807bef0cb1c028c15d67d08c2576faf406d8171 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Jun 2021 12:43:07 +0200 Subject: [PATCH 1/7] added `hosts-enum` entity for settings --- openpype/settings/entities/__init__.py | 2 + openpype/settings/entities/enum_entity.py | 52 +++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/openpype/settings/entities/__init__.py b/openpype/settings/entities/__init__.py index f64ca1e98d7..94eb819f2b4 100644 --- a/openpype/settings/entities/__init__.py +++ b/openpype/settings/entities/__init__.py @@ -101,6 +101,7 @@ from .enum_entity import ( BaseEnumEntity, EnumEntity, + HostsEnumEntity, AppsEnumEntity, ToolsEnumEntity, TaskTypeEnumEntity, @@ -153,6 +154,7 @@ "BaseEnumEntity", "EnumEntity", + "HostsEnumEntity", "AppsEnumEntity", "ToolsEnumEntity", "TaskTypeEnumEntity", diff --git a/openpype/settings/entities/enum_entity.py b/openpype/settings/entities/enum_entity.py index 0b0575a2557..add5c0298ca 100644 --- a/openpype/settings/entities/enum_entity.py +++ b/openpype/settings/entities/enum_entity.py @@ -101,6 +101,58 @@ def schema_validations(self): super(EnumEntity, self).schema_validations() +class HostsEnumEntity(BaseEnumEntity): + schema_types = ["hosts-enum"] + + def _item_initalization(self): + self.multiselection = self.schema_data.get("multiselection", True) + self.use_empty_value = self.schema_data.get( + "use_empty_value", not self.multiselection + ) + self.empty_label = ( + self.schema_data.get("empty_label") or "< without host >" + ) + + self.enum_items = [ + {"aftereffects": "aftereffects"}, + {"blender": "blender"}, + {"celaction": "celaction"}, + {"fusion": "fusion"}, + {"harmony": "harmony"}, + {"hiero": "hiero"}, + {"houdini": "houdini"}, + {"maya": "maya"}, + {"nuke": "nuke"}, + {"photoshop": "photoshop"}, + {"resolve": "resolve"}, + {"tvpaint": "tvpaint"}, + {"unreal": "unreal"} + ] + + if self.use_empty_value: + self.enum_items.insert(0, {"": self.empty_label}) + + valid_keys = set() + for item in self.enum_items or []: + valid_keys.add(tuple(item.keys())[0]) + + self.valid_keys = valid_keys + + if self.multiselection: + self.valid_value_types = (list, ) + self.value_on_not_set = [] + else: + for key in valid_keys: + if self.value_on_not_set is NOT_SET: + self.value_on_not_set = key + break + + self.valid_value_types = (STRING_TYPE, ) + + # GUI attribute + self.placeholder = self.schema_data.get("placeholder") + + class AppsEnumEntity(BaseEnumEntity): schema_types = ["apps-enum"] From c1bb5fec8f6ecf3689408653210fc081039d93d9 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Jun 2021 12:43:56 +0200 Subject: [PATCH 2/7] use host-enum instead of list of strings for hosts --- .../projects_schema/schema_project_slack.json | 4 ++-- .../schemas/schema_global_publish.json | 12 ++++++------ .../projects_schema/schemas/schema_global_tools.json | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openpype/settings/entities/schemas/projects_schema/schema_project_slack.json b/openpype/settings/entities/schemas/projects_schema/schema_project_slack.json index 58708776caa..170de7c8a27 100644 --- a/openpype/settings/entities/schemas/projects_schema/schema_project_slack.json +++ b/openpype/settings/entities/schemas/projects_schema/schema_project_slack.json @@ -59,10 +59,10 @@ "object_type": "text" }, { + "type": "hosts-enum", "key": "hosts", "label": "Host names", - "type": "list", - "object_type": "text" + "multiselection": true }, { "type": "separator" diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_publish.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_publish.json index 8ca203e3bc8..496635287fc 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_publish.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_publish.json @@ -90,10 +90,10 @@ "object_type": "text" }, { + "type": "hosts-enum", "key": "hosts", "label": "Hosts", - "type": "list", - "object_type": "text" + "multiselection": true }, { "type": "splitter" @@ -358,10 +358,10 @@ "object_type": "text" }, { + "type": "hosts-enum", "key": "hosts", "label": "Hosts", - "type": "list", - "object_type": "text" + "multiselection": true }, { "type": "splitter" @@ -492,10 +492,10 @@ "object_type": "text" }, { + "type": "hosts-enum", "key": "hosts", "label": "Hosts", - "type": "list", - "object_type": "text" + "multiselection": true }, { "key": "tasks", diff --git a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json index 224389d42ed..8c92a45a569 100644 --- a/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json +++ b/openpype/settings/entities/schemas/projects_schema/schemas/schema_global_tools.json @@ -35,10 +35,10 @@ "object_type": "text" }, { + "type": "hosts-enum", "key": "hosts", "label": "Hosts", - "type": "list", - "object_type": "text" + "multiselection": true }, { "key": "tasks", @@ -75,10 +75,10 @@ "type": "dict", "children": [ { + "type": "hosts-enum", "key": "hosts", "label": "Hosts", - "type": "list", - "object_type": "text" + "multiselection": true }, { "key": "tasks", From 9d84a39e11653d6f88f774d94e0963816ea51943 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Jun 2021 12:44:18 +0200 Subject: [PATCH 3/7] replaced hosts enum in applications with hosts-enum --- .../template_host_unchangables.json | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/openpype/settings/entities/schemas/system_schema/host_settings/template_host_unchangables.json b/openpype/settings/entities/schemas/system_schema/host_settings/template_host_unchangables.json index e8b2a700766..c4d8d892095 100644 --- a/openpype/settings/entities/schemas/system_schema/host_settings/template_host_unchangables.json +++ b/openpype/settings/entities/schemas/system_schema/host_settings/template_host_unchangables.json @@ -14,25 +14,11 @@ "roles": ["developer"] }, { - "type": "enum", + "type": "hosts-enum", "key": "host_name", "label": "Host implementation", - "enum_items": [ - { "": "< without host >" }, - { "aftereffects": "aftereffects" }, - { "blender": "blender" }, - { "celaction": "celaction" }, - { "fusion": "fusion" }, - { "harmony": "harmony" }, - { "hiero": "hiero" }, - { "houdini": "houdini" }, - { "maya": "maya" }, - { "nuke": "nuke" }, - { "photoshop": "photoshop" }, - { "resolve": "resolve" }, - { "tvpaint": "tvpaint" }, - { "unreal": "unreal" } - ], + "multiselection": false, + "use_empty_value": true, "roles": ["developer"] } ] From fbcb46ac0922cc03c69262d709c765ba319d5803 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Jun 2021 12:51:44 +0200 Subject: [PATCH 4/7] adde hosts-enum to readme --- openpype/settings/entities/schemas/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/openpype/settings/entities/schemas/README.md b/openpype/settings/entities/schemas/README.md index 6c31b61f594..0ad13bfe1a7 100644 --- a/openpype/settings/entities/schemas/README.md +++ b/openpype/settings/entities/schemas/README.md @@ -272,6 +272,22 @@ } ``` +### hosts-enum +- enumeration of available hosts +- multiselection can be allowed with setting key `"multiselection"` to `True` (Default: `False`) +- it is possible to add empty value (represented with empty string) with setting `"use_empty_value"` to `True` (Default: `False`) +- to modify label of empty value set `"empty_label"` key with your label (Default: `< without host >`) +``` +{ + "key": "host", + "label": "Host name", + "type": "hosts-enum", + "multiselection": false, + "use_empty_value": true, + "empty_label": "N/A" +} +``` + ## Inputs for setting value using Pure inputs - these inputs also have required `"key"` - attribute `"label"` is required in few conditions From d7ab6bb7ae8e2c33adf247978f884552c808e10d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Jun 2021 12:57:19 +0200 Subject: [PATCH 5/7] added few comments --- openpype/settings/entities/enum_entity.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/openpype/settings/entities/enum_entity.py b/openpype/settings/entities/enum_entity.py index add5c0298ca..050f0038f70 100644 --- a/openpype/settings/entities/enum_entity.py +++ b/openpype/settings/entities/enum_entity.py @@ -102,6 +102,21 @@ def schema_validations(self): class HostsEnumEntity(BaseEnumEntity): + """Enumeration of host names. + + Enum items are hardcoded in definition of the entity. + + Hosts enum can have defined empty value as valid option which is + represented by empty string. Schema key to set this option is + `use_empty_value` (true/false). And to set label of empty value set + `empty_label` (string). + + Enum can have single and multiselection. + + NOTE: + Host name is not the same as application name. Host name defines + implementation instead of application name. + """ schema_types = ["hosts-enum"] def _item_initalization(self): @@ -113,6 +128,7 @@ def _item_initalization(self): self.schema_data.get("empty_label") or "< without host >" ) + # These are hardcoded there is not list of available host in OpenPype self.enum_items = [ {"aftereffects": "aftereffects"}, {"blender": "blender"}, From a7962aa3a05769a14a8091a7445e63945656b900 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Jun 2021 14:09:48 +0200 Subject: [PATCH 6/7] modified how labels in hosts enum works --- openpype/settings/entities/enum_entity.py | 50 +++++++++++--------- openpype/settings/entities/schemas/README.md | 7 ++- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/openpype/settings/entities/enum_entity.py b/openpype/settings/entities/enum_entity.py index 050f0038f70..d197683afe3 100644 --- a/openpype/settings/entities/enum_entity.py +++ b/openpype/settings/entities/enum_entity.py @@ -124,34 +124,38 @@ def _item_initalization(self): self.use_empty_value = self.schema_data.get( "use_empty_value", not self.multiselection ) - self.empty_label = ( - self.schema_data.get("empty_label") or "< without host >" - ) - - # These are hardcoded there is not list of available host in OpenPype - self.enum_items = [ - {"aftereffects": "aftereffects"}, - {"blender": "blender"}, - {"celaction": "celaction"}, - {"fusion": "fusion"}, - {"harmony": "harmony"}, - {"hiero": "hiero"}, - {"houdini": "houdini"}, - {"maya": "maya"}, - {"nuke": "nuke"}, - {"photoshop": "photoshop"}, - {"resolve": "resolve"}, - {"tvpaint": "tvpaint"}, - {"unreal": "unreal"} + custom_labels = self.schema_data.get("custom_labels") or {} + + host_names = [ + "aftereffects", + "blender", + "celaction", + "fusion", + "harmony", + "hiero", + "houdini", + "maya", + "nuke", + "photoshop", + "resolve", + "tvpaint", + "unreal" ] - if self.use_empty_value: - self.enum_items.insert(0, {"": self.empty_label}) + host_names.insert(0, "") + # Add default label for empty value if not available + if "" not in custom_labels: + custom_labels[""] = "< without host >" + # These are hardcoded there is not list of available host in OpenPype + enum_items = [] valid_keys = set() - for item in self.enum_items or []: - valid_keys.add(tuple(item.keys())[0]) + for key in host_names: + label = custom_labels.get(key, key) + valid_keys.add(key) + enum_items.append({key, label}) + self.enum_items = enum_items self.valid_keys = valid_keys if self.multiselection: diff --git a/openpype/settings/entities/schemas/README.md b/openpype/settings/entities/schemas/README.md index 0ad13bfe1a7..bbd53fa46b9 100644 --- a/openpype/settings/entities/schemas/README.md +++ b/openpype/settings/entities/schemas/README.md @@ -276,7 +276,7 @@ - enumeration of available hosts - multiselection can be allowed with setting key `"multiselection"` to `True` (Default: `False`) - it is possible to add empty value (represented with empty string) with setting `"use_empty_value"` to `True` (Default: `False`) -- to modify label of empty value set `"empty_label"` key with your label (Default: `< without host >`) +- it is possible to set `"custom_labels"` for host names where key `""` is empty value (Default: `{}`) ``` { "key": "host", @@ -284,7 +284,10 @@ "type": "hosts-enum", "multiselection": false, "use_empty_value": true, - "empty_label": "N/A" + "custom_labels": { + "": "N/A", + "nuke": "Nuke" + } } ``` From 9cbb10251947577e3e7b2c9b542b088c7bf2bc3c Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Jun 2021 14:11:57 +0200 Subject: [PATCH 7/7] fix dict/set type --- openpype/settings/entities/enum_entity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/settings/entities/enum_entity.py b/openpype/settings/entities/enum_entity.py index d197683afe3..63e0afeb475 100644 --- a/openpype/settings/entities/enum_entity.py +++ b/openpype/settings/entities/enum_entity.py @@ -153,7 +153,7 @@ def _item_initalization(self): for key in host_names: label = custom_labels.get(key, key) valid_keys.add(key) - enum_items.append({key, label}) + enum_items.append({key: label}) self.enum_items = enum_items self.valid_keys = valid_keys