Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2018-03-14 13:42:36 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2018-03-14 13:42:36 +0300
commitc22c2ff060a27bcd565f84233d2bbfa968b00a3f (patch)
treebb925fe702361b04a1509deeef6605fcf4be097f /doc
parentb76471c1f9f42fda7187194e857b01549c0131d5 (diff)
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.
Diffstat (limited to 'doc')
-rw-r--r--doc/python_api/examples/bpy.props.5.py36
1 files changed, 17 insertions, 19 deletions
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