diff --git a/scripts-blender/addons/blender_kitsu/context/ui.py b/scripts-blender/addons/blender_kitsu/context/ui.py index 928a9e53..d39409b1 100644 --- a/scripts-blender/addons/blender_kitsu/context/ui.py +++ b/scripts-blender/addons/blender_kitsu/context/ui.py @@ -84,13 +84,16 @@ class KITSU_PT_vi3d_context(bpy.types.Panel): row = box.row(align=True) row.label(text="Browser", icon="FILEBROWSER") - # Detect Context. - row.operator( - KITSU_OT_con_detect_context.bl_idname, - icon="FILE_REFRESH", - text="", - emboss=False, - ) + if not context.scene.kitsu_error.kitsu_context: + ui.draw_error_no_kitsu_context(box) + else: + # Detect Context. + row.operator( + KITSU_OT_con_detect_context.bl_idname, + icon="FILE_REFRESH", + text="", + emboss=False, + ) # Category. row = box.row(align=True) diff --git a/scripts-blender/addons/blender_kitsu/playblast/ops.py b/scripts-blender/addons/blender_kitsu/playblast/ops.py index a9ab3273..6cdaf993 100644 --- a/scripts-blender/addons/blender_kitsu/playblast/ops.py +++ b/scripts-blender/addons/blender_kitsu/playblast/ops.py @@ -407,9 +407,6 @@ class KITSU_OT_pull_frame_range(bpy.types.Operator): context.scene.frame_start = frame_in context.scene.frame_end = frame_out - # Update error prop. - context.scene.kitsu_error.frame_range = False - # Log. self.report({"INFO"}, f"Updated frame range {frame_in} - {frame_out}") return {"FINISHED"} @@ -443,39 +440,6 @@ def load_post_handler_init_version_model(dummy: Any) -> None: opsdata.init_playblast_file_model(bpy.context) -@persistent -def load_post_handler_check_frame_range(dummy: Any) -> None: - """ - Compare the current scene's frame range with that of the active shot on kitsu. - If there's a mismatch, set kitsu_error.frame_range -> True. This will enable - a warning in the Animation Tools Tab UI. - """ - active_shot = cache.shot_active_get() - if not active_shot: - return - - # Pull update for shot. - cache.shot_active_pull_update() - - if "3d_start" not in active_shot.data: - logger.warning( - "Failed to check frame range. Shot %s missing '3d_start' attribute on server", - active_shot.name, - ) - return - frame_in = int(active_shot.data["3d_start"]) - frame_out = int(active_shot.data["3d_start"]) + int(active_shot.nb_frames) - 1 - if ( - frame_in == bpy.context.scene.frame_start - and frame_out == bpy.context.scene.frame_end - ): - bpy.context.scene.kitsu_error.frame_range = False - return - - bpy.context.scene.kitsu_error.frame_range = True - logger.warning("Current frame range is outdated!") - - @persistent def save_pre_handler_clean_overrides(dummy: Any) -> None: """ @@ -517,16 +481,12 @@ def register(): # Handlers. bpy.app.handlers.load_post.append(load_post_handler_init_version_model) - bpy.app.handlers.load_post.append(load_post_handler_check_frame_range) - bpy.app.handlers.save_pre.append(save_pre_handler_clean_overrides) def unregister(): # Clear handlers. - bpy.app.handlers.load_post.remove(load_post_handler_check_frame_range) bpy.app.handlers.load_post.remove(load_post_handler_init_version_model) - bpy.app.handlers.save_pre.remove(save_pre_handler_clean_overrides) for cls in reversed(classes): diff --git a/scripts-blender/addons/blender_kitsu/props.py b/scripts-blender/addons/blender_kitsu/props.py index 7e9b1c3b..24eda7c4 100644 --- a/scripts-blender/addons/blender_kitsu/props.py +++ b/scripts-blender/addons/blender_kitsu/props.py @@ -24,7 +24,7 @@ from typing import Any, Union, List, Dict, Optional import bpy from bpy.app.handlers import persistent -from blender_kitsu import propsdata, bkglobals +from blender_kitsu import propsdata, bkglobals, cache from blender_kitsu.logger import LoggerFactory logger = LoggerFactory.getLogger() @@ -232,10 +232,49 @@ class KITSU_property_group_scene(bpy.types.PropertyGroup): class KITSU_property_group_error(bpy.types.PropertyGroup): """""" + def check_frame_range(self): + """ + Compare the current scene's frame range with that of the active shot on kitsu. + If there's a mismatch, set kitsu_error.frame_range -> True. This will enable + a warning in the Animation Tools Tab UI. + """ + active_shot = cache.shot_active_get() + if not active_shot: + return True + + if "3d_start" not in active_shot.data: + logger.warning( + "Failed to check frame range. Shot %s missing '3d_start' attribute on server", + active_shot.name, + ) + return True + frame_in = int(active_shot.data["3d_start"]) + frame_out = int(active_shot.data["3d_start"]) + int(active_shot.nb_frames) - 1 + if ( + frame_in == bpy.context.scene.frame_start + and frame_out == bpy.context.scene.frame_end + ): + return False + logger.warning("Current frame range is outdated!") + return True + + def check_kitsu_context(self): + active_shot = cache.shot_active_get() + return bool(active_shot) + frame_range: bpy.props.BoolProperty( # type: ignore name="Frame Range Error", description="Indicates if the scene frame range does not match the one in Kitsu", default=False, + get=check_frame_range, + options=set(), + ) + kitsu_context: bpy.props.BoolProperty( # type: ignore + name="Kitsu Context not Found", + description="Indicates if the file's context has not been loaded by Kitsu Server", + default=False, + get=check_kitsu_context, + options=set(), ) @@ -256,7 +295,6 @@ class KITSU_property_group_window_manager(bpy.types.PropertyGroup): def _add_window_manager_props(): - # Multi Edit Properties. bpy.types.WindowManager.show_advanced = bpy.props.BoolProperty( name="Show Advanced", @@ -337,9 +375,7 @@ def _calc_kitsu_frame_start(self): Calculates strip.kitsu_frame_start, little hack because it seems like we cant access the strip from a property group But we need acess to seqeuence properties. """ - kitsu_frame_start = ( - bkglobals.FRAME_START - self.kitsu.frame_start_offset - ) + kitsu_frame_start = bkglobals.FRAME_START - self.kitsu.frame_start_offset return int(kitsu_frame_start) @@ -350,7 +386,7 @@ def _calc_kitsu_frame_end(self): But we need acess to seqeuence properties. """ frame_start = _calc_kitsu_frame_start(self) - frame_end_final = (frame_start + (self.frame_final_duration - 1)) + frame_end_final = frame_start + (self.frame_final_duration - 1) return int(frame_end_final) @@ -373,7 +409,6 @@ def update_sequence_colors_coll_prop(dummy: Any) -> None: # Append missing sequences to scene.kitsu.seqeuence_colors. for seq in sequences: - if not seq.kitsu.sequence_id: continue @@ -417,7 +452,6 @@ classes = [ def register(): - for cls in classes: bpy.utils.register_class(cls) diff --git a/scripts-blender/addons/blender_kitsu/ui.py b/scripts-blender/addons/blender_kitsu/ui.py index f01146f5..0e91ad0f 100644 --- a/scripts-blender/addons/blender_kitsu/ui.py +++ b/scripts-blender/addons/blender_kitsu/ui.py @@ -50,10 +50,19 @@ def draw_error_invalid_playblast_root_dir( def draw_error_frame_range_outdated( box: bpy.types.UILayout, ) -> bpy.types.UILayout: - row = box.row(align=True) + row.alert = True row.label(text="Frame Range Outdated") - row.operator("kitsu.pull_frame_range", icon="FILE_REFRESH") + row.operator("kitsu.pull_frame_range", icon="TRIA_DOWN") + + +def draw_error_no_kitsu_context( + box: bpy.types.UILayout, +) -> bpy.types.UILayout: + row = box.row(align=True) + row.alert = True + row.label(text="File's Kitsu Context not found", icon="ERROR") + row.operator("kitsu.con_detect_context", icon="FILE_REFRESH") def draw_error_invalid_render_preset_dir( @@ -87,7 +96,6 @@ def draw_error_config_dir_not_exists( def draw_error_no_active_camera( box: bpy.types.UILayout, ) -> bpy.types.UILayout: - row = box.row(align=True) row.label(text=f"No active camera") row.prop(bpy.context.scene, "camera", text="")