From 12e6211fc9b118c748620611c9f75a1afa121ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 1 Apr 2022 14:28:43 +0200 Subject: [PATCH] Addon: get storage directory from Manager Get the job storage location from the Manager, don't allow editing it, and don't allow per-scene overrides. --- addon/flamenco/gui.py | 11 ------- addon/flamenco/operators.py | 4 ++- addon/flamenco/preferences.py | 60 +++++++++++++++++------------------ 3 files changed, 33 insertions(+), 42 deletions(-) diff --git a/addon/flamenco/gui.py b/addon/flamenco/gui.py index 5e86822e..e506ac79 100644 --- a/addon/flamenco/gui.py +++ b/addon/flamenco/gui.py @@ -42,17 +42,6 @@ class FLAMENCO_PT_job_submission(bpy.types.Panel): col = layout.column(align=True) col.prop(context.scene, "flamenco_job_name", text="Job Name") - job_storage_col = col.column(align=True) - job_storage_col.enabled = not prefs.is_shaman_enabled - if prefs.is_shaman_enabled: - job_storage_col.label( - text="Shaman API will be used for job submission, so job storage location is ignored:" - ) - row = job_storage_col.row(align=True) - row.prop(context.scene, "flamenco_job_storage", text="Job Storage") - prop = row.operator("flamenco3.explore_file_path", text="", icon="WINDOW") - prop.path = context.scene.flamenco_job_storage - layout.separator() col = layout.column() diff --git a/addon/flamenco/operators.py b/addon/flamenco/operators.py index 7a979230..7a36f2db 100644 --- a/addon/flamenco/operators.py +++ b/addon/flamenco/operators.py @@ -111,6 +111,7 @@ class FLAMENCO_OT_ping_manager(FlamencoOpMixin, bpy.types.Operator): # Store whether this Manager supports the Shaman API. prefs = preferences.get(context) prefs.is_shaman_enabled = config.shaman_enabled + prefs.job_storage = config.storage_location self.report({level}, report) context.window_manager.flamenco_status_ping = report @@ -260,7 +261,8 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator): datetime.datetime.now().isoformat("-").replace(":", ""), self.job_name, ) - pack_target_dir = Path(context.scene.flamenco_job_storage) / unique_dir + prefs = preferences.get(context) + pack_target_dir = Path(prefs.job_storage) / unique_dir # TODO: this should take the blendfile location relative to the project path into account. pack_target_file = pack_target_dir / blendfile.name diff --git a/addon/flamenco/preferences.py b/addon/flamenco/preferences.py index f016eacd..47f6159e 100644 --- a/addon/flamenco/preferences.py +++ b/addon/flamenco/preferences.py @@ -12,11 +12,14 @@ def discard_flamenco_client(prefs, context): context.window_manager.flamenco_status_ping = "" -def _update_default_job_storage( +def _refresh_the_planet( prefs: "FlamencoPreferences", context: bpy.types.Context ) -> None: - _unregister_rna_props() - _register_rna_props(prefs) + """Refresh all GUI areas.""" + for win in context.window_manager.windows: + for area in win.screen.areas: + for region in area.regions: + region.tag_redraw() class FlamencoPreferences(bpy.types.AddonPreferences): @@ -33,35 +36,49 @@ class FlamencoPreferences(bpy.types.AddonPreferences): name="Shaman Enabled", description="Whether this Manager has the Shaman protocol enabled", default=False, + update=_refresh_the_planet, ) + # Property that should be editable from Python. It's not exposed to the GUI. job_storage: bpy.props.StringProperty( # type: ignore name="Job Storage Directory", subtype="DIR_PATH", default="", - description="Directory where blend files are stored, when submitting them to Flamenco", - update=_update_default_job_storage, + options={"HIDDEN"}, + description="Directory where blend files are stored when submitting them to Flamenco. This value is determined by Flamenco Manager", + ) + + # Property that gets its value from the above _job_storage, and cannot be + # set. This makes it read-only in the GUI. + job_storage_for_gui: bpy.props.StringProperty( # type: ignore + name="Job Storage Directory", + subtype="DIR_PATH", + default="", + options={"SKIP_SAVE"}, + description="Directory where blend files are stored when submitting them to Flamenco. This value is determined by Flamenco Manager", + get=lambda prefs: prefs.job_storage, ) def draw(self, context: bpy.types.Context) -> None: layout = self.layout + layout.use_property_decorate = False + layout.use_property_split = True col = layout.column() - col.use_property_split = True row = col.row(align=True) row.prop(self, "manager_url") row.operator("flamenco.ping_manager", text="", icon="CHECKMARK") if context.window_manager.flamenco_status_ping: - col.label(text=context.window_manager.flamenco_status_ping) + split = col.split(factor=0.4) + split.label(text="") + split.label(text=context.window_manager.flamenco_status_ping) - col = layout.column(align=True) - col.enabled = not self.is_shaman_enabled if self.is_shaman_enabled: - col.label( - text="This Manager supports the Shaman API, so this setting will be ignored:" - ) - col.prop(self, "job_storage") + split = col.split(factor=0.4) + split.label(text="") + split.label(text="Shaman enabled") + col.prop(self, "job_storage_for_gui", text="Job Storage") def get(context: bpy.types.Context) -> FlamencoPreferences: @@ -79,31 +96,14 @@ def manager_url(context: bpy.types.Context) -> str: return str(prefs.manager_url) -def _register_rna_props(prefs: FlamencoPreferences) -> None: - """RNA properties that have their defaults set in the preferences get registered here.""" - - bpy.types.Scene.flamenco_job_storage = bpy.props.StringProperty( - name="Flamenco Job Storage", - subtype="DIR_PATH", - default=prefs.job_storage, - description="Directory where blend files are stored, when submitting them to Flamenco", - ) - - -def _unregister_rna_props() -> None: - del bpy.types.Scene.flamenco_job_storage - - classes = (FlamencoPreferences,) _register, _unregister = bpy.utils.register_classes_factory(classes) def register(): _register() - _register_rna_props(get(bpy.context)) bpy.context.window_manager.flamenco_status_ping = "" def unregister(): - _unregister_rna_props() _unregister()