Addon: store current job type on the Scene, not the WindowManager
The job type (+ its configuration) is something scene/file dependent, and should thus be stored there.
This commit is contained in:
parent
7181c2c4cf
commit
d18f5d25c5
@ -21,7 +21,7 @@ class FLAMENCO_PT_job_submission(bpy.types.Panel):
|
|||||||
return
|
return
|
||||||
|
|
||||||
row = col.row(align=True)
|
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")
|
row.operator("flamenco.fetch_job_types", text="", icon="FILE_REFRESH")
|
||||||
self.draw_job_settings(context, layout)
|
self.draw_job_settings(context, layout)
|
||||||
|
|
||||||
@ -30,11 +30,11 @@ class FLAMENCO_PT_job_submission(bpy.types.Panel):
|
|||||||
) -> None:
|
) -> None:
|
||||||
from . import job_types
|
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:
|
if job_type is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
propgroup = getattr(context.window_manager, "flamenco_job_settings", None)
|
propgroup = getattr(context.scene, "flamenco_job_settings", None)
|
||||||
if propgroup is None:
|
if propgroup is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -84,15 +84,19 @@ def are_job_types_available() -> bool:
|
|||||||
return bool(_job_type_enum_items)
|
return bool(_job_type_enum_items)
|
||||||
|
|
||||||
|
|
||||||
def _update_job_type(
|
def _update_job_type(scene: bpy.types.Scene, context: bpy.types.Context) -> None:
|
||||||
window_manager: bpy.types.WindowManager, context: bpy.types.Context
|
|
||||||
) -> None:
|
|
||||||
"""Called whenever the selected job type changes."""
|
"""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
|
global _selected_job_type_propgroup
|
||||||
|
|
||||||
from flamenco.manager.model.available_job_type import AvailableJobType
|
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(
|
assert isinstance(job_type, AvailableJobType), "did not expect type %r" % type(
|
||||||
job_type
|
job_type
|
||||||
)
|
)
|
||||||
@ -103,7 +107,7 @@ def _update_job_type(
|
|||||||
pg.register_property_group()
|
pg.register_property_group()
|
||||||
_selected_job_type_propgroup = pg
|
_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,
|
type=pg,
|
||||||
name="Job Settings",
|
name="Job Settings",
|
||||||
description="Parameters for the Flamenco job",
|
description="Parameters for the Flamenco job",
|
||||||
@ -142,9 +146,7 @@ else:
|
|||||||
_AvailableJobType = object
|
_AvailableJobType = object
|
||||||
|
|
||||||
|
|
||||||
def active_job_type(
|
def active_job_type(scene: bpy.types.Scene) -> Optional[_AvailableJobType]:
|
||||||
window_manager: bpy.types.WindowManager,
|
|
||||||
) -> Optional[_AvailableJobType]:
|
|
||||||
"""Return the active job type.
|
"""Return the active job type.
|
||||||
|
|
||||||
Returns a flamenco.manager.model.available_job_type.AvailableJobType,
|
Returns a flamenco.manager.model.available_job_type.AvailableJobType,
|
||||||
@ -153,7 +155,7 @@ def active_job_type(
|
|||||||
if _available_job_types is None:
|
if _available_job_types is None:
|
||||||
return 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:
|
for job_type in _available_job_types:
|
||||||
if job_type.name == job_type_name:
|
if job_type.name == job_type_name:
|
||||||
return job_type
|
return job_type
|
||||||
@ -317,7 +319,7 @@ def discard_flamenco_data():
|
|||||||
|
|
||||||
|
|
||||||
def register() -> None:
|
def register() -> None:
|
||||||
bpy.types.WindowManager.flamenco_job_type = bpy.props.EnumProperty(
|
bpy.types.Scene.flamenco_job_type = bpy.props.EnumProperty(
|
||||||
name="Job Type",
|
name="Job Type",
|
||||||
items=_get_job_types_enum_items,
|
items=_get_job_types_enum_items,
|
||||||
update=_update_job_type,
|
update=_update_job_type,
|
||||||
@ -325,11 +327,11 @@ def register() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def unregister() -> None:
|
def unregister() -> None:
|
||||||
del bpy.types.WindowManager.flamenco_job_type
|
del bpy.types.Scene.flamenco_job_type
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# This property doesn't always exist.
|
# This property doesn't always exist.
|
||||||
del bpy.types.WindowManager.flamenco_job_settings
|
del bpy.types.Scene.flamenco_job_settings
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ class FLAMENCO_OT_fetch_job_types(FlamencoOpMixin, bpy.types.Operator):
|
|||||||
from flamenco.manager import ApiException
|
from flamenco.manager import ApiException
|
||||||
from . import job_types
|
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:
|
try:
|
||||||
job_types.fetch_available_job_types(api_client)
|
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:
|
if old_job_type_name:
|
||||||
# TODO: handle cases where the old job type no longer exists.
|
# 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"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user