[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4400] contrib/py/scripts/addons/ node_efficiency_tools.py: Code clean up.
Bartek Skorupa
bartekskorupa at bartekskorupa.com
Thu Mar 21 13:48:27 CET 2013
Revision: 4400
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4400
Author: bartekskorupa
Date: 2013-03-21 12:48:26 +0000 (Thu, 21 Mar 2013)
Log Message:
-----------
Code clean up. No functional changes.
- change names of some properties of classes.
- replacing EnumProperties with StringProperties.
- Changes in some menus, adding new menus to match new classes properties.
- Different handling of keymap items. Because of large number of keymap items - their properties wrapped in tuples.
Modified Paths:
--------------
contrib/py/scripts/addons/node_efficiency_tools.py
Modified: contrib/py/scripts/addons/node_efficiency_tools.py
===================================================================
--- contrib/py/scripts/addons/node_efficiency_tools.py 2013-03-20 21:38:54 UTC (rev 4399)
+++ contrib/py/scripts/addons/node_efficiency_tools.py 2013-03-21 12:48:26 UTC (rev 4400)
@@ -19,7 +19,7 @@
bl_info = {
'name': "Nodes Efficiency Tools",
'author': "Bartek Skorupa",
- 'version': (2, 0.09),
+ 'version': (2, 0.10),
'blender': (2, 6, 6),
'location': "Node Editor Properties Panel (Ctrl-SPACE)",
'description': "Nodes Efficiency Tools",
@@ -117,10 +117,8 @@
bl_label = "Merge Selected Nodes"
bl_options = {'REGISTER', 'UNDO'}
- combo = StringProperty(
- name = "Combo",
- description = "BlendType/ShaderKind/MathOperation and Node Kind",
- )
+ # option: "BlendType/ShaderKind/MathOperation and Node Kind" separated with space
+ option = StringProperty()
@classmethod
def poll(cls, context):
@@ -134,9 +132,9 @@
elif tree_type == 'SHADER':
node_type = 'ShaderNode'
set_convenience_variables(context)
- combo_split = self.combo.split( )
- mode = combo_split[0]
- node_kind = combo_split[1] # kinds: 'AUTO', 'SHADER', 'MIX', 'MATH'
+ option_split = self.option.split( )
+ mode = option_split[0]
+ node_kind = option_split[1] # kinds: 'AUTO', 'SHADER', 'MIX', 'MATH'
selected_mix = [] # entry = [index, loc]
selected_shader = [] # entry = [index, loc]
selected_math = [] # entry = [index, loc]
@@ -253,10 +251,8 @@
bl_label = "Batch Change Blend Type and Math Operation"
bl_options = {'REGISTER', 'UNDO'}
- combo = StringProperty(
- name = "Combo",
- description = "Mix Blend Type and Math Operation"
- )
+ # Mix Blend Type and Math Operation separated with space.
+ option = StringProperty()
@classmethod
def poll(cls, context):
@@ -266,9 +262,9 @@
def execute(self, context):
set_convenience_variables(context)
navs = ('CURRENT', 'NEXT', 'PREV')
- combo_split = self.combo.split( )
- blend_type = combo_split[0]
- operation = combo_split[1]
+ option_split = self.option.split( )
+ blend_type = option_split[0]
+ operation = option_split[1]
for node in context.selected_nodes:
if node.type == 'MIX_RGB':
if not blend_type in navs:
@@ -314,10 +310,8 @@
bl_label = "Change Factors of Mix Nodes and Mix Shader Nodes"
bl_options = {'REGISTER', 'UNDO'}
- change = StringProperty(
- name = "Fac_Change",
- description = "Factor Change",
- )
+ # option: string indicating factor change. Example: '0.1'
+ option = StringProperty()
@classmethod
def poll(cls, context):
@@ -326,7 +320,7 @@
def execute(self, context):
set_convenience_variables(context)
- change = float(self.change)
+ option = float(self.option)
selected = [] # entry = index
for si, node in enumerate(nodes):
if node.select:
@@ -336,10 +330,10 @@
for si in selected:
fac = nodes[si].inputs[0]
nodes[si].hide = False
- if change in {0.0, 1.0}:
- fac.default_value = change
+ if option in {0.0, 1.0}:
+ fac.default_value = option
else:
- fac.default_value += change
+ fac.default_value += option
return {'FINISHED'}
@@ -468,6 +462,9 @@
bl_label = "Clear Label"
bl_options = {'REGISTER', 'UNDO'}
+ # option: 'confirmed', 'not confirmed'
+ option = StringProperty()
+
@classmethod
def poll(cls, context):
space = context.space_data
@@ -481,13 +478,19 @@
return {'FINISHED'}
def invoke(self, context, event):
- return context.window_manager.invoke_confirm(self, event)
+ if self.option == 'confirmed':
+ return self.execute(context)
+ else:
+ return context.window_manager.invoke_confirm(self, event)
class NodesAddTextureSetup(bpy.types.Operator):
bl_idname = "node.add_texture"
bl_label = "Add Texture Node to Active Node Input"
bl_options = {'REGISTER', 'UNDO'}
+
+ # placeholder
+ option = StringProperty()
@classmethod
def poll(cls, context):
@@ -825,17 +828,9 @@
bl_label = "Align nodes"
bl_options = {'REGISTER', 'UNDO'}
- axes = []
- axes_list = ['Vertically', 'Horizontally']
- for axis in axes_list:
- axes.append((axis, axis, axis))
+ # option: 'Vertically', 'Horizontally'
+ option = StringProperty()
- align_axis = EnumProperty(
- name = "align_axis",
- description = "Align Axis",
- items = axes
- )
-
@classmethod
def poll(cls, context):
space = context.space_data
@@ -908,7 +903,7 @@
max_y_w = selected_sorted_y[count - 1][3] # width of node with max loc.y
max_y_h = selected_sorted_y[count - 1][4] # height of node with max loc.y
- if self.align_axis == 'Vertically':
+ if self.option == 'Vertically':
loc_x = min_x
#loc_y = (max_x_loc_y + min_x_loc_y) / 2.0
loc_y = (max_y - max_y_h / 2.0 + min_y - min_y_h / 2.0) / 2.0
@@ -951,10 +946,8 @@
bl_label = "Select Parent or Children"
bl_options = {'REGISTER', 'UNDO'}
- option = StringProperty(
- name = "option",
- description = "Parent/Children",
- )
+ # option: 'Parent', 'Children'
+ option = StringProperty()
@classmethod
def poll(cls, context):
@@ -1003,9 +996,9 @@
if type == 'ShaderNodeTree':
box.operator(NodesAddTextureSetup.bl_idname, text = 'Add Image Texture (Ctrl T)')
box.menu(BatchChangeNodesMenu.bl_idname, text = 'Batch Change...')
- box.operator_menu_enum(AlignNodes.bl_idname, "align_axis", text = "Align Nodes (Shift =)")
- box.menu(CopyNodePropertiesMenu.bl_idname, text = 'Copy to Selected (Shift-C)')
- box.operator(NodesClearLabel.bl_idname)
+ box.menu(NodeAlignMenu.bl_idname, text = "Align Nodes (Shift =)")
+ box.menu(CopyToSelectedMenu.bl_idname, text = 'Copy to Selected (Shift-C)')
+ box.operator(NodesClearLabel.bl_idname).option = 'confirmed'
box.menu(AddReroutesMenu.bl_idname, text = 'Add Reroutes')
box.menu(ReroutesSwitchesSwapMenu.bl_idname, text = 'Swap Reroutes and Switches')
box.menu(LinkActiveToSelectedMenu.bl_idname, text = 'Link Active To Selected')
@@ -1031,12 +1024,9 @@
if type == 'ShaderNodeTree':
layout.operator(NodesAddTextureSetup.bl_idname, text = 'Add Image Texture with coordinates')
layout.menu(BatchChangeNodesMenu.bl_idname, text = 'Batch Change')
- layout.operator_menu_enum(
- AlignNodes.bl_idname,
- property="align_axis",
- text="Align Nodes",
- )
- layout.menu(CopyNodePropertiesMenu.bl_idname, text = 'Copy to Selected')
+ layout.menu(NodeAlignMenu.bl_idname, text="Align Nodes")
+ layout.menu(CopyToSelectedMenu.bl_idname, text = 'Copy to Selected')
+ layout.operator(NodesClearLabel.bl_idname).option = 'confirmed'
layout.menu(AddReroutesMenu.bl_idname, text = 'Add Reroutes')
layout.menu(ReroutesSwitchesSwapMenu.bl_idname, text = 'Swap Reroutes and Switches')
layout.menu(LinkActiveToSelectedMenu.bl_idname, text = 'Link Active To Selected')
@@ -1072,8 +1062,8 @@
def draw(self, context):
layout = self.layout
for type in merge_shaders:
- combo = type + ' SHADER'
- layout.operator(MergeNodes.bl_idname, text = type).combo = combo
+ option = type + ' SHADER'
+ layout.operator(MergeNodes.bl_idname, text = type).option = option
class MergeMixMenu(bpy.types.Menu):
@@ -1088,8 +1078,8 @@
def draw(self, context):
layout = self.layout
for type in blend_types:
- combo = type + ' MIX'
- layout.operator(MergeNodes.bl_idname, text = type).combo = combo
+ option = type + ' MIX'
+ layout.operator(MergeNodes.bl_idname, text = type).option = option
class MergeMathMenu(bpy.types.Menu):
@@ -1104,8 +1094,8 @@
def draw(self, context):
layout = self.layout
for type in operations:
- combo = type + ' MATH'
- layout.operator(MergeNodes.bl_idname, text = type).combo = combo
+ option = type + ' MATH'
+ layout.operator(MergeNodes.bl_idname, text = type).option = option
class BatchChangeNodesMenu(bpy.types.Menu):
@@ -1135,8 +1125,8 @@
def draw(self, context):
layout = self.layout
for blend_type in blend_types:
- combo = blend_type + ' CURRENT'
- layout.operator(BatchChangeNodes.bl_idname, text = blend_type).combo = combo
+ option = blend_type + ' CURRENT'
+ layout.operator(BatchChangeNodes.bl_idname, text = blend_type).option = option
class BatchChangeOperationMenu(bpy.types.Menu):
@@ -1151,13 +1141,13 @@
def draw(self, context):
layout = self.layout
for operation in operations:
- combo = 'CURRENT ' + operation
- layout.operator(BatchChangeNodes.bl_idname, text = operation).combo = combo
+ option = 'CURRENT ' + operation
+ layout.operator(BatchChangeNodes.bl_idname, text = operation).option = option
-class CopyNodePropertiesMenu(bpy.types.Menu):
+class CopyToSelectedMenu(bpy.types.Menu):
bl_idname = "NODE_MT_copy_node_properties_menu"
- bl_label = "Copy Active Node's Properties to Selected"
+ bl_label = "Copy to Selected"
def draw(self, context):
layout = self.layout
@@ -1228,12 +1218,10 @@
def draw(self, context):
layout = self.layout
- layout.operator_menu_enum(
- AlignNodes.bl_idname,
- property="align_axis",
- text="Direction...",
- )
+ for opt in {'Horizontally', 'Vartically'}:
+ layout.operator(AlignNodes.bl_idname, text=opt).option = opt
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list