From 6d64d6df7f0e0e556d4eaccbcfdb264e8fd6230a Mon Sep 17 00:00:00 2001 From: pullusb Date: Mon, 27 Jan 2025 17:31:37 +0100 Subject: [PATCH] Fix tab name update call at register, now in load handler Fail in background mode with --addons flag to force enable addon. should not be in register since it should happen after a full register. --- __init__.py | 13 +++++++++++-- preferences.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index 18df43f..496528b 100644 --- a/__init__.py +++ b/__init__.py @@ -4,7 +4,7 @@ bl_info = { "name": "Background plane manager", "description": "Manage the background image planes and grease pencil object relative to a camera", "author": "Samuel Bernou", - "version": (0, 5, 2), + "version": (0, 5, 3), "blender": (3, 5, 0), "location": "View3D", "warning": "", @@ -14,6 +14,7 @@ bl_info = { import bpy from pathlib import Path +from bpy.app.handlers import persistent from . import operators from . import import_planes @@ -59,6 +60,11 @@ except Exception: # TODO: Add an enum in prefs to choose default type to use # Override this enum if there is an environement variable in project +@persistent +def subscribe_tab_update(dummy): + ## Update UI Tab name in sidebar + preferences.ui_in_sidebar_update(core.get_addon_prefs(), bpy.context) + modules = ( import_planes, operators, @@ -71,8 +77,11 @@ def register(): for m in modules: m.register() - preferences.ui_in_sidebar_update(core.get_addon_prefs(), bpy.context) + ## Update UI Tab name in sidebar (Disabled : cause Error in CLI when enabling addon with "--addons" flag) + # preferences.ui_in_sidebar_update(core.get_addon_prefs(), bpy.context) + bpy.app.handlers.load_post.append(subscribe_tab_update) def unregister(): + bpy.app.handlers.load_post.remove(subscribe_tab_update) for m in reversed(modules): m.unregister() diff --git a/preferences.py b/preferences.py index a771b39..02aa737 100644 --- a/preferences.py +++ b/preferences.py @@ -17,7 +17,7 @@ def ui_in_sidebar_update(self, _): if hasattr(bpy.types, BPM_PT_bg_manager_panel.bl_idname): try: bpy.utils.unregister_class(BPM_PT_bg_manager_panel) - except: + except Exception: pass BPM_PT_bg_manager_panel.bl_category = self.category.strip()