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:
authorCampbell Barton <ideasman42@gmail.com>2019-03-21 16:07:06 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-03-21 16:07:06 +0300
commitdd1132416e5bcbad5d4f80631b1a9f3152a514ee (patch)
treec3ccf1d18376d42a818dc22c962bcdefc370f0f4 /doc
parentbd1299f6a4398e06db00d77f9ea7382f9e7bcf53 (diff)
Docs: update examples for 2.8x
Use fields for properties
Diffstat (limited to 'doc')
-rw-r--r--doc/python_api/examples/bpy.props.1.py19
-rw-r--r--doc/python_api/examples/bpy.props.2.py9
-rw-r--r--doc/python_api/examples/bpy.props.3.py11
-rw-r--r--doc/python_api/examples/bpy.props.py2
-rw-r--r--doc/python_api/examples/bpy.types.AddonPreferences.1.py6
-rw-r--r--doc/python_api/examples/bpy.types.Operator.1.py4
-rw-r--r--doc/python_api/examples/bpy.types.Operator.2.py2
-rw-r--r--doc/python_api/examples/bpy.types.Operator.3.py12
-rw-r--r--doc/python_api/examples/bpy.types.Operator.4.py8
-rw-r--r--doc/python_api/examples/bpy.types.Operator.6.py2
-rw-r--r--doc/python_api/examples/bpy.types.PropertyGroup.py4
-rw-r--r--doc/python_api/examples/bpy.types.UIList.2.py42
-rw-r--r--doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py29
13 files changed, 90 insertions, 60 deletions
diff --git a/doc/python_api/examples/bpy.props.1.py b/doc/python_api/examples/bpy.props.1.py
index dd3a3ebc432..e442faf245b 100644
--- a/doc/python_api/examples/bpy.props.1.py
+++ b/doc/python_api/examples/bpy.props.1.py
@@ -15,13 +15,15 @@ class OBJECT_OT_property_example(bpy.types.Operator):
bl_label = "Property Example"
bl_options = {'REGISTER', 'UNDO'}
- my_float = bpy.props.FloatProperty(name="Some Floating Point")
- my_bool = bpy.props.BoolProperty(name="Toggle Option")
- my_string = bpy.props.StringProperty(name="String Value")
+ my_float: bpy.props.FloatProperty(name="Some Floating Point")
+ my_bool: bpy.props.BoolProperty(name="Toggle Option")
+ my_string: bpy.props.StringProperty(name="String Value")
def execute(self, context):
- self.report({'INFO'}, 'F: %.2f B: %s S: %r' %
- (self.my_float, self.my_bool, self.my_string))
+ self.report(
+ {'INFO'}, 'F: %.2f B: %s S: %r' %
+ (self.my_float, self.my_bool, self.my_string)
+ )
print('My float:', self.my_float)
print('My bool:', self.my_bool)
print('My string:', self.my_string)
@@ -53,5 +55,8 @@ bpy.utils.register_class(OBJECT_OT_property_example)
bpy.utils.register_class(OBJECT_PT_property_example)
# Demo call. Be sure to also test in the 3D Viewport.
-bpy.ops.object.property_example(my_float=47, my_bool=True,
- my_string="Shouldn't that be 327?")
+bpy.ops.object.property_example(
+ my_float=47,
+ my_bool=True,
+ my_string="Shouldn't that be 327?",
+)
diff --git a/doc/python_api/examples/bpy.props.2.py b/doc/python_api/examples/bpy.props.2.py
index aeb3bab65b4..9cfaefab4a1 100644
--- a/doc/python_api/examples/bpy.props.2.py
+++ b/doc/python_api/examples/bpy.props.2.py
@@ -10,15 +10,14 @@ import bpy
class MaterialSettings(bpy.types.PropertyGroup):
- my_int = bpy.props.IntProperty()
- my_float = bpy.props.FloatProperty()
- my_string = bpy.props.StringProperty()
+ my_int: bpy.props.IntProperty()
+ my_float: bpy.props.FloatProperty()
+ my_string: bpy.props.StringProperty()
bpy.utils.register_class(MaterialSettings)
-bpy.types.Material.my_settings = \
- bpy.props.PointerProperty(type=MaterialSettings)
+bpy.types.Material.my_settings = bpy.props.PointerProperty(type=MaterialSettings)
# test the new settings work
material = bpy.data.materials[0]
diff --git a/doc/python_api/examples/bpy.props.3.py b/doc/python_api/examples/bpy.props.3.py
index 340618e5ca4..b8e0045fe58 100644
--- a/doc/python_api/examples/bpy.props.3.py
+++ b/doc/python_api/examples/bpy.props.3.py
@@ -9,18 +9,17 @@ Custom properties can be added to any subclass of an :class:`ID`,
import bpy
-# Assign a collection
+# Assign a collection.
class SceneSettingItem(bpy.types.PropertyGroup):
- name = bpy.props.StringProperty(name="Test Prop", default="Unknown")
- value = bpy.props.IntProperty(name="Test Prop", default=22)
+ name: bpy.props.StringProperty(name="Test Property", default="Unknown")
+ value: bpy.props.IntProperty(name="Test Property", default=22)
bpy.utils.register_class(SceneSettingItem)
-bpy.types.Scene.my_settings = \
- bpy.props.CollectionProperty(type=SceneSettingItem)
+bpy.types.Scene.my_settings = bpy.props.CollectionProperty(type=SceneSettingItem)
-# Assume an armature object selected
+# Assume an armature object selected.
print("Adding 2 values!")
my_item = bpy.context.scene.my_settings.add()
diff --git a/doc/python_api/examples/bpy.props.py b/doc/python_api/examples/bpy.props.py
index c199bd9b83a..d19b57b13a5 100644
--- a/doc/python_api/examples/bpy.props.py
+++ b/doc/python_api/examples/bpy.props.py
@@ -12,7 +12,7 @@ like Blender's existing properties.
import bpy
# Assign a custom property to an existing type.
-bpy.types.Material.custom_float = bpy.props.FloatProperty(name="Test Prob")
+bpy.types.Material.custom_float = bpy.props.FloatProperty(name="Test Property")
# Test the property is there.
bpy.data.materials[0].custom_float = 5.0
diff --git a/doc/python_api/examples/bpy.types.AddonPreferences.1.py b/doc/python_api/examples/bpy.types.AddonPreferences.1.py
index fdc073b3e2f..95285e8ac0c 100644
--- a/doc/python_api/examples/bpy.types.AddonPreferences.1.py
+++ b/doc/python_api/examples/bpy.types.AddonPreferences.1.py
@@ -22,15 +22,15 @@ class ExampleAddonPreferences(AddonPreferences):
# when defining this in a submodule of a python package.
bl_idname = __name__
- filepath = StringProperty(
+ filepath: StringProperty(
name="Example File Path",
subtype='FILE_PATH',
)
- number = IntProperty(
+ number: IntProperty(
name="Example Number",
default=4,
)
- boolean = BoolProperty(
+ boolean: BoolProperty(
name="Example Boolean",
default=False,
)
diff --git a/doc/python_api/examples/bpy.types.Operator.1.py b/doc/python_api/examples/bpy.types.Operator.1.py
index f09ae969001..728d36f24b9 100644
--- a/doc/python_api/examples/bpy.types.Operator.1.py
+++ b/doc/python_api/examples/bpy.types.Operator.1.py
@@ -28,8 +28,8 @@ class SimpleMouseOperator(bpy.types.Operator):
bl_idname = "wm.mouse_position"
bl_label = "Invoke Mouse Operator"
- x = bpy.props.IntProperty()
- y = bpy.props.IntProperty()
+ x: bpy.props.IntProperty()
+ y: bpy.props.IntProperty()
def execute(self, context):
# rather than printing, use the report function,
diff --git a/doc/python_api/examples/bpy.types.Operator.2.py b/doc/python_api/examples/bpy.types.Operator.2.py
index 901bd7b21f8..5ba09c7e380 100644
--- a/doc/python_api/examples/bpy.types.Operator.2.py
+++ b/doc/python_api/examples/bpy.types.Operator.2.py
@@ -21,7 +21,7 @@ class ExportSomeData(bpy.types.Operator):
bl_idname = "export.some_data"
bl_label = "Export Some Data"
- filepath = bpy.props.StringProperty(subtype="FILE_PATH")
+ filepath: bpy.props.StringProperty(subtype="FILE_PATH")
@classmethod
def poll(cls, context):
diff --git a/doc/python_api/examples/bpy.types.Operator.3.py b/doc/python_api/examples/bpy.types.Operator.3.py
index d59c816319d..ef8bce3d8a9 100644
--- a/doc/python_api/examples/bpy.types.Operator.3.py
+++ b/doc/python_api/examples/bpy.types.Operator.3.py
@@ -11,13 +11,15 @@ class DialogOperator(bpy.types.Operator):
bl_idname = "object.dialog_operator"
bl_label = "Simple Dialog Operator"
- my_float = bpy.props.FloatProperty(name="Some Floating Point")
- my_bool = bpy.props.BoolProperty(name="Toggle Option")
- my_string = bpy.props.StringProperty(name="String Value")
+ my_float: bpy.props.FloatProperty(name="Some Floating Point")
+ my_bool: bpy.props.BoolProperty(name="Toggle Option")
+ my_string: bpy.props.StringProperty(name="String Value")
def execute(self, context):
- message = "Popup Values: %f, %d, '%s'" % \
+ message = (
+ "Popup Values: %f, %d, '%s'" %
(self.my_float, self.my_bool, self.my_string)
+ )
self.report({'INFO'}, message)
return {'FINISHED'}
@@ -28,5 +30,5 @@ class DialogOperator(bpy.types.Operator):
bpy.utils.register_class(DialogOperator)
-# test call
+# Test call.
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
diff --git a/doc/python_api/examples/bpy.types.Operator.4.py b/doc/python_api/examples/bpy.types.Operator.4.py
index 90d1157343d..6b74a96eb2b 100644
--- a/doc/python_api/examples/bpy.types.Operator.4.py
+++ b/doc/python_api/examples/bpy.types.Operator.4.py
@@ -16,11 +16,11 @@ class CustomDrawOperator(bpy.types.Operator):
bl_idname = "object.custom_draw"
bl_label = "Simple Modal Operator"
- filepath = bpy.props.StringProperty(subtype="FILE_PATH")
+ filepath: bpy.props.StringProperty(subtype="FILE_PATH")
- my_float = bpy.props.FloatProperty(name="Float")
- my_bool = bpy.props.BoolProperty(name="Toggle Option")
- my_string = bpy.props.StringProperty(name="String Value")
+ my_float: bpy.props.FloatProperty(name="Float")
+ my_bool: bpy.props.BoolProperty(name="Toggle Option")
+ my_string: bpy.props.StringProperty(name="String Value")
def execute(self, context):
print("Test", self)
diff --git a/doc/python_api/examples/bpy.types.Operator.6.py b/doc/python_api/examples/bpy.types.Operator.6.py
index d32a7d5fd4a..ff14bfa7197 100644
--- a/doc/python_api/examples/bpy.types.Operator.6.py
+++ b/doc/python_api/examples/bpy.types.Operator.6.py
@@ -14,7 +14,7 @@ class SearchEnumOperator(bpy.types.Operator):
bl_label = "Search Enum Operator"
bl_property = "my_search"
- my_search = EnumProperty(
+ my_search: EnumProperty(
name="My Search",
items=(
('FOO', "Foo", ""),
diff --git a/doc/python_api/examples/bpy.types.PropertyGroup.py b/doc/python_api/examples/bpy.types.PropertyGroup.py
index 974142a79b2..57cbde2e8d6 100644
--- a/doc/python_api/examples/bpy.types.PropertyGroup.py
+++ b/doc/python_api/examples/bpy.types.PropertyGroup.py
@@ -28,8 +28,8 @@ import bpy
class MyPropertyGroup(bpy.types.PropertyGroup):
- custom_1 = bpy.props.FloatProperty(name="My Float")
- custom_2 = bpy.props.IntProperty(name="My Int")
+ custom_1: bpy.props.FloatProperty(name="My Float")
+ custom_2: bpy.props.IntProperty(name="My Int")
bpy.utils.register_class(MyPropertyGroup)
diff --git a/doc/python_api/examples/bpy.types.UIList.2.py b/doc/python_api/examples/bpy.types.UIList.2.py
index 81bbec11d9a..582e89af75a 100644
--- a/doc/python_api/examples/bpy.types.UIList.2.py
+++ b/doc/python_api/examples/bpy.types.UIList.2.py
@@ -15,12 +15,24 @@ class MESH_UL_vgroups_slow(bpy.types.UIList):
VGROUP_EMPTY = 1 << 0
# Custom properties, saved with .blend file.
- use_filter_empty = bpy.props.BoolProperty(name="Filter Empty", default=False, options=set(),
- description="Whether to filter empty vertex groups")
- use_filter_empty_reverse = bpy.props.BoolProperty(name="Reverse Empty", default=False, options=set(),
- description="Reverse empty filtering")
- use_filter_name_reverse = bpy.props.BoolProperty(name="Reverse Name", default=False, options=set(),
- description="Reverse name filtering")
+ use_filter_empty: bpy.props.BoolProperty(
+ name="Filter Empty",
+ default=False,
+ options=set(),
+ description="Whether to filter empty vertex groups",
+ )
+ use_filter_empty_reverse: bpy.props.BoolProperty(
+ name="Reverse Empty",
+ default=False,
+ options=set(),
+ description="Reverse empty filtering",
+ )
+ use_filter_name_reverse: bpy.props.BoolProperty(
+ name="Reverse Name",
+ default=False,
+ options=set(),
+ description="Reverse name filtering",
+ )
# This allows us to have mutually exclusive options, which are also all disable-able!
def _gen_order_update(name1, name2):
@@ -28,12 +40,18 @@ class MESH_UL_vgroups_slow(bpy.types.UIList):
if (getattr(self, name1)):
setattr(self, name2, False)
return _u
- use_order_name = bpy.props.BoolProperty(name="Name", default=False, options=set(),
- description="Sort groups by their name (case-insensitive)",
- update=_gen_order_update("use_order_name", "use_order_importance"))
- use_order_importance = bpy.props.BoolProperty(name="Importance", default=False, options=set(),
- description="Sort groups by their average weight in the mesh",
- update=_gen_order_update("use_order_importance", "use_order_name"))
+ use_order_name: bpy.props.BoolProperty(
+ name="Name", default=False, options=set(),
+ description="Sort groups by their name (case-insensitive)",
+ update=_gen_order_update("use_order_name", "use_order_importance"),
+ )
+ use_order_importance: bpy.props.BoolProperty(
+ name="Importance",
+ default=False,
+ options=set(),
+ description="Sort groups by their average weight in the mesh",
+ update=_gen_order_update("use_order_importance", "use_order_name"),
+ )
# Usual draw item function.
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
diff --git a/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py b/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py
index d46ffcc8373..27706c06688 100644
--- a/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py
+++ b/doc/python_api/examples/bpy.types.bpy_struct.keyframe_insert.1.py
@@ -5,25 +5,32 @@ than the bone.
"""
import bpy
-from bpy.props import PointerProperty
+from bpy.props import (
+ FloatProperty,
+ PointerProperty,
+)
-# define a nested property
+# Define a nested property.
class MyPropGroup(bpy.types.PropertyGroup):
- nested = bpy.props.FloatProperty(name="Nested", default=0.0)
+ nested: FloatProperty(name="Nested", default=0.0)
-# register it so its available for all bones
+# Register it so its available for all bones.
bpy.utils.register_class(MyPropGroup)
-bpy.types.Bone.my_prop = PointerProperty(type=MyPropGroup,
- name="MyProp")
+bpy.types.Bone.my_prop = PointerProperty(
+ type=MyPropGroup,
+ name="MyProp",
+)
-# get a bone
+# Get a bone.
obj = bpy.data.objects["Armature"]
arm = obj.data
-# set the keyframe at frame 1
+# Set the keyframe at frame 1.
arm.bones["Bone"].my_prop_group.nested = 10
-arm.keyframe_insert(data_path='bones["Bone"].my_prop.nested',
- frame=1,
- group="Nested Group")
+arm.keyframe_insert(
+ data_path='bones["Bone"].my_prop.nested',
+ frame=1,
+ group="Nested Group",
+)