From bf242aca7e3a65ae078509cc4474a158f0ade8ee Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Fri, 14 Jul 2023 16:58:12 -0400 Subject: [PATCH 1/6] Blender Kitsu: Add Property if Context is Valid --- scripts-blender/addons/blender_kitsu/props.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts-blender/addons/blender_kitsu/props.py b/scripts-blender/addons/blender_kitsu/props.py index 7e9b1c3b..745657f9 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,11 +232,23 @@ class KITSU_property_group_scene(bpy.types.PropertyGroup): class KITSU_property_group_error(bpy.types.PropertyGroup): """""" + + 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, ) + 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(), + ) class KITSU_property_group_window_manager(bpy.types.PropertyGroup): -- 2.30.2 From 74bb94ed8f828fbee4f53bc8e6e102c6e18919a9 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Fri, 14 Jul 2023 16:59:02 -0400 Subject: [PATCH 2/6] BLender Kitsu: Add Warning if Context is not Detected --- .../addons/blender_kitsu/context/ui.py | 17 ++++++++++------- scripts-blender/addons/blender_kitsu/ui.py | 9 +++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) 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/ui.py b/scripts-blender/addons/blender_kitsu/ui.py index f01146f5..1e24aab9 100644 --- a/scripts-blender/addons/blender_kitsu/ui.py +++ b/scripts-blender/addons/blender_kitsu/ui.py @@ -51,9 +51,14 @@ def draw_error_frame_range_outdated( box: bpy.types.UILayout, ) -> bpy.types.UILayout: + +def draw_error_no_kitsu_context( + box: bpy.types.UILayout, +) -> bpy.types.UILayout: row = box.row(align=True) - row.label(text="Frame Range Outdated") - row.operator("kitsu.pull_frame_range", icon="FILE_REFRESH") + 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( -- 2.30.2 From 0b000bba2bada50b5b4ba09df5b64cfdc3b08c4f Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Fri, 14 Jul 2023 17:03:31 -0400 Subject: [PATCH 3/6] Blender Kitsu: Remove check frame range on load --- .../addons/blender_kitsu/playblast/ops.py | 40 ------------------- 1 file changed, 40 deletions(-) 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): -- 2.30.2 From 4fc69271b66183e46e7044321ef850751f34f235 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Fri, 14 Jul 2023 17:04:04 -0400 Subject: [PATCH 4/6] Blender Kitsu: Check Frame Range via Property --- scripts-blender/addons/blender_kitsu/props.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/scripts-blender/addons/blender_kitsu/props.py b/scripts-blender/addons/blender_kitsu/props.py index 745657f9..b82199f0 100644 --- a/scripts-blender/addons/blender_kitsu/props.py +++ b/scripts-blender/addons/blender_kitsu/props.py @@ -232,6 +232,31 @@ 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() @@ -241,6 +266,8 @@ class KITSU_property_group_error(bpy.types.PropertyGroup): 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", -- 2.30.2 From 3befd9043351edc08dd1a1e2d1786be2f37ae827 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Fri, 14 Jul 2023 17:05:31 -0400 Subject: [PATCH 5/6] Blender Kitsu: Fix Frame Range Warning - Make warning more aggressive (red) - Warning is based on property instead of post load so it always checks file state --- scripts-blender/addons/blender_kitsu/ui.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts-blender/addons/blender_kitsu/ui.py b/scripts-blender/addons/blender_kitsu/ui.py index 1e24aab9..6005d510 100644 --- a/scripts-blender/addons/blender_kitsu/ui.py +++ b/scripts-blender/addons/blender_kitsu/ui.py @@ -50,6 +50,10 @@ 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="TRIA_DOWN") def draw_error_no_kitsu_context( -- 2.30.2 From cd855672b88a4dfda8c99410ad0ba27b43695d06 Mon Sep 17 00:00:00 2001 From: Nick Alberelli Date: Fri, 14 Jul 2023 17:05:49 -0400 Subject: [PATCH 6/6] Blender Kitsu: Enforce Black Formatting --- scripts-blender/addons/blender_kitsu/props.py | 9 ++------- scripts-blender/addons/blender_kitsu/ui.py | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts-blender/addons/blender_kitsu/props.py b/scripts-blender/addons/blender_kitsu/props.py index b82199f0..24eda7c4 100644 --- a/scripts-blender/addons/blender_kitsu/props.py +++ b/scripts-blender/addons/blender_kitsu/props.py @@ -295,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", @@ -376,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) @@ -389,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) @@ -412,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 @@ -456,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 6005d510..0e91ad0f 100644 --- a/scripts-blender/addons/blender_kitsu/ui.py +++ b/scripts-blender/addons/blender_kitsu/ui.py @@ -96,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="") -- 2.30.2