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>2011-02-18 17:27:18 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-18 17:27:18 +0300
commit251d27110b943c67ceaf3ab1192a36ebd07eeb4b (patch)
tree41814fcec10384755cf0f0398241e679857f18f0 /doc
parentd9bca3d4919848f3ec43e2655b21b3e2f47c3e97 (diff)
examples for bpy.props
Diffstat (limited to 'doc')
-rw-r--r--doc/python_api/examples/bpy.props.1.py31
-rw-r--r--doc/python_api/examples/bpy.props.2.py27
-rw-r--r--doc/python_api/examples/bpy.props.3.py33
-rw-r--r--doc/python_api/examples/bpy.props.py18
-rw-r--r--doc/python_api/examples/bpy.types.Operator.3.py6
-rw-r--r--doc/python_api/sphinx_doc_gen.py4
6 files changed, 114 insertions, 5 deletions
diff --git a/doc/python_api/examples/bpy.props.1.py b/doc/python_api/examples/bpy.props.1.py
new file mode 100644
index 00000000000..51534628930
--- /dev/null
+++ b/doc/python_api/examples/bpy.props.1.py
@@ -0,0 +1,31 @@
+"""
+Operator Example
+++++++++++++++++
+
+A common use of custom properties is for python based :class:`Operator` classes.
+"""
+
+import bpy
+
+
+class DialogOperator(bpy.types.Operator):
+ bl_idname = "object.dialog_operator"
+ bl_label = "Property Example"
+
+ 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):
+ print("Dialog Runs")
+ return {'FINISHED'}
+
+ def invoke(self, context, event):
+ wm = context.window_manager
+ return wm.invoke_props_dialog(self)
+
+
+bpy.utils.register_class(DialogOperator)
+
+# test call
+bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
diff --git a/doc/python_api/examples/bpy.props.2.py b/doc/python_api/examples/bpy.props.2.py
new file mode 100644
index 00000000000..e27e6227ba3
--- /dev/null
+++ b/doc/python_api/examples/bpy.props.2.py
@@ -0,0 +1,27 @@
+"""
+PropertyGroup Example
++++++++++++++++++++++
+
+PropertyGroups can be used for collecting custom settings into one value
+to avoid many indervidual settings mixed in together.
+"""
+
+import bpy
+
+
+class MaterialSettings(bpy.types.PropertyGroup):
+ 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)
+
+# test the new settings work
+material = bpy.data.materials[0]
+
+material.my_settings.val_int = 5
+material.my_settings.val_float = 3.0
+material.my_settings.my_string = "Foo"
diff --git a/doc/python_api/examples/bpy.props.3.py b/doc/python_api/examples/bpy.props.3.py
new file mode 100644
index 00000000000..e4964c366cf
--- /dev/null
+++ b/doc/python_api/examples/bpy.props.3.py
@@ -0,0 +1,33 @@
+"""
+Collection Example
+++++++++++++++++++
+
+Custom properties can be added to any subclass of an :class:`ID`,
+:class:`Bone` and :class:`PoseBone`.
+"""
+
+import bpy
+
+# 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)
+
+bpy.utils.register_class(SceneSettingItem)
+
+bpy.types.Scene.my_settings = \
+ bpy.props.CollectionProperty(type=SceneSettingItem)
+
+# Assume an armature object selected
+print("Adding 3 values!")
+
+my_item = bpy.context.scene.my_settings.add()
+my_item.name = "Spam"
+my_item.value = 1000
+
+my_item = bpy.context.scene.my_settings.add()
+my_item.name = "Eggs"
+my_item.value = 30
+
+for my_item in bpy.context.scene.my_settings:
+ print(my_item.name, my_item.value)
diff --git a/doc/python_api/examples/bpy.props.py b/doc/python_api/examples/bpy.props.py
new file mode 100644
index 00000000000..f6bc55d6824
--- /dev/null
+++ b/doc/python_api/examples/bpy.props.py
@@ -0,0 +1,18 @@
+"""
+Assigning to Existing Classes
++++++++++++++++++++++++++++++
+
+Custom properties can be added to any subclass of an :class:`ID`,
+:class:`Bone` and :class:`PoseBone`.
+
+These properties can be animated, accessed by the user interface and python
+like blenders existing properties.
+"""
+
+import bpy
+
+# Assign a custom property to an existing type.
+bpy.types.Material.custom_float = bpy.props.FloatProperty(name="Test Prob")
+
+# Test the property is there.
+bpy.data.materials[0].custom_float = 5.0
diff --git a/doc/python_api/examples/bpy.types.Operator.3.py b/doc/python_api/examples/bpy.types.Operator.3.py
index 887657bec7a..7fdccd81379 100644
--- a/doc/python_api/examples/bpy.types.Operator.3.py
+++ b/doc/python_api/examples/bpy.types.Operator.3.py
@@ -7,8 +7,8 @@ import bpy
class DialogOperator(bpy.types.Operator):
- bl_idname = "object.modal_operator"
- bl_label = "Simple Modal 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")
@@ -28,4 +28,4 @@ class DialogOperator(bpy.types.Operator):
bpy.utils.register_class(DialogOperator)
# test call
-bpy.ops.object.modal_operator('INVOKE_DEFAULT')
+bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py
index 5f9505a7ea3..4112e24d6e0 100644
--- a/doc/python_api/sphinx_doc_gen.py
+++ b/doc/python_api/sphinx_doc_gen.py
@@ -61,7 +61,7 @@ else:
"bpy.app",
"bpy.path",
"bpy.data",
- # "bpy.props",
+ #"bpy.props",
"bpy.utils",
"bpy.context",
# "bpy.types", # supports filtering
@@ -74,7 +74,7 @@ else:
"mathutils.geometry",
)
- FILTER_BPY_TYPES = ("PropertyGroup", "Panel", "Menu", "Operator") # allow
+ FILTER_BPY_TYPES = ("PropertyGroup", "Panel", "Menu", "Operator", "RenderEngine") # allow
FILTER_BPY_OPS = ("import.scene", ) # allow
# for quick rebuilds