From 1cb0ec14fa685680e972c88f68cf4fa9d2475809 Mon Sep 17 00:00:00 2001 From: Doug Hammond <doughammond@hamsterfight.co.uk> Date: Tue, 28 Jun 2011 20:00:43 +0000 Subject: [PATCH] extensions_framework: add ability to set UILayout alert state based on a logical test of PropertyGroup members --- modules/extensions_framework/__init__.py | 7 +++++++ modules/extensions_framework/ui.py | 25 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/extensions_framework/__init__.py b/modules/extensions_framework/__init__.py index b34940429..df815eb3c 100644 --- a/modules/extensions_framework/__init__.py +++ b/modules/extensions_framework/__init__.py @@ -246,6 +246,13 @@ class declarative_property_group(bpy.types.PropertyGroup): """ enabled = {} + """The alert dict controls the alert state of properties based on + the value of other properties. See extensions_framework.validate + for test syntax. + + """ + alert = {} + """The properties list describes each property to be created. Each item should be a dict of args to pass to a bpy.props.<?>Property function, with the exception of 'type' diff --git a/modules/extensions_framework/ui.py b/modules/extensions_framework/ui.py index 5c846712b..4f24d8734 100644 --- a/modules/extensions_framework/ui.py +++ b/modules/extensions_framework/ui.py @@ -116,6 +116,19 @@ class property_group_renderer(bpy.types.Panel): else: return True + def check_alert(self, lookup_property, property_group): + """Determine if the lookup_property should be in an alert state in the Panel""" + et = Logician(property_group) + if lookup_property in property_group.alert.keys(): + if hasattr(property_group, lookup_property): + member = getattr(property_group, lookup_property) + else: + member = None + return et.test_logic(member, + property_group.alert[lookup_property]) + else: + return False + def is_real_property(self, lookup_property, property_group): for prop in property_group.properties: if prop['attr'] == lookup_property: @@ -158,11 +171,21 @@ class property_group_renderer(bpy.types.Panel): if current_property['attr'] == control_list_item: current_property_keys = current_property.keys() + sub_layout_created = False if not self.check_enabled(control_list_item, property_group): last_layout = layout + sub_layout_created = True + layout = layout.row() layout.enabled = False + if self.check_alert(control_list_item, property_group): + if not sub_layout_created: + last_layout = layout + sub_layout_created = True + layout = layout.row() + layout.alert = True + if 'type' in current_property_keys: if current_property['type'] in ['int', 'float', 'float_vector', 'string']: @@ -304,7 +327,7 @@ class property_group_renderer(bpy.types.Panel): else: layout.prop(property_group, control_list_item) - if not self.check_enabled(control_list_item, property_group): + if sub_layout_created: layout = last_layout # Fire a draw callback if specified -- GitLab