Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(416)

Issue 7027056: Support for Get/Set callbacks in bpy.props (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 4 months ago by lukas.toenne1
Modified:
11 years, 1 month ago
Reviewers:
ideasman42, bf-codereview
Base URL:
https://svn.blender.org/svnroot/bf-blender/trunk/blender/
Visibility:
Public.

Description

This patch adds support in bpy.props for getter/setter callback functions. We already have update callbacks, but generic get/set functions can come in handy in some cases where the functionality is too complex to use a single value. The current C callback functions are too simple allow a straightforward implementation, in particular they don't receive the PropertyRNA pointer itself as an argument, which means the callback cannot directly access the PropertyRNA's py_data pointers which store the python function objects. For this reason a second runtime variant of these callbacks has been added. It is only used for runtime callbacks and not in makesrna, but otherwise works the same way. A few possible improvements: * BPy_EnumProperty: Could use generic property py_data slot for the enum item callback. Would be one unused pointer for non-enum properties, but a bit simpler. * BPy_EnumProperty: Integrate enum item function argument check into general bpy_prop_callback_check. * enum get/set callbacks only work with integer values for now. Using string identifiers would be better, for that the extended callback variants must be modified for runtime enum callbacks. No access to the items list in get/set itself (no context).

Patch Set 1 #

Total comments: 15
Unified diffs Side-by-side diffs Delta from patch set Stats (+1759 lines, -324 lines) Patch
source/blender/makesrna/RNA_define.h View 2 chunks +11 lines, -1 line 0 comments Download
source/blender/makesrna/RNA_types.h View 1 chunk +21 lines, -1 line 0 comments Download
source/blender/makesrna/intern/makesrna.c View 5 chunks +27 lines, -8 lines 0 comments Download
source/blender/makesrna/intern/rna_access.c View 21 chunks +69 lines, -0 lines 3 comments Download
source/blender/makesrna/intern/rna_define.c View 6 chunks +138 lines, -6 lines 0 comments Download
source/blender/makesrna/intern/rna_internal_types.h View 7 chunks +47 lines, -5 lines 0 comments Download
source/blender/python/intern/bpy_props.c View 40 chunks +1446 lines, -303 lines 12 comments Download

Messages

Total messages: 4
lukas.toenne1
11 years, 4 months ago (2013-01-04 18:43:43 UTC) #1
lukas.toenne1
Here is a small test file: http://www.pasteall.org/blend/18621 Just run the test.py script from blender editor. ...
11 years, 4 months ago (2013-01-04 18:46:32 UTC) #2
ideasman42
LGTM, besides some minor suggestions https://codereview.appspot.com/7027056/diff/1/source/blender/makesrna/intern/rna_access.c File source/blender/makesrna/intern/rna_access.c (right): https://codereview.appspot.com/7027056/diff/1/source/blender/makesrna/intern/rna_access.c#newcode995 source/blender/makesrna/intern/rna_access.c:995: + *softmin = MAX2(*softmin, ...
11 years, 4 months ago (2013-01-05 13:32:07 UTC) #3
lukas.toenne1
11 years, 4 months ago (2013-01-05 14:39:45 UTC) #4
https://codereview.appspot.com/7027056/diff/1/source/blender/makesrna/intern/...
File source/blender/makesrna/intern/rna_access.c (right):

https://codereview.appspot.com/7027056/diff/1/source/blender/makesrna/intern/...
source/blender/makesrna/intern/rna_access.c:995: *softmin = MAX2(*softmin,
hardmin);
On 2013/01/05 13:32:07, ideasman42 wrote:
> picky, preference for min_ii, max_ii

I basically just copy/pasted this from the case above, guess that should be
changed too then.

https://codereview.appspot.com/7027056/diff/1/source/blender/python/intern/bp...
File source/blender/python/intern/bpy_props.c (right):

https://codereview.appspot.com/7027056/diff/1/source/blender/python/intern/bp...
source/blender/python/intern/bpy_props.c:267: value = 0.0f;
On 2013/01/05 13:32:07, ideasman42 wrote:
> float, should be true/false

Done.

https://codereview.appspot.com/7027056/diff/1/source/blender/python/intern/bp...
source/blender/python/intern/bpy_props.c:364: PyObject *py_seq =
PySequence_Fast(ret, "the return value must be a sequence");
On 2013/01/05 13:32:07, ideasman42 wrote:
> Think it'd be better to use: PyC_AsArray here

Done.

https://codereview.appspot.com/7027056/diff/1/source/blender/python/intern/bp...
source/blender/python/intern/bpy_props.c:577: PyObject *py_seq =
PySequence_Fast(ret, "the return value must be a sequence");
On 2013/01/05 13:32:07, ideasman42 wrote:
> Think it'd be better to use: PyC_AsArray here

Done.

https://codereview.appspot.com/7027056/diff/1/source/blender/python/intern/bp...
source/blender/python/intern/bpy_props.c:639: py_values = PyTuple_New(len);
On 2013/01/05 13:32:07, ideasman42 wrote:
> Not so important but could have a util function - PyC_ToArray that works like
> PyC_AsArray.
> 
> same goes for other types here.

Done.

https://codereview.appspot.com/7027056/diff/1/source/blender/python/intern/bp...
source/blender/python/intern/bpy_props.c:789: else {
On 2013/01/05 13:32:07, ideasman42 wrote:
> Think it'd be better to use: PyC_AsArray here

Done.

https://codereview.appspot.com/7027056/diff/1/source/blender/python/intern/bp...
source/blender/python/intern/bpy_props.c:989: PyTuple_SET_ITEM(args, 1,
PyUnicode_FromString(value));
On 2013/01/05 13:32:07, ideasman42 wrote:
> should error check that PyUnicode_FromString() isnt failing.

Done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b