BIMTabProperties fixes

1) Fixed non-existent tool.Blender.get_screen
2) ui.py - remove try/except for the case when tabs are not loaded yet as it's covered by BIMTabProperties
3) removed previous_tab, alt_tab props never used in ui
4) general method for getting area properties that includes BIMTabProperties automatically
This commit is contained in:
Andrej730
2024-11-06 14:17:09 +05:00
parent e3de9c3ea4
commit 41fc0cf8c1
3 changed files with 51 additions and 59 deletions
+2 -3
View File
@@ -60,7 +60,7 @@ def update_tab(self: "BIMAreaProperties", context: bpy.types.Context) -> None:
def update_global_tab(self: "BIMTabProperties", context: bpy.types.Context) -> None: def update_global_tab(self: "BIMTabProperties", context: bpy.types.Context) -> None:
tool.Blender.setup_tabs() tool.Blender.setup_tabs()
screen = tool.Blender.get_screen(context) screen = context.id_data
aprops = screen.BIMAreaProperties[screen.areas[:].index(context.area)] aprops = screen.BIMAreaProperties[screen.areas[:].index(context.area)]
aprops.tab = self.tab aprops.tab = self.tab
@@ -400,10 +400,9 @@ class BIMAreaProperties(PropertyGroup):
# BIMAreaProperties exists per area and is setup on load post. However, for new # BIMAreaProperties exists per area and is setup on load post. However, for new
# or temporary screens, they may not be setup yet, so this global tab # or temporary screens, they may not be setup yet, so this global tab
# properties is used as a fallback. # properties is used as a fallback.
# Need it basically only for UI - to display those props and allow changing tab from the dropdown.
class BIMTabProperties(PropertyGroup): class BIMTabProperties(PropertyGroup):
tab: EnumProperty(default=0, items=get_tab, name="Tab", update=update_global_tab) tab: EnumProperty(default=0, items=get_tab, name="Tab", update=update_global_tab)
previous_tab: StringProperty(default="PROJECT", name="Previous Tab")
alt_tab: StringProperty(default="OBJECT", name="Alt Tab")
active_tab: BoolProperty(default=True, name="Active Tab") active_tab: BoolProperty(default=True, name="Active Tab")
inactive_tab: BoolProperty(default=False, name="Inactive Tab") inactive_tab: BoolProperty(default=False, name="Inactive Tab")
-6
View File
@@ -392,12 +392,8 @@ class BIM_PT_tabs(Panel):
bl_options = {"HIDE_HEADER"} bl_options = {"HIDE_HEADER"}
def draw(self, context): def draw(self, context):
try:
is_ifc_project = bool(tool.Ifc.get()) is_ifc_project = bool(tool.Ifc.get())
aprops = tool.Blender.get_area_props(context) aprops = tool.Blender.get_area_props(context)
if not aprops:
# Fallback in case areas aren't setup yet.
aprops = context.screen.BIMTabProperties
row = self.layout.row() row = self.layout.row()
row.alignment = "CENTER" row.alignment = "CENTER"
@@ -442,8 +438,6 @@ class BIM_PT_tabs(Panel):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.prop(aprops, "tab", text="") row.prop(aprops, "tab", text="")
except:
pass # Prior to load_post, we may not have any area properties setup
if bonsai.REINSTALLED_BBIM_VERSION: if bonsai.REINSTALLED_BBIM_VERSION:
box = self.layout.box() box = self.layout.box()
+6 -7
View File
@@ -86,16 +86,17 @@ class Blender(bonsai.core.tool.Blender):
area.spaces[0].region_3d.view_perspective = "CAMERA" area.spaces[0].region_3d.view_perspective = "CAMERA"
@classmethod @classmethod
def get_area_props(cls, context: bpy.types.Context) -> Any: def get_area_props(cls, context: bpy.types.Context) -> bpy.types.PropertyGroup:
try: try:
if context.screen.name.endswith("-nonnormal"): # Ctrl-space temporary fullscreen if context.screen.name.endswith("-nonnormal"): # Ctrl-space temporary fullscreen
screen = bpy.data.screens[context.screen.name[0 : -len("-nonnormal")]] screen = bpy.data.screens[context.screen.name.removesuffix("-nonnormal")]
# The original area object has its type changed to "EMPTY" apparently # The original area object has its type changed to "EMPTY" apparently
index = [a.type for a in screen.areas].index("EMPTY") index = [a.type for a in screen.areas].index("EMPTY")
return screen.BIMAreaProperties[index] return screen.BIMAreaProperties[index]
return context.screen.BIMAreaProperties[context.screen.areas[:].index(context.area)] return context.screen.BIMAreaProperties[context.screen.areas[:].index(context.area)]
except: except IndexError:
return # Fallback in case areas aren't setup yet.
return context.screen.BIMTabProperties
@classmethod @classmethod
def set_active_object(cls, obj: bpy.types.Object) -> None: def set_active_object(cls, obj: bpy.types.Object) -> None:
@@ -119,9 +120,7 @@ class Blender(bonsai.core.tool.Blender):
@classmethod @classmethod
def is_tab(cls, context: bpy.types.Context, tab: str) -> bool: def is_tab(cls, context: bpy.types.Context, tab: str) -> bool:
aprops = cls.get_area_props(context) aprops = cls.get_area_props(context)
if not aprops: if aprops.path_from_id() == "BIMAreaProperties" and context.area.spaces.active.search_filter:
return context.screen.BIMTabProperties.tab == tab
if context.area.spaces.active.search_filter:
return True return True
return aprops.tab == tab return aprops.tab == tab