From a4a4b5244f07b08099748217c86a4e15057d85e1 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Fri, 11 Sep 2020 14:34:26 +0200 Subject: [PATCH] added ability to save as defaults --- .../global/applications.json | 31 +++--- .../projects_schema/1_plugins_gui_schema.json | 4 + .../config_setting/widgets/base.py | 94 ++++++++++++++++++- 3 files changed, 109 insertions(+), 20 deletions(-) diff --git a/pype/configurations/defaults/system_configurations/global/applications.json b/pype/configurations/defaults/system_configurations/global/applications.json index 8e27f11002..3a74a85468 100644 --- a/pype/configurations/defaults/system_configurations/global/applications.json +++ b/pype/configurations/defaults/system_configurations/global/applications.json @@ -6,34 +6,29 @@ "celaction_local": true, "celaction_remote": true, "harmony_17": true, - "houdini_16": true, - "houdini_17": true, - "houdini_18": true, - "maya_2016": true, "maya_2017": true, "maya_2018": true, "maya_2019": true, "maya_2020": true, - "nukestudio_10.0": true, - "nukestudio_11.0": true, - "nukestudio_11.2": true, - "nukestudio_11.3": true, - "nukestudio_12.0": true, - "nukex_10.0": true, - "nukex_11.0": true, - "nukex_11.2": true, - "nukex_11.3": true, - "nukex_12.0": true, "nuke_10.0": true, - "nuke_11.0": true, "nuke_11.2": true, "nuke_11.3": true, "nuke_12.0": true, - "photoshop_2020": true, + "nukex_10.0": true, + "nukex_11.2": true, + "nukex_11.3": true, + "nukex_12.0": true, + "nukestudio_10.0": true, + "nukestudio_11.2": true, + "nukestudio_11.3": true, + "nukestudio_12.0": true, + "houdini_16": true, + "houdini_16.5": false, + "houdini_17": true, + "houdini_18": true, "premiere_2019": true, "premiere_2020": true, "resolve_16": true, "storyboardpro_7": true, - "unreal_4.24": true, - "houdini_16.5": false + "unreal_4.24": true } \ No newline at end of file diff --git a/pype/tools/config_setting/config_setting/config_gui_schema/projects_schema/1_plugins_gui_schema.json b/pype/tools/config_setting/config_setting/config_gui_schema/projects_schema/1_plugins_gui_schema.json index df0de07a4d..c279a6b04a 100644 --- a/pype/tools/config_setting/config_setting/config_gui_schema/projects_schema/1_plugins_gui_schema.json +++ b/pype/tools/config_setting/config_setting/config_gui_schema/projects_schema/1_plugins_gui_schema.json @@ -140,6 +140,10 @@ "is_group": true, "children": [ { + "type": "boolean", + "key": "enabled", + "label": "Enabled" + }, { "type": "dict-invisible", "key": "ffmpeg_args", "children": [ diff --git a/pype/tools/config_setting/config_setting/widgets/base.py b/pype/tools/config_setting/config_setting/widgets/base.py index 58e53b8c58..d7078e4ab6 100644 --- a/pype/tools/config_setting/config_setting/widgets/base.py +++ b/pype/tools/config_setting/config_setting/widgets/base.py @@ -2,8 +2,12 @@ import os import json from Qt import QtWidgets, QtCore, QtGui from pype.configurations.lib import ( + SYSTEM_CONFIGURATIONS_KEY, SYSTEM_CONFIGURATIONS_PATH, + PROJECT_CONFIGURATIONS_KEY, PROJECT_CONFIGURATIONS_PATH, + DEFAULTS_DIR, + reset_default_configurations, default_configuration, studio_system_configurations, project_configurations_overrides, @@ -145,7 +149,50 @@ class SystemWidget(QtWidgets.QWidget): self._update_values() def _save_as_defaults(self): - print("_save_as_defaults") + output = {} + for item in self.input_fields: + output.update(item.config_value()) + + for key in reversed(self.keys): + _output = {key: output} + output = _output + + all_values = {} + for item in self.input_fields: + all_values.update(item.config_value()) + + for key in reversed(self.keys): + _all_values = {key: all_values} + all_values = _all_values + + # Skip first key + all_values = all_values["system"] + + prject_defaults_dir = os.path.join( + DEFAULTS_DIR, SYSTEM_CONFIGURATIONS_KEY + ) + keys_to_file = lib.file_keys_from_schema(self.schema) + for key_sequence in keys_to_file: + # Skip first key + key_sequence = key_sequence[1:] + subpath = "/".join(key_sequence) + ".json" + + new_values = all_values + for key in key_sequence: + new_values = new_values[key] + + output_path = os.path.join(prject_defaults_dir, subpath) + dirpath = os.path.dirname(output_path) + if not os.path.exists(dirpath): + os.makedirs(dirpath) + + print("Saving data to: ", subpath) + with open(output_path, "w") as file_stream: + json.dump(new_values, file_stream, indent=4) + + reset_default_configurations() + + self._update_values() def _update_values(self): self.ignore_value_changes = True @@ -415,7 +462,50 @@ class ProjectWidget(QtWidgets.QWidget): self.ignore_value_changes = False def _save_as_defaults(self): - print("_save_as_defaults") + output = {} + for item in self.input_fields: + output.update(item.config_value()) + + for key in reversed(self.keys): + _output = {key: output} + output = _output + + all_values = {} + for item in self.input_fields: + all_values.update(item.config_value()) + + for key in reversed(self.keys): + _all_values = {key: all_values} + all_values = _all_values + + # Skip first key + all_values = all_values["project"] + + prject_defaults_dir = os.path.join( + DEFAULTS_DIR, PROJECT_CONFIGURATIONS_KEY + ) + keys_to_file = lib.file_keys_from_schema(self.schema) + for key_sequence in keys_to_file: + # Skip first key + key_sequence = key_sequence[1:] + subpath = "/".join(key_sequence) + ".json" + + new_values = all_values + for key in key_sequence: + new_values = new_values[key] + + output_path = os.path.join(prject_defaults_dir, subpath) + dirpath = os.path.dirname(output_path) + if not os.path.exists(dirpath): + os.makedirs(dirpath) + + print("Saving data to: ", subpath) + with open(output_path, "w") as file_stream: + json.dump(new_values, file_stream, indent=4) + + reset_default_configurations() + + self._update_values() def _save(self): has_invalid = False