From d3ed9be3b90febc943e052cbf5756ecef1a09f58 Mon Sep 17 00:00:00 2001 From: doc-code Date: Sun, 18 Aug 2024 16:56:44 +0200 Subject: [PATCH] Move draw functions to file --- addon/classes/draw.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 addon/classes/draw.py diff --git a/addon/classes/draw.py b/addon/classes/draw.py new file mode 100644 index 0000000..9713a70 --- /dev/null +++ b/addon/classes/draw.py @@ -0,0 +1,42 @@ +from .. import __package__ as base_package + +def draw_addon_separator(layout): + layout.separator() + layout.label(text="Custom Templates") + layout.separator() + +def draw_file_new_templates(self, context): + layout = self.layout + + prefs = context.preferences.addons[base_package].preferences + if len(prefs.projects) > 0: + draw_addon_separator(layout) + draw_templates_on_col(layout, context) + + +def draw_templates_on_col(layout, context, splash_mode = False): + layout.operator_context = 'INVOKE_DEFAULT' + + prefs = context.preferences.addons[base_package].preferences + for i in range(min(5, len(prefs.projects)) if splash_mode else len(prefs.projects)): + project = prefs.projects[i] + layout.operator( + "wm.read_homefile", text=project.name, icon="FILE_NEW" if splash_mode else "NONE").filepath = project.path + + +def draw_file_default_operators(self, context): + layout = self.layout + draw_addon_separator(layout) + # Manage Template + layout.operator("custom_templates.open_preferences", + text="Manage templates") + # Import/Export + layout.menu("custom_templates.export_menu", text="Import/Export") + layout.separator() + # Select new custom template + layout.operator("custom_templates.select_template_popup", + text="Select new custom template") + # Use current as new template (only with an active saved .blend file opened) + if bpy.data.filepath != "": + layout.operator("custom_templates.add_template_popup", + text="Use current as new template") \ No newline at end of file