diff --git a/addon/flamenco/gui.py b/addon/flamenco/gui.py index 6912b60f..1c40aa82 100644 --- a/addon/flamenco/gui.py +++ b/addon/flamenco/gui.py @@ -21,7 +21,7 @@ class FLAMENCO_PT_job_submission(bpy.types.Panel): return row = col.row(align=True) - row.prop(context.window_manager, "flamenco_job_type", text="") + row.prop(context.scene, "flamenco_job_type", text="") row.operator("flamenco.fetch_job_types", text="", icon="FILE_REFRESH") self.draw_job_settings(context, layout) @@ -30,11 +30,11 @@ class FLAMENCO_PT_job_submission(bpy.types.Panel): ) -> None: from . import job_types - job_type = job_types.active_job_type(context.window_manager) + job_type = job_types.active_job_type(context.scene) if job_type is None: return - propgroup = getattr(context.window_manager, "flamenco_job_settings", None) + propgroup = getattr(context.scene, "flamenco_job_settings", None) if propgroup is None: return diff --git a/addon/flamenco/job_types.py b/addon/flamenco/job_types.py index d93f1d14..79a9f5bf 100644 --- a/addon/flamenco/job_types.py +++ b/addon/flamenco/job_types.py @@ -84,15 +84,19 @@ def are_job_types_available() -> bool: return bool(_job_type_enum_items) -def _update_job_type( - window_manager: bpy.types.WindowManager, context: bpy.types.Context -) -> None: +def _update_job_type(scene: bpy.types.Scene, context: bpy.types.Context) -> None: """Called whenever the selected job type changes.""" + update_job_type_properties(scene) + + +def update_job_type_properties(scene: bpy.types.Scene) -> None: + """(Re)construct the PropertyGroup for the currently selected job type.""" + global _selected_job_type_propgroup from flamenco.manager.model.available_job_type import AvailableJobType - job_type = active_job_type(window_manager) + job_type = active_job_type(scene) assert isinstance(job_type, AvailableJobType), "did not expect type %r" % type( job_type ) @@ -103,7 +107,7 @@ def _update_job_type( pg.register_property_group() _selected_job_type_propgroup = pg - bpy.types.WindowManager.flamenco_job_settings = bpy.props.PointerProperty( + bpy.types.Scene.flamenco_job_settings = bpy.props.PointerProperty( type=pg, name="Job Settings", description="Parameters for the Flamenco job", @@ -142,9 +146,7 @@ else: _AvailableJobType = object -def active_job_type( - window_manager: bpy.types.WindowManager, -) -> Optional[_AvailableJobType]: +def active_job_type(scene: bpy.types.Scene) -> Optional[_AvailableJobType]: """Return the active job type. Returns a flamenco.manager.model.available_job_type.AvailableJobType, @@ -153,7 +155,7 @@ def active_job_type( if _available_job_types is None: return None - job_type_name = window_manager.flamenco_job_type + job_type_name = scene.flamenco_job_type for job_type in _available_job_types: if job_type.name == job_type_name: return job_type @@ -317,7 +319,7 @@ def discard_flamenco_data(): def register() -> None: - bpy.types.WindowManager.flamenco_job_type = bpy.props.EnumProperty( + bpy.types.Scene.flamenco_job_type = bpy.props.EnumProperty( name="Job Type", items=_get_job_types_enum_items, update=_update_job_type, @@ -325,11 +327,11 @@ def register() -> None: def unregister() -> None: - del bpy.types.WindowManager.flamenco_job_type + del bpy.types.Scene.flamenco_job_type try: # This property doesn't always exist. - del bpy.types.WindowManager.flamenco_job_settings + del bpy.types.Scene.flamenco_job_settings except AttributeError: pass diff --git a/addon/flamenco/operators.py b/addon/flamenco/operators.py index a8df5608..f40f41e9 100644 --- a/addon/flamenco/operators.py +++ b/addon/flamenco/operators.py @@ -30,7 +30,8 @@ class FLAMENCO_OT_fetch_job_types(FlamencoOpMixin, bpy.types.Operator): from flamenco.manager import ApiException from . import job_types - old_job_type_name = getattr(context.window_manager, "flamenco_job_type", "") + scene = context.scene + old_job_type_name = getattr(scene, "flamenco_job_type", "") try: job_types.fetch_available_job_types(api_client) @@ -40,8 +41,9 @@ class FLAMENCO_OT_fetch_job_types(FlamencoOpMixin, bpy.types.Operator): if old_job_type_name: # TODO: handle cases where the old job type no longer exists. - context.window_manager.flamenco_job_type = old_job_type_name + scene.flamenco_job_type = old_job_type_name + job_types.update_job_type_properties(scene) return {"FINISHED"}