custom_shelf/__init__.py

89 lines
2.6 KiB
Python
Raw Permalink Normal View History

2022-03-04 12:28:53 +01:00
bl_info = {
"name": "Custom Shelf",
"author": "Christophe Seux",
"description": "Adds buttons to launch custom python scripts in the User panel.",
"version": (0, 3, 2),
2024-10-03 12:07:33 +02:00
"blender": (4, 0, 2),
2022-03-04 12:28:53 +01:00
"location": "View3D > User Panel",
2022-03-19 16:37:30 +01:00
"doc_url": "https://gitlab.com/autour-de-minuit/blender/custom_shelf/-/blob/main/README.md",
2022-03-04 12:28:53 +01:00
"tracker_url": "https://gitlab.com/autour-de-minuit/blender/custom_shelf/-/issues",
"support": "COMMUNITY",
"category": "User"}
if "bpy" in locals():
import importlib
importlib.reload(operators)
importlib.reload(panels)
importlib.reload(functions)
importlib.reload(properties)
2024-10-03 12:07:33 +02:00
from . utils import report
from . functions import read_shelves
from . import operators
from . import properties
from . import ui
2022-03-04 12:28:53 +01:00
from .properties import CustomShelfSettings,CustomShelfProps
import bpy
import os
2024-10-03 12:07:33 +02:00
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,
ui.CSHELF_MT_text_editor
2022-03-04 12:28:53 +01:00
]
2024-10-03 12:07:33 +02:00
def draw_menu(self, context):
self.layout.menu('CSHELF_MT_text_editor')
2022-03-04 12:28:53 +01:00
def register():
2024-10-03 12:07:33 +02:00
for bl_class in bl_classes :
bpy.utils.register_class(bl_class)
2022-03-04 12:28:53 +01:00
bpy.types.Scene.CustomShelf = bpy.props.PointerProperty(type=CustomShelfSettings)
bpy.types.WindowManager.CustomShelf = bpy.props.PointerProperty(type=CustomShelfProps)
2024-10-03 12:07:33 +02:00
bpy.types.TEXT_MT_editor_menus.append(draw_menu)
2022-03-04 12:28:53 +01:00
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:
2024-10-03 12:07:33 +02:00
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
2022-03-04 12:28:53 +01:00
read_shelves()
def unregister():
# unregister panel :
2024-10-03 12:07:33 +02:00
for panel in CustomShelfSettings.panel_list :
2022-03-04 12:28:53 +01:00
try :
2024-10-03 12:07:33 +02:00
bpy.utils.unregister_class(panel)
except Exception:
2022-03-04 12:28:53 +01:00
pass
2024-10-03 12:07:33 +02:00
bpy.types.TEXT_MT_editor_menus.remove(draw_menu)
2022-03-04 12:28:53 +01:00
del bpy.types.Scene.CustomShelf
del bpy.types.WindowManager.CustomShelf
2024-10-03 12:07:33 +02:00
for bl_class in bl_classes :
bpy.utils.unregister_class(bl_class)