From 8ddc03d6ef5f6b781fe0b23ec6ae61d0034bca33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 29 Jul 2022 10:25:02 +0200 Subject: [PATCH] Add-on: evaluate visible job settings immediately For each job setting, if it's visible and has an `eval` property, it is now evaluated immediately when switching job types. This means that properties like the frame range get filled in automatically. If there is already a value, this process is skipped, in order to not overwrite the user's choice. This resolves a common issue where the render job was rejected because the frame range was kept empty. --- addon/flamenco/job_types.py | 2 ++ addon/flamenco/job_types_propgroup.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/addon/flamenco/job_types.py b/addon/flamenco/job_types.py index 26210772..4822ed34 100644 --- a/addon/flamenco/job_types.py +++ b/addon/flamenco/job_types.py @@ -142,6 +142,8 @@ def update_job_type_properties(scene: bpy.types.Scene) -> None: description="Parameters for the Flamenco job", ) + scene.flamenco_job_settings.eval_visible_settings_if_no_value(bpy.context) + def _clear_available_job_types(scene: bpy.types.Scene) -> None: global _available_job_types diff --git a/addon/flamenco/job_types_propgroup.py b/addon/flamenco/job_types_propgroup.py index 97ae9eb9..df7809b2 100644 --- a/addon/flamenco/job_types_propgroup.py +++ b/addon/flamenco/job_types_propgroup.py @@ -142,6 +142,33 @@ class JobTypePropertyGroup: job.settings[setting.key] = value + def eval_visible_settings_if_no_value(self, context: bpy.types.Context) -> None: + """Assign default values to all visible, evaluatable settings. + + If the setting already has a value, that value will not be overwritten + in order to retain the user's input. + + If the setting has an `eval` property, it'll be evaluated and used as + the setting value. Otherwise it will be skipped. + """ + print(f"eval_visible_settings_if_no_value") + for setting in self.job_type.settings: + if not job_types.setting_is_visible(setting): + # Skip those settings that will be hidden from the GUI. + # These are evaluated at submission time anyway. + continue + + setting_eval = setting.get("eval", "") + if not setting_eval: + continue + + if getattr(self, setting.key): + # Non-falsey setting, so don't overwrite. + continue + + value = self.eval_setting(context, setting.key, setting_eval) + setattr(self, setting.key, value) + @staticmethod def last_n_dir_parts(n: int, filepath: Union[str, Path, None] = None) -> Path: """Return the last `n` parts of the directory of `filepath`.