Skip to content

Commit

Permalink
Prop and args change (#3925)
Browse files Browse the repository at this point in the history
* apply tests

* i think...

* correct typo

* works in both|

* or maybe this

* CR/NL
  • Loading branch information
zeffii authored Feb 23, 2021
1 parent 825283d commit a3562ba
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
3 changes: 2 additions & 1 deletion core/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

from sverchok.settings import get_params

from sverchok.utils.handle_blender_data import get_func_and_args
from sverchok.utils.socket_utils import format_bpy_property, setup_new_node_location
from sverchok.utils.field.scalar import SvScalarField
from sverchok.utils.field.vector import SvVectorField
Expand Down Expand Up @@ -1444,7 +1445,7 @@ def socket_interface_classes():
'draw_color': lambda self, context: self.color
}
if 'default_property' in socket_cls.__annotations__:
prop_func, prop_args = socket_cls.__annotations__['default_property']
prop_func, prop_args = get_func_and_args(socket_cls.__annotations__['default_property'])
prop_args = {k: prop_args[k] for k in prop_args if k not in {'update', 'name'}}
prop_args['name'] = "Default value"
prop_args['update'] = lambda s, c: s.id_data.update_sockets()
Expand Down
4 changes: 2 additions & 2 deletions nodes/list_mutators/vd_attr_node_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, enum_item_5
from sverchok.nodes.viz.viewer_draw_mk4 import SvViewerDrawMk4

from sverchok.utils.handle_blender_data import get_func_and_args

sock_str = {
'enum': "SvStringsSocket",
Expand Down Expand Up @@ -81,7 +81,7 @@ class SvVDMK4Properties(bpy.types.PropertyGroup):
# this populates a property-group using VDExperimental.__annotations__ as the source -
__annotations__ = {}
for key, v in maximum_spec_vd_dict.items():
prop_func, kw_args = SvViewerDrawMk4.__annotations__[key]
prop_func, kw_args = get_func_and_args(SvViewerDrawMk4.__annotations__[key])
copy_kw_args = copy.deepcopy(kw_args)
copy_kw_args.pop('update', None)
__annotations__[key] = prop_func(**copy_kw_args)
Expand Down
16 changes: 16 additions & 0 deletions utils/handle_blender_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,19 @@ def get_type(cls, bl_rna) -> Union[BPYPointers, None]:
if pointer.type.bl_rna == bl_rna:
return pointer
raise TypeError(f'Type: "{bl_rna}" was not found in: {[t.type.bl_rna for t in BPYPointers]}')


def get_func_and_args(prop):
"""
usage:
- formerly
prop_func, prop_args = some_class.__annotations__[some_prop_name]
- new
prop_to_decompose = some_class.__annotations__[some_prop_name]
prop_func, prop_args = get_func_and_args(prop_to_decompose)
"""
if hasattr(prop, "keywords"):
return prop.function, prop.keywords
else:
return prop
26 changes: 13 additions & 13 deletions utils/handling_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def process(self):
from bpy.types import Node

from sverchok.data_structure import updateNode

from sverchok.utils.handle_blender_data import get_func_and_args

class WrapNode:
# instancing the class for crating properties and sockets
Expand Down Expand Up @@ -380,27 +380,27 @@ def update_node(node, context):
updateNode(node, context)

for name, prop in self.properties.items():

bpy_prop, bpy_prop_arguments = prop.bpy_props
bpy_prop, bpy_prop_arguments = get_func_and_args(prop.bpy_props)
bpy_prop_arguments['update'] = update_node
rebuild_bpy_prop = blender_properties[bpy_prop](**bpy_prop_arguments)

node_annotations[name] = rebuild_bpy_prop

get_func = lambda prop: get_func_and_args(prop)[0]

blender_properties = {
# properties are functions which return tuples with themselves as first argument
# it should help to rebuild properties with new arguments
bpy.props.BoolProperty()[0]: bpy.props.BoolProperty,
bpy.props.BoolVectorProperty()[0]: bpy.props.BoolVectorProperty,
bpy.props.CollectionProperty()[0]: bpy.props.CollectionProperty,
bpy.props.EnumProperty()[0]: bpy.props.EnumProperty,
bpy.props.FloatProperty()[0]: bpy.props.FloatProperty,
bpy.props.FloatVectorProperty()[0]: bpy.props.FloatVectorProperty,
bpy.props.IntProperty()[0]: bpy.props.IntProperty,
bpy.props.IntVectorProperty()[0]: bpy.props.IntVectorProperty,
bpy.props.PointerProperty()[0]: bpy.props.PointerProperty,
bpy.props.StringProperty()[0]: bpy.props.StringProperty
get_func(bpy.props.BoolProperty()): bpy.props.BoolProperty,
get_func(bpy.props.BoolVectorProperty()): bpy.props.BoolVectorProperty,
get_func(bpy.props.CollectionProperty()): bpy.props.CollectionProperty,
get_func(bpy.props.EnumProperty()): bpy.props.EnumProperty,
get_func(bpy.props.FloatProperty()): bpy.props.FloatProperty,
get_func(bpy.props.FloatVectorProperty()): bpy.props.FloatVectorProperty,
get_func(bpy.props.IntProperty()): bpy.props.IntProperty,
get_func(bpy.props.IntVectorProperty()): bpy.props.IntVectorProperty,
get_func(bpy.props.PointerProperty()): bpy.props.PointerProperty,
get_func(bpy.props.StringProperty()): bpy.props.StringProperty
}


Expand Down

0 comments on commit a3562ba

Please sign in to comment.