[Bf-blender-cvs] [b54b4ee] master: UI: expose soft limits to custom-property editor

Campbell Barton noreply at git.blender.org
Tue Feb 23 17:02:51 CET 2016


Commit: b54b4eee3bb557b5c3bb2024a94559e131888895
Author: Campbell Barton
Date:   Wed Feb 24 02:53:11 2016 +1100
Branches: master
https://developer.blender.org/rBb54b4eee3bb557b5c3bb2024a94559e131888895

UI: expose soft limits to custom-property editor

Internally custom-id-properties used soft-limits, but there was no way to edit these.

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

M	release/scripts/startup/bl_operators/wm.py

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

diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 6839e7b..e8f3b10 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -1127,6 +1127,10 @@ rna_max = FloatProperty(
         precision=3,
         )
 
+rna_use_soft_limits = BoolProperty(
+        name="Use Soft Limits",
+        )
+
 
 class WM_OT_properties_edit(Operator):
     bl_idname = "wm.properties_edit"
@@ -1139,10 +1143,21 @@ class WM_OT_properties_edit(Operator):
     value = rna_value
     min = rna_min
     max = rna_max
+    use_soft_limits = rna_use_soft_limits
+    soft_min = rna_min
+    soft_max = rna_max
     description = StringProperty(
             name="Tooltip",
             )
 
+    def _cmp_props_get(self):
+        # Changing these properties will refresh the UI
+        return {
+            "use_soft_limits": self.use_soft_limits,
+            "soft_range": (self.soft_min, self.soft_max),
+            "hard_range": (self.min, self.max),
+            }
+
     def execute(self, context):
         from rna_prop_ui import (
                 rna_idprop_ui_prop_get,
@@ -1190,8 +1205,15 @@ class WM_OT_properties_edit(Operator):
         prop_ui = rna_idprop_ui_prop_get(item, prop)
 
         if prop_type in {float, int}:
-            prop_ui["soft_min"] = prop_ui["min"] = prop_type(self.min)
-            prop_ui["soft_max"] = prop_ui["max"] = prop_type(self.max)
+            prop_ui["min"] = prop_type(self.min)
+            prop_ui["max"] = prop_type(self.max)
+
+            if self.use_soft_limits:
+                prop_ui["soft_min"] = prop_type(self.soft_min)
+                prop_ui["soft_max"] = prop_type(self.soft_max)
+            else:
+                prop_ui["soft_min"] = prop_type(self.min)
+                prop_ui["soft_max"] = prop_type(self.max)
 
         prop_ui["description"] = self.description
 
@@ -1252,9 +1274,62 @@ class WM_OT_properties_edit(Operator):
             self.max = prop_ui.get("max", 1000000000)
             self.description = prop_ui.get("description", "")
 
+            self.soft_min = prop_ui.get("soft_min", self.min)
+            self.soft_max = prop_ui.get("soft_max", self.max)
+            self.use_soft_limits = (
+                    self.min != self.soft_min or
+                    self.max != self.soft_max)
+
+        # store for comparison
+        self._cmp_props = self._cmp_props_get()
+
         wm = context.window_manager
         return wm.invoke_props_dialog(self)
 
+    def check(self, context):
+        cmp_props = self._cmp_props_get()
+        changed = False
+        if self._cmp_props != cmp_props:
+            if cmp_props["use_soft_limits"]:
+                if cmp_props["soft_range"] != self._cmp_props["soft_range"]:
+                    self.min = min(self.min, self.soft_min)
+                    self.max = max(self.max, self.soft_max)
+                    changed = True
+                if cmp_props["hard_range"] != self._cmp_props["hard_range"]:
+                    self.soft_min = max(self.min, self.soft_min)
+                    self.soft_max = min(self.max, self.soft_max)
+                    changed = True
+            else:
+                if cmp_props["soft_range"] != cmp_props["hard_range"]:
+                    self.soft_min = self.min
+                    self.soft_max = self.max
+                    changed = True
+
+            changed |= (cmp_props["use_soft_limits"] != self._cmp_props["use_soft_limits"])
+
+            if changed:
+                cmp_props = self._cmp_props_get()
+
+            self._cmp_props = cmp_props
+
+        return changed
+
+    def draw(self, context):
+        layout = self.layout
+        layout.prop(self, "property")
+        layout.prop(self, "value")
+        row = layout.row(align=True)
+        row.prop(self, "min")
+        row.prop(self, "max")
+
+        layout.prop(self, "use_soft_limits")
+
+        row = layout.row(align=True)
+        row.enabled = self.use_soft_limits
+        row.prop(self, "soft_min", text="Soft Min")
+        row.prop(self, "soft_max", text="Soft Max")
+        layout.prop(self, "description")
+
 
 class WM_OT_properties_add(Operator):
     bl_idname = "wm.properties_add"




More information about the Bf-blender-cvs mailing list