mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
Quick Favorites Manager - support enum items
This commit is contained in:
@@ -33,6 +33,7 @@ classes = (
|
||||
operator.SetOverrideColour,
|
||||
operator.SnapSpacesTogether,
|
||||
operator.SplitAlongEdge,
|
||||
prop.QuickFavoriteEnumItem,
|
||||
prop.QuickFavoriteProperty,
|
||||
prop.QuickFavoritesItem,
|
||||
prop.BIMMiscProperties,
|
||||
|
||||
@@ -397,8 +397,11 @@ class ConfirmQuickFavoriteOperator(bpy.types.Operator):
|
||||
elif isinstance(p, bpy.types.IntProperty):
|
||||
item.value_prop = "int_value"
|
||||
item.int_value = p.default
|
||||
elif isinstance(p, (bpy.types.StringProperty, bpy.types.EnumProperty)):
|
||||
# TODO: support displaying enum items in the UI for EnumProperty
|
||||
elif isinstance(p, bpy.types.EnumProperty):
|
||||
item.value_prop = "enum_value"
|
||||
item.set_enum_items([(e.identifier, e.name, e.description) for e in p.enum_items])
|
||||
item.enum_value = p.default
|
||||
elif isinstance(p, bpy.types.StringProperty):
|
||||
item.value_prop = "string_value"
|
||||
item.string_value = p.default
|
||||
else:
|
||||
@@ -436,7 +439,7 @@ class ImportQuickFavorites(bpy.types.Operator):
|
||||
has_missing_props = True
|
||||
continue
|
||||
item = fav.properties[key]
|
||||
setattr(item, item.value_prop, value)
|
||||
item.set_value(value)
|
||||
|
||||
if has_missing_props:
|
||||
self.report(
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from typing import TYPE_CHECKING, Literal, cast, get_args
|
||||
from typing import TYPE_CHECKING, Any, Literal, cast, get_args
|
||||
|
||||
import bpy
|
||||
from bpy.props import (
|
||||
@@ -32,7 +32,22 @@ from bpy.types import PropertyGroup
|
||||
|
||||
from bonsai.bim.module.misc.data import QuickFavoritesData
|
||||
|
||||
QuickFavoriteValueType = Literal["float_value", "bool_value", "int_value", "string_value"]
|
||||
QuickFavoriteValueType = Literal["float_value", "bool_value", "int_value", "string_value", "enum_value"]
|
||||
|
||||
|
||||
class QuickFavoriteEnumItem(PropertyGroup):
|
||||
name: StringProperty(name="Name", default="") # pyright: ignore[reportRedeclaration]
|
||||
display_name: StringProperty(name="Display Name", default="") # pyright: ignore[reportRedeclaration]
|
||||
description: StringProperty(name="Description", default="") # pyright: ignore[reportRedeclaration]
|
||||
|
||||
if TYPE_CHECKING:
|
||||
name: str
|
||||
display_name: str
|
||||
description: str
|
||||
|
||||
|
||||
def get_enum_items(self: "QuickFavoriteProperty", context: bpy.types.Context | None) -> list[tuple[str, str, str]]:
|
||||
return [(item.name, item.display_name, item.description) for item in self.enum_items]
|
||||
|
||||
|
||||
class QuickFavoriteProperty(PropertyGroup):
|
||||
@@ -46,12 +61,25 @@ class QuickFavoriteProperty(PropertyGroup):
|
||||
float_value: FloatProperty(name="Float Value", default=0.0) # pyright: ignore[reportRedeclaration]
|
||||
int_value: IntProperty(name="Int Value", default=0) # pyright: ignore[reportRedeclaration]
|
||||
bool_value: BoolProperty(name="Bool Value", default=False) # pyright: ignore[reportRedeclaration]
|
||||
enum_value: EnumProperty(name="Enum Value", items=get_enum_items) # pyright: ignore[reportRedeclaration]
|
||||
enum_items: CollectionProperty(type=QuickFavoriteEnumItem) # pyright: ignore[reportRedeclaration]
|
||||
is_active: BoolProperty( # pyright: ignore[reportRedeclaration]
|
||||
name="Is Active",
|
||||
description="Only active properties will be added to the operator when invoked from Quick Favorites",
|
||||
default=False,
|
||||
)
|
||||
|
||||
def set_value(self, value: Any) -> None:
|
||||
setattr(self, self.value_prop, value)
|
||||
|
||||
def set_enum_items(self, items: list[tuple[str, str, str]]) -> None:
|
||||
self.enum_items.clear()
|
||||
for identifier, name, description in items:
|
||||
item = self.enum_items.add()
|
||||
item.name = identifier
|
||||
item.display_name = name
|
||||
item.description = description
|
||||
|
||||
if TYPE_CHECKING:
|
||||
name: str
|
||||
display_name: str
|
||||
@@ -60,6 +88,8 @@ class QuickFavoriteProperty(PropertyGroup):
|
||||
float_value: float
|
||||
int_value: int
|
||||
bool_value: bool
|
||||
enum_value: str
|
||||
enum_items: bpy.types.bpy_prop_collection_idprop[QuickFavoriteEnumItem]
|
||||
is_active: bool
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user