[Bf-blender-cvs] [c22c2ff060a] master: Updated bpy.props getter/setter example

Sybren A. Stüvel noreply at git.blender.org
Wed Mar 14 11:43:28 CET 2018


Commit: c22c2ff060a27bcd565f84233d2bbfa968b00a3f
Author: Sybren A. Stüvel
Date:   Wed Mar 14 11:42:36 2018 +0100
Branches: master
https://developer.blender.org/rBc22c2ff060a27bcd565f84233d2bbfa968b00a3f

Updated bpy.props getter/setter example

- The common name in computer science are 'getters' and 'setters', so by
  adding these names to the documentation (while 'get' and 'set are still
  also mentioned) we improve findability. Having 'Getters/Setters' as a
  title also makes it clearer that this example is not just about
  getting or setting the property value.
- Added a little prefix to each printed value, so that print statement,
  expected output, and real output can be matched easier.

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

M	doc/python_api/examples/bpy.props.5.py

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

diff --git a/doc/python_api/examples/bpy.props.5.py b/doc/python_api/examples/bpy.props.5.py
index 87741cbab8a..a9e79fa0272 100644
--- a/doc/python_api/examples/bpy.props.5.py
+++ b/doc/python_api/examples/bpy.props.5.py
@@ -1,13 +1,12 @@
 """
-Get/Set Example
-+++++++++++++++
+Getter/Setter Example
++++++++++++++++++++++
 
-Get/Set functions can be used for boolean, int, float, string and enum properties.
+Getter/setter functions can be used for boolean, int, float, string and enum properties.
 If these callbacks are defined the property will not be stored in the ID properties
-automatically, instead the get/set functions will be called when the property is
-read or written from the API.
+automatically. Instead, the `get` and `set` functions will be called when the property
+is respectively read or written from the API.
 """
-
 import bpy
 
 
@@ -65,25 +64,24 @@ def set_enum(self, value):
 bpy.types.Scene.test_enum = bpy.props.EnumProperty(items=test_items, get=get_enum, set=set_enum)
 
 
-# Testing
-
+# Testing the properties:
 scene = bpy.context.scene
 
 scene.test_float = 12.34
-print(scene.test_float)
+print('test_float:', scene.test_float)
 
 scene.test_array = (True, False)
-print([x for x in scene.test_array])
+print('test_array:', tuple(scene.test_array))
 
 # scene.test_date = "blah"   # this would fail, property is read-only
-print(scene.test_date)
+print('test_date:', scene.test_date)
 
 scene.test_enum = 'BLUE'
-print(scene.test_enum)
-
-
-# >>> 12.34000015258789
-# >>> [True, False]
-# >>> 2013-01-05 16:33:52.135340
-# >>> setting value 3
-# >>> GREEN
+print('test_enum:', scene.test_enum)
+
+# The above outputs:
+# test_float: 12.34000015258789
+# test_array: (True, False)
+# test_date: 2018-03-14 11:36:53.158653
+# setting value 3
+# test_enum: GREEN



More information about the Bf-blender-cvs mailing list