From c22c2ff060a27bcd565f84233d2bbfa968b00a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 14 Mar 2018 11:42:36 +0100 Subject: 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. --- doc/python_api/examples/bpy.props.5.py | 36 ++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'doc') 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 -- cgit v1.2.3