61 lines
2.6 KiB
Python

import bpy
from bpy.types import PropertyGroup, AddonPreferences
from bpy.props import StringProperty, CollectionProperty, IntProperty, BoolProperty
from .funcs import on_path_update
from .. import __package__ as base_package
class TemplateItem(PropertyGroup):
name: StringProperty(
name="Name", description="Display name for this template")
path: StringProperty(
name="Path", description="Path to the .blend file for this template", subtype='FILE_PATH', update=on_path_update)
class CustomTemplatesPreferences(AddonPreferences):
bl_idname = base_package
override_splash: BoolProperty(
default=True, name="Use Custom Templates", description="Override Splash Screen's 'New File' list with your Custom Templates")
start_from: BoolProperty(
default=False, name="Add option: File > New > Start from...", description="Show an option in File > New menu to start a new project from any .blend file")
projects: CollectionProperty(type=TemplateItem)
active_template_index: IntProperty(
description="Index of the selected template")
def draw(self, context):
layout = self.layout
layout.label(
text=f"Your custom templates ({len(self.projects)})")
row = layout.row()
row.template_list("UI_UL_list", "custom_templates",
self, "projects", self, "active_template_index", rows=6, maxrows=6)
col = row.column(align=True)
col.menu("CT_MT_templates_menu", icon='DOWNARROW_HLT', text="")
col.separator()
col.operator("ct.add_templates_from_folder", text="", icon="FILE_FOLDER")
col.operator("ct.add", icon='ADD', text="")
col.operator("ct.remove", icon='REMOVE', text="")
col.separator()
col.operator("ct.move_up", icon='TRIA_UP', text="")
col.operator("ct.move_down", icon='TRIA_DOWN', text="")
if self.projects:
project = self.projects[self.active_template_index]
layout.prop(project, "path")
layout.prop(project, "name")
b = layout.box()
b.label(text="Splash Screen", icon="SETTINGS")
b.prop(self, "override_splash")
box = b.box()
if self.override_splash and self.projects:
box.label(text="Custom templates will be shown in the Splash Screen.")
if not self.override_splash or len(self.projects) == 0:
box.label(
text="The default Blender list will be shown in the Splash Screen.", icon=("ERROR" if not self.projects else "NONE"))
b = layout.box()
b.label(text="Extra", icon="SETTINGS")
b.prop(self, "start_from")