[Bf-blender-cvs] [ff9bc901f43] master: Cleanup: grease pencil app-template versioning

Campbell Barton noreply at git.blender.org
Mon Aug 9 04:45:44 CEST 2021


Commit: ff9bc901f43668f27ea36e0d156a916aa08e8877
Author: Campbell Barton
Date:   Mon Aug 9 12:36:19 2021 +1000
Branches: master
https://developer.blender.org/rBff9bc901f43668f27ea36e0d156a916aa08e8877

Cleanup: grease pencil app-template versioning

- Remove check for screens being None as this would raise an error.
- Replace loop over `area.spaces` with `area.spaces.active`.
- Loop over grease pencil data directly instead of accessing
  through the scenes objects.
- Split versioning into functions.
- Use `update_factory_startup_*` prefix for function names
  as this isn't versioning existing files.

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

M	release/scripts/startup/bl_app_templates_system/2D_Animation/__init__.py
M	release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py

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

diff --git a/release/scripts/startup/bl_app_templates_system/2D_Animation/__init__.py b/release/scripts/startup/bl_app_templates_system/2D_Animation/__init__.py
index 40dd0729fec..be47890a002 100644
--- a/release/scripts/startup/bl_app_templates_system/2D_Animation/__init__.py
+++ b/release/scripts/startup/bl_app_templates_system/2D_Animation/__init__.py
@@ -21,48 +21,43 @@
 import bpy
 from bpy.app.handlers import persistent
 
-
- at persistent
-def load_handler(_):
-    import bpy
-
-    # 2D Animation
-    screen = bpy.data.screens['2D Animation']
-    if screen:
-        for area in screen.areas:
+def update_factory_startup_screens():
+    # 2D Animation.
+    screen = bpy.data.screens["2D Animation"]
+    for area in screen.areas:
+        if area.type == 'PROPERTIES':
             # Set Tool settings as default in properties panel.
-            if area.type == 'PROPERTIES':
-                for space in area.spaces:
-                    if space.type != 'PROPERTIES':
-                        continue
-                    space.context = 'TOOL'
-
+            space = area.spaces.active
+            space.context = 'TOOL'
+        elif area.type == 'DOPESHEET_EDITOR':
             # Open sidebar in Dopesheet.
-            elif area.type == 'DOPESHEET_EDITOR':
-                for space in area.spaces:
-                    if space.type != 'DOPESHEET_EDITOR':
-                        continue
-                    space.show_region_ui = True
+            space = area.spaces.active
+            space.show_region_ui = True
+
+    # 2D Full Canvas.
+    screen = bpy.data.screens["2D Full Canvas"]
+    for area in screen.areas:
+        if area.type == 'VIEW_3D':
+            space = area.spaces.active
+            space.shading.type = 'MATERIAL'
+            space.shading.use_scene_world = True
 
-    # 2D Full Canvas
-    screen = bpy.data.screens['2D Full Canvas']
-    if screen:
-        for area in screen.areas:
-            if area.type == 'VIEW_3D':
-                for space in area.spaces:
-                    if space.type != 'VIEW_3D':
-                        continue
-                    space.shading.type = 'MATERIAL'
-                    space.shading.use_scene_world = True
 
-    # Grease pencil object
-    scene = bpy.data.scenes[0]
-    if scene:
+def update_factory_startup_scenes():
+    for scene in bpy.data.scenes:
         scene.tool_settings.use_keyframe_insert_auto = True
-        for ob in scene.objects:
-            if ob.type == 'GPENCIL':
-                gpd = ob.data
-                gpd.onion_keyframe_type = 'ALL'
+
+
+def update_factory_startup_grease_pencils():
+    for gpd in bpy.data.grease_pencils:
+        gpd.onion_keyframe_type = 'ALL'
+
+
+ at persistent
+def load_handler(_):
+    update_factory_startup_screens()
+    update_factory_startup_scenes()
+    update_factory_startup_grease_pencils()
 
 
 def register():
diff --git a/release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py b/release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py
index c61acf2ce71..247a1ec342e 100644
--- a/release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py
+++ b/release/scripts/startup/bl_app_templates_system/Video_Editing/__init__.py
@@ -20,7 +20,7 @@ import bpy
 from bpy.app.handlers import persistent
 
 
-def do_version_file_browser():
+def update_factory_startup_screens():
     screen = bpy.data.screens["Video Editing"]
     for area in screen.areas:
         if area.type == 'FILE_BROWSER':
@@ -31,7 +31,7 @@ def do_version_file_browser():
 
 @persistent
 def load_handler(_):
-    do_version_file_browser()
+    update_factory_startup_screens()
 
 
 def register():



More information about the Bf-blender-cvs mailing list