[Bf-extensions-cvs] [cebfa3b6] master: Collection Manager: Code cleanup. Task: T69577

Ryan Inch noreply at git.blender.org
Mon Mar 9 07:53:39 CET 2020


Commit: cebfa3b6e6f4a436a937baf9549963dde2dedc6c
Author: Ryan Inch
Date:   Mon Mar 9 02:45:51 2020 -0400
Branches: master
https://developer.blender.org/rBAcebfa3b6e6f4a436a937baf9549963dde2dedc6c

Collection Manager: Code cleanup. Task: T69577

Combined all my global blender properties into a property group.
General code cleanup.

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

M	object_collection_manager/__init__.py
M	object_collection_manager/internals.py
M	object_collection_manager/operators.py
M	object_collection_manager/ui.py

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

diff --git a/object_collection_manager/__init__.py b/object_collection_manager/__init__.py
index 3739d71c..39a22906 100644
--- a/object_collection_manager/__init__.py
+++ b/object_collection_manager/__init__.py
@@ -22,7 +22,7 @@ bl_info = {
     "name": "Collection Manager",
     "description": "Manage collections and their objects",
     "author": "Ryan Inch",
-    "version": (1,9,2),
+    "version": (1,9,3),
     "blender": (2, 80, 0),
     "location": "View3D - Object Mode (Shortcut - M)",
     "warning": '',  # used for warning icon and text in addons panel
@@ -44,12 +44,28 @@ else:
     from . import ui
 
 import bpy
+from bpy.types import PropertyGroup
 from bpy.props import (
     CollectionProperty,
     IntProperty,
     BoolProperty,
+    PointerProperty,
     )
 
+
+class CollectionManagerProperties(PropertyGroup):
+    cm_list_collection: CollectionProperty(type=internals.CMListCollection)
+    cm_list_index: IntProperty(update=ui.update_selection)
+
+    show_exclude: BoolProperty(default=True, name="Exclude from View Layer")
+    show_selectable: BoolProperty(default=True, name="Selectable")
+    show_hide_viewport: BoolProperty(default=True, name="Hide in Viewport")
+    show_disable_viewport: BoolProperty(default=False, name="Disable in Viewports")
+    show_render: BoolProperty(default=False, name="Disable in Renders")
+
+    in_phantom_mode: BoolProperty(default=False)
+
+
 addon_keymaps = []
 
 classes = (
@@ -74,23 +90,14 @@ classes = (
     ui.CM_UL_items,
     ui.CollectionManager,
     ui.CMRestrictionTogglesPanel,
+    CollectionManagerProperties,
     )
 
 def register():
     for cls in classes:
         bpy.utils.register_class(cls)
 
-    bpy.types.Scene.CMListCollection = CollectionProperty(type=internals.CMListCollection)
-    bpy.types.Scene.CMListIndex = IntProperty(update=ui.update_selection)
-
-    bpy.types.Scene.show_exclude = BoolProperty(default=True, name="Exclude from View Layer")
-    bpy.types.Scene.show_selectable = BoolProperty(default=True, name="Selectable")
-    bpy.types.Scene.show_hideviewport = BoolProperty(default=True, name="Hide in Viewport")
-    bpy.types.Scene.show_disableviewport = BoolProperty(default=False, name="Disable in Viewports")
-    bpy.types.Scene.show_render = BoolProperty(default=False, name="Disable in Renders")
-
-    bpy.types.Scene.CM_Phantom_Mode = BoolProperty(default=False)
-
+    bpy.types.Scene.collection_manager = PointerProperty(type=CollectionManagerProperties)
 
     # create the global menu hotkey
     wm = bpy.context.window_manager
@@ -102,16 +109,7 @@ def unregister():
     for cls in classes:
         bpy.utils.unregister_class(cls)
 
-    del bpy.types.Scene.CMListCollection
-    del bpy.types.Scene.CMListIndex
-
-    del bpy.types.Scene.show_exclude
-    del bpy.types.Scene.show_selectable
-    del bpy.types.Scene.show_hideviewport
-    del bpy.types.Scene.show_disableviewport
-    del bpy.types.Scene.show_render
-
-    del bpy.types.Scene.CM_Phantom_Mode
+    del bpy.types.Scene.collection_manager
 
     # remove keymaps when add-on is deactivated
     for km, kmi in addon_keymaps:
diff --git a/object_collection_manager/internals.py b/object_collection_manager/internals.py
index 64c48150..5267b1c6 100644
--- a/object_collection_manager/internals.py
+++ b/object_collection_manager/internals.py
@@ -65,10 +65,11 @@ def update_collection_tree(context):
     max_lvl = 0
     row_index = 0
 
-    init_laycol_list = context.view_layer.layer_collection.children
+    layer_collection = context.view_layer.layer_collection
+    init_laycol_list = layer_collection.children
 
     master_laycol = {"id": 0,
-                     "name": context.view_layer.layer_collection.name,
+                     "name": layer_collection.name,
                      "lvl": -1,
                      "row_index": -1,
                      "visible": True,
@@ -76,7 +77,7 @@ def update_collection_tree(context):
                      "expanded": True,
                      "parent": None,
                      "children": [],
-                     "ptr": context.view_layer.layer_collection
+                     "ptr": layer_collection
                      }
 
     get_all_collections(context, init_laycol_list, master_laycol, collection_tree, visible=True)
@@ -120,15 +121,17 @@ def get_all_collections(context, collections, parent, tree, level=0, visible=Fal
 
 def update_property_group(context):
     update_collection_tree(context)
-    context.scene.CMListCollection.clear()
+    context.scene.collection_manager.cm_list_collection.clear()
     create_property_group(context, collection_tree)
 
 
 def create_property_group(context, tree):
     global in_filter
 
+    cm = context.scene.collection_manager
+
     for laycol in tree:
-        new_cm_listitem = context.scene.CMListCollection.add()
+        new_cm_listitem = cm.cm_list_collection.add()
         new_cm_listitem.name = laycol["name"]
 
         if laycol["has_children"]:
diff --git a/object_collection_manager/operators.py b/object_collection_manager/operators.py
index bd23f8a9..7f693ac9 100644
--- a/object_collection_manager/operators.py
+++ b/object_collection_manager/operators.py
@@ -120,7 +120,7 @@ class ExpandSublevelOperator(Operator):
 
 
         # set selected row to the collection you're expanding/collapsing and update tree view
-        context.scene.CMListIndex = self.index
+        context.scene.collection_manager.cm_list_index = self.index
         update_property_group(context)
 
         return {'FINISHED'}
@@ -192,7 +192,8 @@ class CMExcludeOperator(Operator):
         if modifiers == {"shift"}:
             # isolate/de-isolate exclusion of collections
 
-            active_layer_collections = [x["ptr"] for x in layer_collections.values() if not x["ptr"].exclude]
+            active_layer_collections = [x["ptr"] for x in layer_collections.values()
+                                        if not x["ptr"].exclude]
 
             # check if previous state should be restored
             if cls.isolated and self.name == target:
@@ -206,7 +207,8 @@ class CMExcludeOperator(Operator):
                 cls.isolated = False
 
             # check if all collections should be enabled
-            elif len(active_layer_collections) == 1 and active_layer_collections[0].name == self.name:
+            elif (len(active_layer_collections) == 1 and
+                  active_layer_collections[0].name == self.name):
                 # enable all collections
                 for item in layer_collections.values():
                     item["ptr"].exclude = False
@@ -441,8 +443,8 @@ class CMRestrictSelectOperator(Operator):
             laycol = layer_collections[self.name]
 
             # get active collections
-            active_layer_collections = [x["ptr"] for x in layer_collections.values() \
-                                          if x["ptr"].collection.hide_select == False]
+            active_layer_collections = [x["ptr"] for x in layer_collections.values()
+                                        if x["ptr"].collection.hide_select == False]
 
             # check if previous state should be restored
             if cls.isolated and self.name == target:
@@ -456,7 +458,8 @@ class CMRestrictSelectOperator(Operator):
                 cls.isolated = False
 
             # check if all collections should be enabled
-            elif len(active_layer_collections) == 1 and active_layer_collections[0].name == self.name:
+            elif (len(active_layer_collections) == 1 and
+                  active_layer_collections[0].name == self.name):
                 # make all collections selectable
                 for item in layer_collections.values():
                     item["ptr"].collection.hide_select = False
@@ -622,17 +625,19 @@ class CMUnRestrictSelectAllOperator(Operator):
             keep_history = False
 
             for item in layer_collections.values():
+                collection = item["ptr"].collection
+
                 if event.shift:
                     keep_history = True
-                    select_all_history.append(item["ptr"].collection.hide_select)
-                    item["ptr"].collection.hide_select = not item["ptr"].collection.hide_select
+                    select_all_history.append(collection.hide_select)
+                    collection.hide_select = not collection.hide_select
 
                 else:
-                    if item["ptr"].collection.hide_select:
+                    if collection.hide_select:
                         keep_history = True
 
-                    select_all_history.append(item["ptr"].collection.hide_select)
-                    item["ptr"].collection.hide_select = False
+                    select_all_history.append(collection.hide_select)
+                    collection.hide_select = False
 
             if not keep_history:
                 del rto_history["select_all"][view_layer]
@@ -677,8 +682,8 @@ class CMHideOperator(Operator):
             laycol = layer_collections[self.name]
 
             # get active collections
-            active_layer_collections = [x["ptr"] for x in layer_collections.values() \
-                                          if x["ptr"].hide_viewport == False]
+            active_layer_collections = [x["ptr"] for x in layer_collections.values()
+                                        if x["ptr"].hide_viewport == False]
 
             # check if previous state should be restored
             if cls.isolated and self.name == target:
@@ -692,7 +697,8 @@ class CMHideOperator(Operator):
                 cls.isolated = False
 
             # check if all collections should be enabled
-            elif len(active_layer_collections) == 1 and active_layer_collections[0].name == self.name:
+            elif (len(active_layer_collections) == 1 and
+                  active_layer_collections[0].name == self.name):
                 # show all collections
                 for laycol in layer_collections.values():
                     laycol["ptr"].hide_viewport = False
@@ -913,8 +919,8 @@ class CMDisableViewportOperator(Operator):
             laycol = layer_collections[self.name]
 
             # get active collections
-            active_layer_collect

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list