From 09aa799e5331a9da666f8a6325b038a866b1f35d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 11 Jul 2018 22:18:09 +0200 Subject: PyAPI: Use annotations for RNA definitions - Logical use of fields since they define type information. - Avoids using ordered-dict metaclass. Properties using regular assignments will print a warning and load, however the order is undefined. --- release/scripts/templates_py/addon_add_object.py | 2 +- release/scripts/templates_py/custom_nodes.py | 13 +++++++++---- release/scripts/templates_py/manipulator_operator.py | 4 ++-- release/scripts/templates_py/operator_file_export.py | 6 +++--- release/scripts/templates_py/operator_file_import.py | 6 +++--- release/scripts/templates_py/operator_mesh_add.py | 14 +++++++------- release/scripts/templates_py/operator_modal.py | 4 ++-- release/scripts/templates_py/operator_modal_view3d.py | 2 +- release/scripts/templates_py/ui_list.py | 6 ++++-- 9 files changed, 32 insertions(+), 25 deletions(-) (limited to 'release/scripts/templates_py') diff --git a/release/scripts/templates_py/addon_add_object.py b/release/scripts/templates_py/addon_add_object.py index b74c0f8ee25..d26f3d351bf 100644 --- a/release/scripts/templates_py/addon_add_object.py +++ b/release/scripts/templates_py/addon_add_object.py @@ -45,7 +45,7 @@ class OBJECT_OT_add_object(Operator, AddObjectHelper): bl_label = "Add Mesh Object" bl_options = {'REGISTER', 'UNDO'} - scale = FloatVectorProperty( + scale: FloatVectorProperty( name="scale", default=(1.0, 1.0, 1.0), subtype='TRANSLATION', diff --git a/release/scripts/templates_py/custom_nodes.py b/release/scripts/templates_py/custom_nodes.py index 23d8ee55e72..7e4e89dafeb 100644 --- a/release/scripts/templates_py/custom_nodes.py +++ b/release/scripts/templates_py/custom_nodes.py @@ -30,10 +30,15 @@ class MyCustomSocket(NodeSocket): ('DOWN', "Down", "Where your feet are"), ('UP', "Up", "Where your head should be"), ('LEFT', "Left", "Not right"), - ('RIGHT', "Right", "Not left") + ('RIGHT', "Right", "Not left"), ) - my_enum_prop = bpy.props.EnumProperty(name="Direction", description="Just an example", items=my_items, default='UP') + my_enum_prop: bpy.props.EnumProperty( + name="Direction", + description="Just an example", + items=my_items, + default='UP', + ) # Optional function for drawing the socket input value def draw(self, context, layout, node, text): @@ -71,8 +76,8 @@ class MyCustomNode(Node, MyCustomTreeNode): # These work just like custom properties in ID data blocks # Extensive information can be found under # http://wiki.blender.org/index.php/Doc:2.6/Manual/Extensions/Python/Properties - my_string_prop = bpy.props.StringProperty() - my_float_prop = bpy.props.FloatProperty(default=3.1415926) + my_string_prop: bpy.props.StringProperty() + my_float_prop: bpy.props.FloatProperty(default=3.1415926) # === Optional Functions === # Initialization function, called when a new node is created. diff --git a/release/scripts/templates_py/manipulator_operator.py b/release/scripts/templates_py/manipulator_operator.py index 35e1c5b4fd1..61796489a95 100644 --- a/release/scripts/templates_py/manipulator_operator.py +++ b/release/scripts/templates_py/manipulator_operator.py @@ -39,11 +39,11 @@ class SelectSideOfPlane(Operator): bl_label = "Select Side of Plane" bl_options = {'REGISTER', 'UNDO'} - plane_co = FloatVectorProperty( + plane_co: FloatVectorProperty( size=3, default=(0, 0, 0), ) - plane_no = FloatVectorProperty( + plane_no: FloatVectorProperty( size=3, default=(0, 0, 1), ) diff --git a/release/scripts/templates_py/operator_file_export.py b/release/scripts/templates_py/operator_file_export.py index 8a1eb4ae54c..4ea817d3507 100644 --- a/release/scripts/templates_py/operator_file_export.py +++ b/release/scripts/templates_py/operator_file_export.py @@ -25,7 +25,7 @@ class ExportSomeData(Operator, ExportHelper): # ExportHelper mixin class uses this filename_ext = ".txt" - filter_glob = StringProperty( + filter_glob: StringProperty( default="*.txt", options={'HIDDEN'}, maxlen=255, # Max internal buffer length, longer would be clamped. @@ -33,13 +33,13 @@ class ExportSomeData(Operator, ExportHelper): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - use_setting = BoolProperty( + use_setting: BoolProperty( name="Example Boolean", description="Example Tooltip", default=True, ) - type = EnumProperty( + type: EnumProperty( name="Example Enum", description="Choose between two items", items=( diff --git a/release/scripts/templates_py/operator_file_import.py b/release/scripts/templates_py/operator_file_import.py index 9856b6a9040..b932b008c49 100644 --- a/release/scripts/templates_py/operator_file_import.py +++ b/release/scripts/templates_py/operator_file_import.py @@ -28,7 +28,7 @@ class ImportSomeData(Operator, ImportHelper): # ImportHelper mixin class uses this filename_ext = ".txt" - filter_glob = StringProperty( + filter_glob: StringProperty( default="*.txt", options={'HIDDEN'}, maxlen=255, # Max internal buffer length, longer would be clamped. @@ -36,13 +36,13 @@ class ImportSomeData(Operator, ImportHelper): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. - use_setting = BoolProperty( + use_setting: BoolProperty( name="Example Boolean", description="Example Tooltip", default=True, ) - type = EnumProperty( + type: EnumProperty( name="Example Enum", description="Choose between two items", items=( diff --git a/release/scripts/templates_py/operator_mesh_add.py b/release/scripts/templates_py/operator_mesh_add.py index 407956a0fda..6b39ef7bbba 100644 --- a/release/scripts/templates_py/operator_mesh_add.py +++ b/release/scripts/templates_py/operator_mesh_add.py @@ -49,25 +49,25 @@ class AddBox(bpy.types.Operator): bl_label = "Add Box" bl_options = {'REGISTER', 'UNDO'} - width = FloatProperty( + width: FloatProperty( name="Width", description="Box Width", min=0.01, max=100.0, default=1.0, ) - height = FloatProperty( + height: FloatProperty( name="Height", description="Box Height", min=0.01, max=100.0, default=1.0, ) - depth = FloatProperty( + depth: FloatProperty( name="Depth", description="Box Depth", min=0.01, max=100.0, default=1.0, ) - layers = BoolVectorProperty( + layers: BoolVectorProperty( name="Layers", description="Object Layers", size=20, @@ -75,15 +75,15 @@ class AddBox(bpy.types.Operator): ) # generic transform props - view_align = BoolProperty( + view_align: BoolProperty( name="Align to View", default=False, ) - location = FloatVectorProperty( + location: FloatVectorProperty( name="Location", subtype='TRANSLATION', ) - rotation = FloatVectorProperty( + rotation: FloatVectorProperty( name="Rotation", subtype='EULER', ) diff --git a/release/scripts/templates_py/operator_modal.py b/release/scripts/templates_py/operator_modal.py index 88e5ee80590..c242e3b67b9 100644 --- a/release/scripts/templates_py/operator_modal.py +++ b/release/scripts/templates_py/operator_modal.py @@ -7,8 +7,8 @@ class ModalOperator(bpy.types.Operator): bl_idname = "object.modal_operator" bl_label = "Simple Modal Operator" - first_mouse_x = IntProperty() - first_value = FloatProperty() + first_mouse_x: IntProperty() + first_value: FloatProperty() def modal(self, context, event): if event.type == 'MOUSEMOVE': diff --git a/release/scripts/templates_py/operator_modal_view3d.py b/release/scripts/templates_py/operator_modal_view3d.py index 65bab3489b4..9d371446829 100644 --- a/release/scripts/templates_py/operator_modal_view3d.py +++ b/release/scripts/templates_py/operator_modal_view3d.py @@ -8,7 +8,7 @@ class ViewOperator(bpy.types.Operator): bl_idname = "view3d.modal_operator" bl_label = "Simple View Operator" - offset = FloatVectorProperty( + offset: FloatVectorProperty( name="Offset", size=3, ) diff --git a/release/scripts/templates_py/ui_list.py b/release/scripts/templates_py/ui_list.py index 92e1b29d2ae..f6b82356a78 100644 --- a/release/scripts/templates_py/ui_list.py +++ b/release/scripts/templates_py/ui_list.py @@ -7,8 +7,10 @@ class MESH_UL_mylist(bpy.types.UIList): # E.g. VGROUP_EMPTY = 1 << 0 # Custom properties, saved with .blend file. E.g. - # use_filter_empty = bpy.props.BoolProperty(name="Filter Empty", default=False, options=set(), - # description="Whether to filter empty vertex groups") + # use_filter_empty: bpy.props.BoolProperty( + # name="Filter Empty", default=False, options=set(), + # description="Whether to filter empty vertex groups", + # ) # Called for each drawn item. def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag): -- cgit v1.2.3