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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-09-07 07:49:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-09-07 07:53:06 +0300
commit1601089ece8a1f62c4c8d965fbef8073ccf0e0e5 (patch)
treef3a84201ed715d5d20d8a7888ea42fcc7af898cb /release/scripts
parentf1021ee9290ecba9b799a0abc93be50e15209477 (diff)
parent3f8aaec6bd98cbdf6d42591027f1d905f8b6a8f9 (diff)
Merge branch 'master' into blender2.8
This discards node drawing changes which need to be written as shaders.
Diffstat (limited to 'release/scripts')
-rw-r--r--release/scripts/modules/nodeitems_utils.py6
-rw-r--r--release/scripts/templates_py/custom_nodes.py81
2 files changed, 47 insertions, 40 deletions
diff --git a/release/scripts/modules/nodeitems_utils.py b/release/scripts/modules/nodeitems_utils.py
index 904062c36cd..4be6e340760 100644
--- a/release/scripts/modules/nodeitems_utils.py
+++ b/release/scripts/modules/nodeitems_utils.py
@@ -59,7 +59,8 @@ class NodeItem:
return self._label
else:
# if no custom label is defined, fall back to the node type UI name
- return getattr(bpy.types, self.nodetype).bl_rna.name
+ cls = next(cls for cls in bpy.types.Node.__subclasses__() if cls.bl_rna.identifier == self.nodetype)
+ return cls.bl_rna.name
@property
def translation_context(self):
@@ -67,7 +68,8 @@ class NodeItem:
return bpy.app.translations.contexts.default
else:
# if no custom label is defined, fall back to the node type UI name
- return getattr(bpy.types, self.nodetype).bl_rna.translation_context
+ cls = next(cls for cls in bpy.types.Node.__subclasses__() if cls.bl_rna.identifier == self.nodetype)
+ return cls.bl_rna.translation_context
# NB: is a staticmethod because called with an explicit self argument
# NodeItemCustom sets this as a variable attribute in __init__
diff --git a/release/scripts/templates_py/custom_nodes.py b/release/scripts/templates_py/custom_nodes.py
index 32c61abace7..8ca748c1d66 100644
--- a/release/scripts/templates_py/custom_nodes.py
+++ b/release/scripts/templates_py/custom_nodes.py
@@ -11,7 +11,7 @@ class MyCustomTree(NodeTree):
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'CustomTreeType'
# Label for nice name display
- bl_label = 'Custom Node Tree'
+ bl_label = "Custom Node Tree"
# Icon identifier
bl_icon = 'NODETREE'
@@ -23,24 +23,24 @@ class MyCustomSocket(NodeSocket):
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'CustomSocketType'
# Label for nice name display
- bl_label = 'Custom Node Socket'
+ bl_label = "Custom Node Socket"
# Enum items list
- my_items = [
- ("DOWN", "Down", "Where your feet are"),
- ("UP", "Up", "Where your head should be"),
- ("LEFT", "Left", "Not right"),
- ("RIGHT", "Right", "Not left")
- ]
+ my_items = (
+ ('DOWN', "Down", "Where your feet are"),
+ ('UP', "Up", "Where your head should be"),
+ ('LEFT', "Left", "Not right"),
+ ('RIGHT', "Right", "Not left")
+ )
- myEnumProperty = 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):
if self.is_output or self.is_linked:
layout.label(text)
else:
- layout.prop(self, "myEnumProperty", text=text)
+ layout.prop(self, "my_enum_prop", text=text)
# Socket color
def draw_color(self, context, node):
@@ -63,7 +63,7 @@ class MyCustomNode(Node, MyCustomTreeNode):
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'CustomNodeType'
# Label for nice name display
- bl_label = 'Custom Node'
+ bl_label = "Custom Node"
# Icon identifier
bl_icon = 'SOUND'
@@ -71,8 +71,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
- myStringProperty = bpy.props.StringProperty()
- myFloatProperty = 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.
@@ -99,14 +99,14 @@ class MyCustomNode(Node, MyCustomTreeNode):
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.label("Node settings")
- layout.prop(self, "myFloatProperty")
+ layout.prop(self, "my_float_prop")
# Detail buttons in the sidebar.
# If this function is not defined, the draw_buttons function is used instead
def draw_buttons_ext(self, context, layout):
- layout.prop(self, "myFloatProperty")
- # myStringProperty button will only be visible in the sidebar
- layout.prop(self, "myStringProperty")
+ layout.prop(self, "my_float_prop")
+ # my_string_prop button will only be visible in the sidebar
+ layout.prop(self, "my_string_prop")
# Optional: custom label
# Explicit user label overrides this, but here we can define a label dynamically
@@ -122,7 +122,6 @@ class MyCustomNode(Node, MyCustomTreeNode):
import nodeitems_utils
from nodeitems_utils import NodeCategory, NodeItem
-
# our own base class with an appropriate poll function,
# so the categories only show up in our own tree type
class MyNodeCategory(NodeCategory):
@@ -130,44 +129,50 @@ class MyNodeCategory(NodeCategory):
def poll(cls, context):
return context.space_data.tree_type == 'CustomTreeType'
+
# all categories in a list
node_categories = [
# identifier, label, items list
- MyNodeCategory("SOMENODES", "Some Nodes", items=[
+ MyNodeCategory('SOMENODES', "Some Nodes", items=[
# our basic node
NodeItem("CustomNodeType"),
- ]),
- MyNodeCategory("OTHERNODES", "Other Nodes", items=[
+ ]),
+ MyNodeCategory('OTHERNODES', "Other Nodes", items=[
# the node item can have additional settings,
# which are applied to new nodes
# NB: settings values are stored as string expressions,
# for this reason they should be converted to strings using repr()
NodeItem("CustomNodeType", label="Node A", settings={
- "myStringProperty": repr("Lorem ipsum dolor sit amet"),
- "myFloatProperty": repr(1.0),
- }),
+ "my_string_prop": repr("Lorem ipsum dolor sit amet"),
+ "my_float_prop": repr(1.0),
+ }),
NodeItem("CustomNodeType", label="Node B", settings={
- "myStringProperty": repr("consectetur adipisicing elit"),
- "myFloatProperty": repr(2.0),
- }),
- ]),
- ]
-
+ "my_string_prop": repr("consectetur adipisicing elit"),
+ "my_float_prop": repr(2.0),
+ }),
+ ]),
+]
+
+classes = (
+ MyCustomTree,
+ MyCustomSocket,
+ MyCustomNode,
+)
def register():
- bpy.utils.register_class(MyCustomTree)
- bpy.utils.register_class(MyCustomSocket)
- bpy.utils.register_class(MyCustomNode)
+ from bpy.utils import register_class
+ for cls in classes:
+ register_class(cls)
- nodeitems_utils.register_node_categories("CUSTOM_NODES", node_categories)
+ nodeitems_utils.register_node_categories('CUSTOM_NODES', node_categories)
def unregister():
- nodeitems_utils.unregister_node_categories("CUSTOM_NODES")
+ nodeitems_utils.unregister_node_categories('CUSTOM_NODES')
- bpy.utils.unregister_class(MyCustomTree)
- bpy.utils.unregister_class(MyCustomSocket)
- bpy.utils.unregister_class(MyCustomNode)
+ from bpy.utils import unregister_class
+ for cls in reversed(classes):
+ unregister_class(cls)
if __name__ == "__main__":