From 83d321c69d7d9d8d9db2ea1e0dbbe371cb691aa8 Mon Sep 17 00:00:00 2001 From: Aurelien Vaillant Date: Thu, 6 Jun 2024 19:55:46 +0200 Subject: [PATCH] Make a class panel to easily draw each class --- Fange_Pipeline/__init__.py | 8 ++++---- Fange_Pipeline/ui/asset.py | 8 +++----- Fange_Pipeline/ui/export.py | 36 ++---------------------------------- Fange_Pipeline/ui/icon.py | 7 ++----- Fange_Pipeline/ui/main.py | 25 +++++++++++++++++++++++++ Fange_Pipeline/ui/setup.py | 13 +++++++------ 6 files changed, 43 insertions(+), 54 deletions(-) create mode 100644 Fange_Pipeline/ui/main.py diff --git a/Fange_Pipeline/__init__.py b/Fange_Pipeline/__init__.py index f7e1338..12e6779 100644 --- a/Fange_Pipeline/__init__.py +++ b/Fange_Pipeline/__init__.py @@ -1,9 +1,9 @@ import bpy # UI and Interface -from .ui.asset import GRAOU_PT_asset +from .ui.asset import GraouPanel_asset from .ui.export import GRAOU_PT_export -from .ui.icon import GRAOU_PT_thumbnail +from .ui.icon import GraouPanel_thumbnail from .ui.setup import GRAOU_PT_setup # All operators from .operators.exports import ExportForFange @@ -29,8 +29,8 @@ bl_info = { modules_class = [ # Main operators property ExportForFange, MakeBasicCollision, ConfigBlendScene, ConfigLighting, - # UI - GRAOU_PT_asset, GRAOU_PT_export, GRAOU_PT_thumbnail, GRAOU_PT_setup, + # UI, the order are the way to select how show each panel + GRAOU_PT_setup, GraouPanel_asset, GRAOU_PT_export, GraouPanel_thumbnail, # Preference GRAOU_AddonPreference, FangeProperties ] diff --git a/Fange_Pipeline/ui/asset.py b/Fange_Pipeline/ui/asset.py index b09910f..86bd586 100644 --- a/Fange_Pipeline/ui/asset.py +++ b/Fange_Pipeline/ui/asset.py @@ -1,14 +1,12 @@ -import bpy +from .main import GraouPanel -class GRAOU_PT_asset(bpy.types.Panel): +class GraouPanel_asset(GraouPanel): bl_idname = 'GRAOU_PT_asset' - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' bl_label = 'Generate Assets' - bl_category = 'Graou Studio' def draw(self, context): layout = self.layout layout.label(text='Asset:') + layout.operator('graou.make_collision', text='Generate collision', icon='MOD_PHYSICS') diff --git a/Fange_Pipeline/ui/export.py b/Fange_Pipeline/ui/export.py index 1a3021f..3e6aa3f 100644 --- a/Fange_Pipeline/ui/export.py +++ b/Fange_Pipeline/ui/export.py @@ -1,45 +1,13 @@ -import bpy -# import os - -# from pathlib import Path -# -# preview_collection = {} -# icon_sauropod_path = Path(os.path.dirname(os.path.abspath(__file__)), "icons") -# -# pcoll = bpy.utils.previews.new() -# -# for entry in os.scandir(icon_sauropod_path): -# if entry.name.endswith(".png"): -# name = os.path.splitext(entry.name)[0] -# print(f'[Pipeline] Add icon "{name}"') -# pcoll.load(name.upper(), entry.path, "IMAGE") +from .main import GraouPanel -class GRAOU_PT_export(bpy.types.Panel): +class GRAOU_PT_export(GraouPanel): bl_idname = 'GRAOU_PT_MAIN' - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' bl_label = 'Export' - bl_category = 'Graou Studio' def draw(self, context): layout = self.layout - # layout.label(text='Graou Pipeline', icon_value=pcoll["GRAOU"].icon_id) - - col = layout.column(align=True) - col.label(text='Main Config:') - col.operator('graou.build_scene', text='Init Scene', icon='OUTLINER') - col.prop(context.scene.graou_props, 'socket_collection', text='Use socket', toggle=True) - col.operator('graou.lighting', text='Set basic lighting', icon='OUTLINER_OB_LIGHT') - - layout.separator() - - layout.label(text='Asset:') - layout.operator('graou.make_collision', text='Generate collision', icon='MOD_PHYSICS') - - layout.separator() - layout.label(text='Export scene:') box = layout.box() box.label(text='Sanity Check') diff --git a/Fange_Pipeline/ui/icon.py b/Fange_Pipeline/ui/icon.py index c1fba31..92a22fe 100644 --- a/Fange_Pipeline/ui/icon.py +++ b/Fange_Pipeline/ui/icon.py @@ -1,12 +1,9 @@ -import bpy +from .main import GraouPanel -class GRAOU_PT_thumbnail(bpy.types.Panel): +class GraouPanel_thumbnail(GraouPanel): bl_idname = 'GRAOU_PT_thumbnail' - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' bl_label = 'Thumbnail' - bl_category = 'Graou Studio' def draw(self, context): layout = self.layout diff --git a/Fange_Pipeline/ui/main.py b/Fange_Pipeline/ui/main.py new file mode 100644 index 0000000..521cf9f --- /dev/null +++ b/Fange_Pipeline/ui/main.py @@ -0,0 +1,25 @@ +import bpy +# import os + +# from pathlib import Path +# +# preview_collection = {} +# icon_sauropod_path = Path(os.path.dirname(os.path.abspath(__file__)), "icons") +# +# pcoll = bpy.utils.previews.new() +# +# for entry in os.scandir(icon_sauropod_path): +# if entry.name.endswith(".png"): +# name = os.path.splitext(entry.name)[0] +# print(f'[Pipeline] Add icon "{name}"') +# pcoll.load(name.upper(), entry.path, "IMAGE") + +# layout.label(text='Graou Pipeline', icon_value=pcoll["GRAOU"].icon_id) + + +class GraouPanel(bpy.types.Panel): + bl_idname = 'GRAOU_PT_MAIN' + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_label = 'Export' + bl_category = 'Graou Studio' diff --git a/Fange_Pipeline/ui/setup.py b/Fange_Pipeline/ui/setup.py index fa2d895..85b00bd 100644 --- a/Fange_Pipeline/ui/setup.py +++ b/Fange_Pipeline/ui/setup.py @@ -1,14 +1,15 @@ -import bpy +from .main import GraouPanel -class GRAOU_PT_setup(bpy.types.Panel): +class GRAOU_PT_setup(GraouPanel): bl_idname = 'GRAOU_PT_setup' - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' bl_label = 'Setup Pipeline' - bl_category = 'Graou Studio' def draw(self, context): layout = self.layout - layout.label(text='Main Config:') + col = layout.column(align=True) + col.label(text='Main Config:') + col.operator('graou.build_scene', text='Init Scene', icon='OUTLINER') + col.prop(context.scene.graou_props, 'socket_collection', text='Use socket', toggle=True) + col.operator('graou.lighting', text='Set basic lighting', icon='OUTLINER_OB_LIGHT')