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.
This commit is contained in:
Sybren A. Stüvel 2022-04-01 14:28:43 +02:00
parent 5f16201832
commit 12e6211fc9
3 changed files with 33 additions and 42 deletions

View File

@ -42,17 +42,6 @@ class FLAMENCO_PT_job_submission(bpy.types.Panel):
col = layout.column(align=True) col = layout.column(align=True)
col.prop(context.scene, "flamenco_job_name", text="Job Name") 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() layout.separator()
col = layout.column() col = layout.column()

View File

@ -111,6 +111,7 @@ class FLAMENCO_OT_ping_manager(FlamencoOpMixin, bpy.types.Operator):
# Store whether this Manager supports the Shaman API. # Store whether this Manager supports the Shaman API.
prefs = preferences.get(context) prefs = preferences.get(context)
prefs.is_shaman_enabled = config.shaman_enabled prefs.is_shaman_enabled = config.shaman_enabled
prefs.job_storage = config.storage_location
self.report({level}, report) self.report({level}, report)
context.window_manager.flamenco_status_ping = 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(":", ""), datetime.datetime.now().isoformat("-").replace(":", ""),
self.job_name, 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. # TODO: this should take the blendfile location relative to the project path into account.
pack_target_file = pack_target_dir / blendfile.name pack_target_file = pack_target_dir / blendfile.name

View File

@ -12,11 +12,14 @@ def discard_flamenco_client(prefs, context):
context.window_manager.flamenco_status_ping = "" context.window_manager.flamenco_status_ping = ""
def _update_default_job_storage( def _refresh_the_planet(
prefs: "FlamencoPreferences", context: bpy.types.Context prefs: "FlamencoPreferences", context: bpy.types.Context
) -> None: ) -> None:
_unregister_rna_props() """Refresh all GUI areas."""
_register_rna_props(prefs) 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): class FlamencoPreferences(bpy.types.AddonPreferences):
@ -33,35 +36,49 @@ class FlamencoPreferences(bpy.types.AddonPreferences):
name="Shaman Enabled", name="Shaman Enabled",
description="Whether this Manager has the Shaman protocol enabled", description="Whether this Manager has the Shaman protocol enabled",
default=False, 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 job_storage: bpy.props.StringProperty( # type: ignore
name="Job Storage Directory", name="Job Storage Directory",
subtype="DIR_PATH", subtype="DIR_PATH",
default="", default="",
description="Directory where blend files are stored, when submitting them to Flamenco", options={"HIDDEN"},
update=_update_default_job_storage, 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: def draw(self, context: bpy.types.Context) -> None:
layout = self.layout layout = self.layout
layout.use_property_decorate = False
layout.use_property_split = True
col = layout.column() col = layout.column()
col.use_property_split = True
row = col.row(align=True) row = col.row(align=True)
row.prop(self, "manager_url") row.prop(self, "manager_url")
row.operator("flamenco.ping_manager", text="", icon="CHECKMARK") row.operator("flamenco.ping_manager", text="", icon="CHECKMARK")
if context.window_manager.flamenco_status_ping: 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: if self.is_shaman_enabled:
col.label( split = col.split(factor=0.4)
text="This Manager supports the Shaman API, so this setting will be ignored:" split.label(text="")
) split.label(text="Shaman enabled")
col.prop(self, "job_storage") col.prop(self, "job_storage_for_gui", text="Job Storage")
def get(context: bpy.types.Context) -> FlamencoPreferences: def get(context: bpy.types.Context) -> FlamencoPreferences:
@ -79,31 +96,14 @@ def manager_url(context: bpy.types.Context) -> str:
return str(prefs.manager_url) 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,) classes = (FlamencoPreferences,)
_register, _unregister = bpy.utils.register_classes_factory(classes) _register, _unregister = bpy.utils.register_classes_factory(classes)
def register(): def register():
_register() _register()
_register_rna_props(get(bpy.context))
bpy.context.window_manager.flamenco_status_ping = "" bpy.context.window_manager.flamenco_status_ping = ""
def unregister(): def unregister():
_unregister_rna_props()
_unregister() _unregister()