Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Inch <mythologylover75@gmail.com>2020-03-09 09:45:51 +0300
committerRyan Inch <mythologylover75@gmail.com>2020-03-09 09:45:51 +0300
commitcebfa3b6e6f4a436a937baf9549963dde2dedc6c (patch)
treeed9b73005d65fc5bf5e3a96e9fe60e193b3b28ff
parent7861d837bad60bdd604c872d2b21bc38d8a6c64f (diff)
Collection Manager: Code cleanup. Task: T69577
Combined all my global blender properties into a property group. General code cleanup.
-rw-r--r--object_collection_manager/__init__.py42
-rw-r--r--object_collection_manager/internals.py13
-rw-r--r--object_collection_manager/operators.py121
-rw-r--r--object_collection_manager/ui.py163
4 files changed, 185 insertions, 154 deletions
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_collections = [x["ptr"] for x in layer_collections.values() \
- if x["ptr"].collection.hide_viewport == False]
+ active_layer_collections = [x["ptr"] for x in layer_collections.values()
+ if x["ptr"].collection.hide_viewport == False]
# check if previous state should be restored
if cls.isolated and self.name == target:
@@ -928,7 +934,8 @@ class CMDisableViewportOperator(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 in viewport
for laycol in layer_collections.values():
laycol["ptr"].collection.hide_viewport = False
@@ -1094,18 +1101,19 @@ class CMUnDisableViewportAllOperator(Operator):
keep_history = False
for item in layer_collections.values():
+ collection = item["ptr"].collection
+
if event.shift:
keep_history = True
- disable_all_history.append(item["ptr"].collection.hide_viewport)
- item["ptr"].collection.hide_viewport = not \
- item["ptr"].collection.hide_viewport
+ disable_all_history.append(collection.hide_viewport)
+ collection.hide_viewport = not collection.hide_viewport
else:
- if item["ptr"].collection.hide_viewport:
+ if collection.hide_viewport:
keep_history = True
- disable_all_history.append(item["ptr"].collection.hide_viewport)
- item["ptr"].collection.hide_viewport = False
+ disable_all_history.append(collection.hide_viewport)
+ collection.hide_viewport = False
if not keep_history:
del rto_history["disable_all"][view_layer]
@@ -1150,8 +1158,8 @@ class CMDisableRenderOperator(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_render == False]
+ active_layer_collections = [x["ptr"] for x in layer_collections.values()
+ if x["ptr"].collection.hide_render == False]
# check if previous state should be restored
if cls.isolated and self.name == target:
@@ -1165,7 +1173,8 @@ class CMDisableRenderOperator(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):
# allow render of all collections
for laycol in layer_collections.values():
laycol["ptr"].collection.hide_render = False
@@ -1331,18 +1340,19 @@ class CMUnDisableRenderAllOperator(Operator):
keep_history = False
for item in layer_collections.values():
+ collection = item["ptr"].collection
+
if event.shift:
keep_history = True
- render_all_history.append(item["ptr"].collection.hide_render)
- item["ptr"].collection.hide_render = not \
- item["ptr"].collection.hide_render
+ render_all_history.append(collection.hide_render)
+ collection.hide_render = not collection.hide_render
else:
- if item["ptr"].collection.hide_render:
+ if collection.hide_render:
keep_history = True
- render_all_history.append(item["ptr"].collection.hide_render)
- item["ptr"].collection.hide_render = False
+ render_all_history.append(collection.hide_render)
+ collection.hide_render = False
if not keep_history:
del rto_history["render_all"][view_layer]
@@ -1367,6 +1377,8 @@ class CMRemoveCollectionOperator(Operator):
def execute(self, context):
global rto_history
+ cm = context.scene.collection_manager
+
laycol = layer_collections[self.collection_name]
collection = laycol["ptr"].collection
parent_collection = laycol["parent"]["ptr"].collection
@@ -1389,8 +1401,8 @@ class CMRemoveCollectionOperator(Operator):
update_property_group(context)
- if len(context.scene.CMListCollection) == context.scene.CMListIndex:
- context.scene.CMListIndex = len(context.scene.CMListCollection) - 1
+ if len(cm.cm_list_collection) == cm.cm_list_index:
+ cm.cm_list_index = len(cm.cm_list_collection) - 1
update_property_group(context)
@@ -1413,12 +1425,13 @@ class CMNewCollectionOperator(Operator):
global rto_history
new_collection = bpy.data.collections.new('Collection')
- scn = context.scene
+ cm = context.scene.collection_manager
+
# if there are collections
- if len(scn.CMListCollection) > 0:
+ if len(cm.cm_list_collection) > 0:
# get selected collection
- laycol = layer_collections[scn.CMListCollection[scn.CMListIndex].name]
+ laycol = layer_collections[cm.cm_list_collection[cm.cm_list_index].name]
# add new collection
if self.child:
@@ -1428,7 +1441,7 @@ class CMNewCollectionOperator(Operator):
# update tree view property
update_property_group(context)
- scn.CMListIndex = layer_collections[new_collection.name]["row_index"]
+ cm.cm_list_index = layer_collections[new_collection.name]["row_index"]
else:
laycol["parent"]["ptr"].collection.children.link(new_collection)
@@ -1436,16 +1449,16 @@ class CMNewCollectionOperator(Operator):
# update tree view property
update_property_group(context)
- scn.CMListIndex = layer_collections[new_collection.name]["row_index"]
+ cm.cm_list_index = layer_collections[new_collection.name]["row_index"]
# if no collections add top level collection and select it
else:
- scn.collection.children.link(new_collection)
+ context.scene.collection.children.link(new_collection)
# update tree view property
update_property_group(context)
- scn.CMListIndex = 0
+ cm.cm_list_index = 0
global rename
rename[0] = True
@@ -1482,18 +1495,18 @@ class CMPhantomModeOperator(Operator):
global phantom_history
global rto_history
- scn = context.scene
- view_layer = context.view_layer.name
+ cm = context.scene.collection_manager
+ view_layer = context.view_layer
# enter Phantom Mode
- if not scn.CM_Phantom_Mode:
+ if not cm.in_phantom_mode:
- scn.CM_Phantom_Mode = True
+ cm.in_phantom_mode = True
# save current visibility state
- phantom_history["view_layer"] = view_layer
+ phantom_history["view_layer"] = view_layer.name
- laycol_iter_list = [context.view_layer.layer_collection.children]
+ laycol_iter_list = [view_layer.layer_collection.children]
while len(laycol_iter_list) > 0:
new_laycol_iter_list = []
for laycol_iter in laycol_iter_list:
@@ -1514,13 +1527,13 @@ class CMPhantomModeOperator(Operator):
# save current rto history
for rto, history, in rto_history.items():
- if history.get(view_layer, None):
- phantom_history[rto+"_history"] = deepcopy(history[view_layer])
+ if history.get(view_layer.name, None):
+ phantom_history[rto+"_history"] = deepcopy(history[view_layer.name])
# return to normal mode
else:
- laycol_iter_list = [context.view_layer.layer_collection.children]
+ laycol_iter_list = [view_layer.layer_collection.children]
while len(laycol_iter_list) > 0:
new_laycol_iter_list = []
for laycol_iter in laycol_iter_list:
@@ -1551,15 +1564,15 @@ class CMPhantomModeOperator(Operator):
# restore previous rto history
for rto, history, in rto_history.items():
- if view_layer in history:
- del history[view_layer]
+ if view_layer.name in history:
+ del history[view_layer.name]
if phantom_history[rto+"_history"]:
- history[view_layer] = deepcopy(phantom_history[rto+"_history"])
+ history[view_layer.name] = deepcopy(phantom_history[rto+"_history"])
phantom_history[rto+"_history"].clear()
- scn.CM_Phantom_Mode = False
+ cm.in_phantom_mode = False
return {'FINISHED'}
diff --git a/object_collection_manager/ui.py b/object_collection_manager/ui.py
index dfdeb889..dcd804fa 100644
--- a/object_collection_manager/ui.py
+++ b/object_collection_manager/ui.py
@@ -49,12 +49,12 @@ class CollectionManager(Operator):
def draw(self, context):
layout = self.layout
- scn = context.scene
- view_layer = context.view_layer.name
+ cm = context.scene.collection_manager
+ view_layer = context.view_layer
- if view_layer != self.last_view_layer:
+ if view_layer.name != self.last_view_layer:
update_collection_tree(context)
- self.last_view_layer = view_layer
+ self.last_view_layer = view_layer.name
title_row = layout.split(factor=0.5)
main = title_row.row()
@@ -63,7 +63,7 @@ class CollectionManager(Operator):
main.label(text="Collection Manager")
- view.prop(context.view_layer, "use", text="")
+ view.prop(view_layer, "use", text="")
view.separator()
window = context.window
@@ -104,48 +104,54 @@ class CollectionManager(Operator):
sec2 = toggle_row.row()
sec2.alignment = 'RIGHT'
- if scn.show_exclude:
- exclude_all_history = rto_history["exclude_all"].get(view_layer, [])
+ if cm.show_exclude:
+ exclude_all_history = rto_history["exclude_all"].get(view_layer.name, [])
depress = True if len(exclude_all_history) else False
sec2.operator("view3d.un_exclude_all_collections", text="", icon='CHECKBOX_HLT', depress=depress)
- if scn.show_selectable:
- select_all_history = rto_history["select_all"].get(view_layer, [])
+ if cm.show_selectable:
+ select_all_history = rto_history["select_all"].get(view_layer.name, [])
depress = True if len(select_all_history) else False
sec2.operator("view3d.un_restrict_select_all_collections", text="", icon='RESTRICT_SELECT_OFF', depress=depress)
- if scn.show_hideviewport:
- hide_all_history = rto_history["hide_all"].get(view_layer, [])
+ if cm.show_hide_viewport:
+ hide_all_history = rto_history["hide_all"].get(view_layer.name, [])
depress = True if len(hide_all_history) else False
sec2.operator("view3d.un_hide_all_collections", text="", icon='HIDE_OFF', depress=depress)
- if scn.show_disableviewport:
- disable_all_history = rto_history["disable_all"].get(view_layer, [])
+ if cm.show_disable_viewport:
+ disable_all_history = rto_history["disable_all"].get(view_layer.name, [])
depress = True if len(disable_all_history) else False
sec2.operator("view3d.un_disable_viewport_all_collections", text="", icon='RESTRICT_VIEW_OFF', depress=depress)
- if scn.show_render:
- render_all_history = rto_history["render_all"].get(view_layer, [])
+ if cm.show_render:
+ render_all_history = rto_history["render_all"].get(view_layer.name, [])
depress = True if len(render_all_history) else False
sec2.operator("view3d.un_disable_render_all_collections", text="", icon='RESTRICT_RENDER_OFF', depress=depress)
- layout.row().template_list("CM_UL_items", "", context.scene, "CMListCollection", context.scene, "CMListIndex", rows=15, sort_lock=True)
+ layout.row().template_list("CM_UL_items", "",
+ cm, "cm_list_collection",
+ cm, "cm_list_index",
+ rows=15,
+ sort_lock=True)
addcollec_row = layout.row()
- addcollec_row.operator("view3d.add_collection", text="Add Collection", icon='COLLECTION_NEW').child = False
+ addcollec_row.operator("view3d.add_collection", text="Add Collection",
+ icon='COLLECTION_NEW').child = False
- addcollec_row.operator("view3d.add_collection", text="Add SubCollection", icon='COLLECTION_NEW').child = True
+ addcollec_row.operator("view3d.add_collection", text="Add SubCollection",
+ icon='COLLECTION_NEW').child = True
phantom_row = layout.row()
- toggle_text = "Disable " if scn.CM_Phantom_Mode else "Enable "
+ toggle_text = "Disable " if cm.in_phantom_mode else "Enable "
phantom_row.operator("view3d.toggle_phantom_mode", text=toggle_text+"Phantom Mode")
- if scn.CM_Phantom_Mode:
+ if cm.in_phantom_mode:
view.enabled = False
addcollec_row.enabled = False
@@ -154,23 +160,27 @@ class CollectionManager(Operator):
wm = context.window_manager
update_property_group(context)
- self.view_layer = context.view_layer.name
+
+ cm = context.scene.collection_manager
+ view_layer = context.view_layer
+
+ self.view_layer = view_layer.name
# sync selection in ui list with active layer collection
try:
- active_laycol_name = context.view_layer.active_layer_collection.name
+ active_laycol_name = view_layer.active_layer_collection.name
active_laycol_row_index = layer_collections[active_laycol_name]["row_index"]
- context.scene.CMListIndex = active_laycol_row_index
+ cm.cm_list_index = active_laycol_row_index
except:
- context.scene.CMListIndex = -1
+ cm.cm_list_index = -1
# check if in phantom mode and if it's still viable
- if context.scene.CM_Phantom_Mode:
+ if cm.in_phantom_mode:
if set(layer_collections.keys()) != set(phantom_history["initial_state"].keys()):
- context.scene.CM_Phantom_Mode = False
+ cm.in_phantom_mode = False
- if context.view_layer.name != phantom_history["view_layer"]:
- context.scene.CM_Phantom_Mode = False
+ if view_layer.name != phantom_history["view_layer"]:
+ cm.in_phantom_mode = False
# handle window sizing
max_width = 960
@@ -191,12 +201,12 @@ class CollectionManager(Operator):
def update_selection(self, context):
- scn = context.scene
+ cm = context.scene.collection_manager
- if scn.CMListIndex == -1:
+ if cm.cm_list_index == -1:
return
- selected_item = scn.CMListCollection[scn.CMListIndex]
+ selected_item = cm.cm_list_collection[cm.cm_list_index]
layer_collection = layer_collections[selected_item.name]["ptr"]
context.view_layer.active_layer_collection = layer_collection
@@ -250,8 +260,8 @@ class CM_UL_items(UIList):
def draw_item(self, context, layout, data, item, icon, active_data,active_propname, index):
self.use_filter_show = True
- scn = context.scene
- view_layer = context.view_layer.name
+ cm = context.scene.collection_manager
+ view_layer = context.view_layer
laycol = layer_collections[item.name]
collection = laycol["ptr"].collection
@@ -267,13 +277,15 @@ class CM_UL_items(UIList):
# add expander if collection has children to make UIList act like tree view
if laycol["has_children"]:
if laycol["expanded"]:
- prop = row.operator("view3d.expand_sublevel", text="", icon='DISCLOSURE_TRI_DOWN', emboss=False)
+ prop = row.operator("view3d.expand_sublevel", text="",
+ icon='DISCLOSURE_TRI_DOWN', emboss=False)
prop.expand = False
prop.name = item.name
prop.index = index
else:
- prop = row.operator("view3d.expand_sublevel", text="", icon='DISCLOSURE_TRI_RIGHT', emboss=False)
+ prop = row.operator("view3d.expand_sublevel", text="",
+ icon='DISCLOSURE_TRI_RIGHT', emboss=False)
prop.expand = True
prop.name = item.name
prop.index = index
@@ -286,7 +298,7 @@ class CM_UL_items(UIList):
name_row = row.row()
- #if rename[0] and index == scn.CMListIndex:
+ #if rename[0] and index == cm.cm_list_index:
#name_row.activate_init = True
#rename[0] = False
@@ -308,72 +320,77 @@ class CM_UL_items(UIList):
row_setcol.enabled = False
- prop = row_setcol.operator("view3d.set_collection", text="", icon=icon, emboss=False)
+ prop = row_setcol.operator("view3d.set_collection", text="",
+ icon=icon, emboss=False)
prop.collection_index = laycol["id"]
prop.collection_name = item.name
- if scn.show_exclude:
- exclude_history_base = rto_history["exclude"].get(view_layer, {})
+ if cm.show_exclude:
+ exclude_history_base = rto_history["exclude"].get(view_layer.name, {})
exclude_target = exclude_history_base.get("target", "")
exclude_history = exclude_history_base.get("history", [])
- depress = True if len(exclude_history) and exclude_target == item.name else False
- emboss = True if len(exclude_history) and exclude_target == item.name else False
+ highlight = bool(exclude_history and exclude_target == item.name)
icon = 'CHECKBOX_DEHLT' if laycol["ptr"].exclude else 'CHECKBOX_HLT'
- row.operator("view3d.exclude_collection", text="", icon=icon, emboss=emboss, depress=depress).name = item.name
+ row.operator("view3d.exclude_collection", text="", icon=icon,
+ emboss=highlight, depress=highlight).name = item.name
- if scn.show_selectable:
- select_history_base = rto_history["select"].get(view_layer, {})
+ if cm.show_selectable:
+ select_history_base = rto_history["select"].get(view_layer.name, {})
select_target = select_history_base.get("target", "")
select_history = select_history_base.get("history", [])
- depress = True if len(select_history) and select_target == item.name else False
- emboss = True if len(select_history) and select_target == item.name else False
- icon = 'RESTRICT_SELECT_ON' if laycol["ptr"].collection.hide_select else 'RESTRICT_SELECT_OFF'
+ highlight = bool(select_history and select_target == item.name)
+ icon = ('RESTRICT_SELECT_ON' if laycol["ptr"].collection.hide_select else
+ 'RESTRICT_SELECT_OFF')
- row.operator("view3d.restrict_select_collection", text="", icon=icon, emboss=emboss, depress=depress).name = item.name
+ row.operator("view3d.restrict_select_collection", text="", icon=icon,
+ emboss=highlight, depress=highlight).name = item.name
- if scn.show_hideviewport:
- hide_history_base = rto_history["hide"].get(view_layer, {})
+ if cm.show_hide_viewport:
+ hide_history_base = rto_history["hide"].get(view_layer.name, {})
hide_target = hide_history_base.get("target", "")
hide_history = hide_history_base.get("history", [])
- depress = True if len(hide_history) and hide_target == item.name else False
- emboss = True if len(hide_history) and hide_target == item.name else False
+ highlight = bool(hide_history and hide_target == item.name)
icon = 'HIDE_ON' if laycol["ptr"].hide_viewport else 'HIDE_OFF'
- row.operator("view3d.hide_collection", text="", icon=icon, emboss=emboss, depress=depress).name = item.name
+ row.operator("view3d.hide_collection", text="", icon=icon,
+ emboss=highlight, depress=highlight).name = item.name
- if scn.show_disableviewport:
- disable_history_base = rto_history["disable"].get(view_layer, {})
+ if cm.show_disable_viewport:
+ disable_history_base = rto_history["disable"].get(view_layer.name, {})
disable_target = disable_history_base.get("target", "")
disable_history = disable_history_base.get("history", [])
- depress = True if len(disable_history) and disable_target == item.name else False
- emboss = True if len(disable_history) and disable_target == item.name else False
- icon = 'RESTRICT_VIEW_ON' if laycol["ptr"].collection.hide_viewport else 'RESTRICT_VIEW_OFF'
+ highlight = bool(disable_history and disable_target == item.name)
+ icon = ('RESTRICT_VIEW_ON' if laycol["ptr"].collection.hide_viewport else
+ 'RESTRICT_VIEW_OFF')
- row.operator("view3d.disable_viewport_collection", text="", icon=icon, emboss=emboss, depress=depress).name = item.name
+ row.operator("view3d.disable_viewport_collection", text="", icon=icon,
+ emboss=highlight, depress=highlight).name = item.name
- if scn.show_render:
- render_history_base = rto_history["render"].get(view_layer, {})
+ if cm.show_render:
+ render_history_base = rto_history["render"].get(view_layer.name, {})
render_target = render_history_base.get("target", "")
render_history = render_history_base.get("history", [])
- depress = True if len(render_history) and render_target == item.name else False
- emboss = True if len(render_history) and render_target == item.name else False
- icon = 'RESTRICT_RENDER_ON' if laycol["ptr"].collection.hide_render else 'RESTRICT_RENDER_OFF'
+ highlight = bool(render_history and render_target == item.name)
+ icon = ('RESTRICT_RENDER_ON' if laycol["ptr"].collection.hide_render else
+ 'RESTRICT_RENDER_OFF')
- row.operator("view3d.disable_render_collection", text="", icon=icon, emboss=emboss, depress=depress).name = item.name
+ row.operator("view3d.disable_render_collection", text="", icon=icon,
+ emboss=highlight, depress=highlight).name = item.name
rm_op = split.row()
rm_op.alignment = 'RIGHT'
- rm_op.operator("view3d.remove_collection", text="", icon='X', emboss=False).collection_name = item.name
+ rm_op.operator("view3d.remove_collection", text="", icon='X',
+ emboss=False).collection_name = item.name
- if scn.CM_Phantom_Mode:
+ if cm.in_phantom_mode:
name_row.enabled = False
row_setcol.enabled = False
rm_op.enabled = False
@@ -432,13 +449,13 @@ class CMRestrictionTogglesPanel(Panel):
bl_region_type = 'HEADER'
def draw(self, context):
+ cm = context.scene.collection_manager
layout = self.layout
-
row = layout.row()
- row.prop(context.scene, "show_exclude", icon='CHECKBOX_HLT', icon_only=True)
- row.prop(context.scene, "show_selectable", icon='RESTRICT_SELECT_OFF', icon_only=True)
- row.prop(context.scene, "show_hideviewport", icon='HIDE_OFF', icon_only=True)
- row.prop(context.scene, "show_disableviewport", icon='RESTRICT_VIEW_OFF', icon_only=True)
- row.prop(context.scene, "show_render", icon='RESTRICT_RENDER_OFF', icon_only=True)
+ row.prop(cm, "show_exclude", icon='CHECKBOX_HLT', icon_only=True)
+ row.prop(cm, "show_selectable", icon='RESTRICT_SELECT_OFF', icon_only=True)
+ row.prop(cm, "show_hide_viewport", icon='HIDE_OFF', icon_only=True)
+ row.prop(cm, "show_disable_viewport", icon='RESTRICT_VIEW_OFF', icon_only=True)
+ row.prop(cm, "show_render", icon='RESTRICT_RENDER_OFF', icon_only=True)