[Bf-blender-cvs] [3e8d01b5581] shot-tools-development: Added Addon Preferences + New Shot File operator.

Jeroen Bakker noreply at git.blender.org
Fri Jan 15 12:09:34 CET 2021


Commit: 3e8d01b55813960b7d473eb5fd11a3651561ea02
Author: Jeroen Bakker
Date:   Tue Jan 12 12:59:08 2021 +0100
Branches: shot-tools-development
https://developer.blender.org/rB3e8d01b55813960b7d473eb5fd11a3651561ea02

Added Addon Preferences + New Shot File operator.

The shot file operator uses the add-on preferences and current file to
detect what the root of the production is. It is prefilled in the
operator.

Operator does not do anything yet.

===================================================================

A	.gitignore
M	shot-builder/shot_builder/__init__.py
A	shot-builder/shot_builder/operators.py
A	shot-builder/shot_builder/project.py
A	shot-builder/shot_builder/properties.py
A	shot-builder/shot_builder/ui.py

===================================================================

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000000..bee8a64b79a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+__pycache__
diff --git a/shot-builder/shot_builder/__init__.py b/shot-builder/shot_builder/__init__.py
index e69de29bb2d..d86836b54ea 100644
--- a/shot-builder/shot_builder/__init__.py
+++ b/shot-builder/shot_builder/__init__.py
@@ -0,0 +1,53 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+bl_info = {
+    'name': 'Shot Builder',
+    "author": "Jeroen Bakker",
+    'version': (0, 1),
+    'blender': (2, 90, 0),
+    'location': 'Addon Preferences panel and file new menu',
+    'description': 'Shot builder production tool.',
+    'category': 'Studio',
+}
+
+import bpy
+
+from shot_builder.properties import *
+from shot_builder.operators import *
+from shot_builder.ui import *
+
+
+classes = (
+    ShotBuilderPreferences,
+    SHOTBUILDER_OT_NewShotFile,
+)
+
+
+def register():
+    for cls in classes:
+        bpy.utils.register_class(cls)
+    bpy.types.TOPBAR_MT_file_new.append(topbar_file_new_draw_handler)
+
+
+def unregister():
+    bpy.types.TOPBAR_MT_file_new.remove(topbar_file_new_draw_handler)
+    for cls in classes:
+        bpy.utils.unregister_class(cls)
diff --git a/shot-builder/shot_builder/operators.py b/shot-builder/shot_builder/operators.py
new file mode 100644
index 00000000000..9f159679e0e
--- /dev/null
+++ b/shot-builder/shot_builder/operators.py
@@ -0,0 +1,36 @@
+import bpy
+from shot_builder.project import *
+
+class SHOTBUILDER_OT_NewShotFile(bpy.types.Operator):
+    """Build a new shot file"""
+    bl_idname = "shotbuilder.new_shot_file"
+    bl_label = "New Production Shot File"
+
+    production_root: bpy.props.StringProperty(
+        name="Production Root",
+        description="Root of the production.",
+        subtype='DIR_PATH',
+    )
+
+    shot_id: bpy.props.StringProperty(
+        name="Shot ID",
+        description="Shot ID of the shot to build",
+    )
+
+    task_type: bpy.props.EnumProperty(
+        name="Task",
+        description="Task to create the shot file for",
+        items=(
+            ("anim", "anim", "anim"),
+        )
+    )
+
+    def invoke(self, context, event):
+        production_root = get_production_root(context)
+        if production_root:
+            self.production_root = str(production_root)
+        return context.window_manager.invoke_props_dialog(self, width = 400)
+    
+    def execute(self, context):
+        return {'CANCELLED'}
+    
\ No newline at end of file
diff --git a/shot-builder/shot_builder/project.py b/shot-builder/shot_builder/project.py
new file mode 100644
index 00000000000..f53ef24e291
--- /dev/null
+++ b/shot-builder/shot_builder/project.py
@@ -0,0 +1,81 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import pathlib
+
+import bpy
+
+
+def is_valid_project_path(project_path: pathlib.Path) -> bool:
+    """
+    Test if the given project path is configured correctly.
+    
+    A valid project path contains a subfolder with the name `shot-builder`
+    holding configuration files.
+    """
+    if not project_path.is_absolute():
+        return False
+    if not project_path.exists():
+        return False
+    if not project_path.is_dir():
+        return False
+    config_file_path = get_project_config_file_path(project_path)
+    return config_file_path.exists()
+
+
+def get_project_config_dir_path(project_path: pathlib.Path) -> pathlib.Path:
+    """
+    Get the project configuration dir path.
+    """
+    return project_path / "shot-builder"
+
+
+def get_project_config_file_path(project_path: pathlib.Path) -> pathlib.Path:
+    """
+    Get the project configuration file path.
+    """
+    return get_project_config_dir_path(project_path) / "config.py"
+
+
+def _find_production_root(path: pathlib.Path) -> pathlib.Path:
+    if is_valid_project_path(path):
+        return path
+    try:
+        parent_path = path.parents[0]
+        return _find_production_root(parent_path)
+    except IndexError:
+        return None
+    
+# TODO: return type is optional
+def get_production_root(context: bpy.types.Context) -> pathlib.Path:
+    """
+    Determine the project root based on the current file.
+    When current file isn't part of a project the project root 
+    configured in the add-on will be used.
+    """
+    current_file = pathlib.Path(bpy.data.filepath)
+    production_root = _find_production_root(current_file)
+    if production_root:
+        return production_root
+    production_root = pathlib.Path(
+        context.preferences.addons[__package__].preferences.project_path)
+    if is_valid_project_path(production_root):
+        return production_root
+    return None
diff --git a/shot-builder/shot_builder/properties.py b/shot-builder/shot_builder/properties.py
new file mode 100644
index 00000000000..79b74e689e3
--- /dev/null
+++ b/shot-builder/shot_builder/properties.py
@@ -0,0 +1,48 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+import bpy
+
+import pathlib
+
+from shot_builder.project import is_valid_project_path
+
+class ShotBuilderPreferences(bpy.types.AddonPreferences):
+    bl_idname = __package__
+
+    project_path: bpy.props.StringProperty(
+        name="Project Root",
+        description="The location to load configuration files from when "
+            "they couldn't be found in any parent folder of the current "
+            "file. Folder must contain a sub-folder named `shot-builder` "
+            "that holds the configuration files",
+        subtype='DIR_PATH',
+    )
+
+    def draw(self, context):
+        layout = self.layout
+
+        is_valid = is_valid_project_path(pathlib.Path(self.project_path))
+        layout.prop(self, "project_path", icon='NONE' if is_valid else 'ERROR')
+        if not is_valid:
+            layout.label(text="Folder must contain a sub-folder named "
+                              "`shot-builder` that holds the configuration "
+                              "files.",
+                         icon="ERROR")
+        
diff --git a/shot-builder/shot_builder/ui.py b/shot-builder/shot_builder/ui.py
new file mode 100644
index 00000000000..83f10b1a2ed
--- /dev/null
+++ b/shot-builder/shot_builder/ui.py
@@ -0,0 +1,9 @@
+import bpy
+
+
+from shot_builder.operators import *
+
+def topbar_file_new_draw_handler(self, context: bpy.types.Context):
+    layout = self.layout
+    op = layout.operator(SHOTBUILDER_OT_NewShotFile.bl_idname, text="Shot File")
+



More information about the Bf-blender-cvs mailing list