custom_shelf/__init__.py
2025-12-03 16:58:25 +01:00

93 lines
2.6 KiB
Python

import os
import bpy
from . import operators, properties, ui, functions
from .functions import read_shelves
from .properties import CustomShelfProps, CustomShelfSettings
if "bpy" in locals():
import importlib
_ = importlib.reload(operators)
# _ = importlib.reload(panels)
_ = importlib.reload(functions)
_ = importlib.reload(properties)
bl_info = {
"name": "Custom Shelf",
"author": "Christophe Seux",
"description": "Adds buttons to launch custom python scripts in the User panel.",
"version": (0, 3, 2),
"blender": (4, 0, 2),
"location": "View3D > User Panel",
"doc_url": "https://gitlab.com/autour-de-minuit/blender/custom_shelf/-/blob/main/README.md",
"tracker_url": "https://gitlab.com/autour-de-minuit/blender/custom_shelf/-/issues",
"support": "COMMUNITY",
"category": "User",
}
bl_classes = [
properties.AdditionnalShelves,
properties.CustomShelfProps,
properties.CustomShelfSettings,
properties.CustomShelfPrefs,
operators.CSHELF_OT_refresh,
operators.CSHELF_OT_add_shelf_folder,
operators.CSHELF_OT_remove_shelf_folder,
operators.CSHELF_OT_open_shelf_folder,
operators.CSHELF_OT_add_script,
operators.CSHELF_OT_set_tag_filter,
operators.CustomShelfAddonPreferences,
ui.CSHELF_MT_text_editor,
]
def draw_menu(self, context: bpy.types.Context):
self.layout.menu("CSHELF_MT_text_editor")
def register():
for bl_class in bl_classes:
bpy.utils.register_class(bl_class)
# bpy.types.Scene.CustomShelf = bpy.props.PointerProperty(type=CustomShelfSettings)
# bpy.types.WindowManager.CustomShelf = bpy.props.PointerProperty(
# type=CustomShelfProps
# )
bpy.types.TEXT_MT_editor_menus.append(draw_menu)
env_shelves = os.getenv("CUSTOM_SHELVES")
if env_shelves:
shelves = env_shelves.split(os.pathsep)
prefs = bpy.context.preferences.addons[__name__].preferences
# prefs.global_shelves = ''
# prefs.additionnal_shelves.clear()
for path in shelves:
shelf = next((s for s in prefs.additionnal_shelves if s.path == path), None)
if not shelf:
shelf = prefs.additionnal_shelves.add()
shelf.path = path
read_shelves()
def unregister():
# unregister panel :
for panel in CustomShelfSettings.panel_list:
try:
bpy.utils.unregister_class(panel)
except Exception:
pass
bpy.types.TEXT_MT_editor_menus.remove(draw_menu)
# del bpy.types.Scene.CustomShelf
# del bpy.types.WindowManager.CustomShelf
for bl_class in bl_classes:
bpy.utils.unregister_class(bl_class)