forked from bartvdbraak/blender
ID properties that are displayed via RNA can now define their own UI settings,
only implimented min/max precision & step. at the moment there is no way to edit these other then via python example of setting UI limits... >>> C.object['foo'] = 0.5 >>> C.object['_RNA_UI'] = {'foo': {'step': 0.5, 'soft_max': 10.0, 'soft_min': 0.0, 'precision': 2, 'description': 'Some setting'}} Also fixed typo's: precission -> precision
This commit is contained in:
parent
5f6b9fd324
commit
ae5a814f26
@ -36,7 +36,7 @@ def evil_prop_init():
|
||||
Scene.StringProperty(attr=EVIL_PROP_PROP_ORIG)
|
||||
|
||||
|
||||
def draw(layout, context, context_member):
|
||||
def draw(layout, context, context_member, use_edit = True):
|
||||
|
||||
def assign_props(prop, val, key):
|
||||
prop.path = context_member
|
||||
@ -63,11 +63,17 @@ def draw(layout, context, context_member):
|
||||
items = rna_item.items()
|
||||
items.sort()
|
||||
|
||||
row = layout.row()
|
||||
props = row.itemO("wm.properties_add", properties=True, text="Add")
|
||||
props.path = context_member
|
||||
|
||||
if use_edit:
|
||||
row = layout.row()
|
||||
props = row.itemO("wm.properties_add", properties=True, text="Add")
|
||||
props.path = context_member
|
||||
del row
|
||||
|
||||
for key, val in items:
|
||||
|
||||
if key == '_RNA_UI':
|
||||
continue
|
||||
|
||||
row = layout.row()
|
||||
convert_to_pyobject = getattr(val, "convert_to_pyobject", None)
|
||||
|
||||
@ -80,7 +86,7 @@ def draw(layout, context, context_member):
|
||||
|
||||
box = row.box()
|
||||
|
||||
if key == global_prop_orig and context_member == global_path:
|
||||
if use_edit and key == global_prop_orig and context_member == global_path:
|
||||
split = box.split(percentage=0.75)
|
||||
|
||||
row = split.row()
|
||||
@ -92,8 +98,12 @@ def draw(layout, context, context_member):
|
||||
assign_props(prop, val_draw, key)
|
||||
|
||||
else:
|
||||
split = box.split(percentage=0.75)
|
||||
row = split.row()
|
||||
if use_edit:
|
||||
split = box.split(percentage=0.75)
|
||||
row = split.row()
|
||||
else:
|
||||
row = box.row()
|
||||
|
||||
row.itemL(text=key)
|
||||
|
||||
# explicit exception for arrays
|
||||
@ -102,13 +112,13 @@ def draw(layout, context, context_member):
|
||||
else:
|
||||
row.itemR(rna_item, '["%s"]' % key, text="")
|
||||
|
||||
|
||||
row = split.row(align=True)
|
||||
prop = row.itemO("wm.properties_edit_begin", properties=True, text="edit")
|
||||
assign_props(prop, val_draw, key)
|
||||
|
||||
prop = row.itemO("wm.properties_remove", properties=True, text="", icon='ICON_ZOOMOUT')
|
||||
assign_props(prop, val_draw, key)
|
||||
if use_edit:
|
||||
row = split.row(align=True)
|
||||
prop = row.itemO("wm.properties_edit_begin", properties=True, text="edit")
|
||||
assign_props(prop, val_draw, key)
|
||||
|
||||
prop = row.itemO("wm.properties_remove", properties=True, text="", icon='ICON_ZOOMOUT')
|
||||
assign_props(prop, val_draw, key)
|
||||
|
||||
|
||||
from bpy.props import *
|
||||
|
@ -300,7 +300,7 @@ class OBJECT_PT_properties(ObjectButtonsPanel):
|
||||
def draw(self, context):
|
||||
import rna_prop_ui
|
||||
# reload(rna_prop_ui)
|
||||
|
||||
|
||||
rna_prop_ui.draw(self.layout, context, "object")
|
||||
|
||||
bpy.types.register(OBJECT_PT_context_object)
|
||||
|
@ -1629,6 +1629,29 @@ class VIEW3D_PT_etch_a_ton(bpy.types.Panel):
|
||||
col.itemR(toolsettings, "etch_side")
|
||||
|
||||
|
||||
class VIEW3D_PT_context_properties(bpy.types.Panel):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Properties"
|
||||
bl_default_closed = True
|
||||
|
||||
def draw(self, context):
|
||||
import rna_prop_ui
|
||||
# reload(rna_prop_ui)
|
||||
obj = context.object
|
||||
if obj:
|
||||
mode = obj.mode
|
||||
if mode == 'POSE':
|
||||
item = "active_pchan"
|
||||
elif mode == 'EDIT' and obj.type == 'ARMATURE':
|
||||
item = "active_bone"
|
||||
else:
|
||||
item = "object"
|
||||
|
||||
# Draw with no edit button
|
||||
rna_prop_ui.draw(self.layout, context, item, False)
|
||||
|
||||
|
||||
# Operators
|
||||
from bpy.props import *
|
||||
|
||||
@ -1757,4 +1780,6 @@ bpy.types.register(VIEW3D_PT_background_image)
|
||||
bpy.types.register(VIEW3D_PT_transform_orientations)
|
||||
bpy.types.register(VIEW3D_PT_etch_a_ton)
|
||||
|
||||
bpy.types.register(VIEW3D_PT_context_properties)
|
||||
|
||||
bpy.ops.add(OBJECT_OT_select_pattern)
|
||||
|
@ -117,7 +117,7 @@ int IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous,
|
||||
*/
|
||||
void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop);
|
||||
|
||||
IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, char *name);
|
||||
IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, const char *name);
|
||||
|
||||
/*Get an iterator to iterate over the members of an id property group.
|
||||
Note that this will automatically free the iterator once iteration is complete;
|
||||
|
@ -442,7 +442,7 @@ void IDP_RemFromGroup(IDProperty *group, IDProperty *prop)
|
||||
BLI_remlink(&group->data.group, prop);
|
||||
}
|
||||
|
||||
IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, char *name)
|
||||
IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name)
|
||||
{
|
||||
IDProperty *loop;
|
||||
for (loop=prop->data.group.first; loop; loop=loop->next) {
|
||||
|
@ -1355,15 +1355,15 @@ static void ui_get_but_string_unit(uiBut *but, char *str, int len_max, double va
|
||||
Scene *scene= CTX_data_scene((bContext *)but->block->evil_C);
|
||||
int do_split= scene->unit.flag & USER_UNIT_OPT_SPLIT;
|
||||
int unit_type= RNA_SUBTYPE_UNIT_VALUE(RNA_property_subtype(but->rnaprop));
|
||||
int precission= but->a2;
|
||||
int precision= but->a2;
|
||||
|
||||
if(scene->unit.scale_length<0.0001) scene->unit.scale_length= 1.0; // XXX do_versions
|
||||
|
||||
/* Sanity checks */
|
||||
if(precission>4) precission= 4;
|
||||
else if(precission==0) precission= 2;
|
||||
if(precision>4) precision= 4;
|
||||
else if(precision==0) precision= 2;
|
||||
|
||||
bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precission, scene->unit.system, unit_type, do_split, pad);
|
||||
bUnit_AsString(str, len_max, ui_get_but_scale_unit(but, value), precision, scene->unit.system, unit_type, do_split, pad);
|
||||
}
|
||||
|
||||
static float ui_get_but_step_unit(uiBut *but, double value, float step_default)
|
||||
|
@ -525,7 +525,7 @@ static void draw_shadedstrip(Sequence *seq, char *col, float x1, float y1, float
|
||||
/*
|
||||
Draw a sequence strip, bounds check alredy made
|
||||
ARegion is currently only used to get the windows width in pixels
|
||||
so wave file sample drawing precission is zoom adjusted
|
||||
so wave file sample drawing precision is zoom adjusted
|
||||
*/
|
||||
static void draw_seq_strip(Scene *scene, ARegion *ar, SpaceSeq *sseq, Sequence *seq, int outline_tint, float pixelx)
|
||||
{
|
||||
|
@ -2234,7 +2234,7 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
|
||||
if(G.f & (G_RENDER_OGL|G_RENDER_SHADOW))
|
||||
return;
|
||||
|
||||
/* make the precission of the pronted value proportionate to the gridsize */
|
||||
/* make the precision of the pronted value proportionate to the gridsize */
|
||||
|
||||
if (grid < 0.01f)
|
||||
strcpy(conv_float, "%.6f");
|
||||
|
@ -91,7 +91,7 @@ void info_callback(const char *msg, void *client_data) {
|
||||
struct ImBuf *imb_jp2_decode(unsigned char *mem, int size, int flags)
|
||||
{
|
||||
struct ImBuf *ibuf = 0;
|
||||
int use_float = 0; /* for precissions higher then 8 use float */
|
||||
int use_float = 0; /* for precision higher then 8 use float */
|
||||
unsigned char *rect= NULL;
|
||||
float *rect_float= NULL;
|
||||
|
||||
|
@ -190,6 +190,29 @@ PointerRNA rna_pointer_inherit_refine(PointerRNA *ptr, StructRNA *type, void *da
|
||||
|
||||
/* ID Properties */
|
||||
|
||||
/* return a UI local ID prop definition for this prop */
|
||||
IDProperty *rna_idproperty_ui(PropertyRNA *prop)
|
||||
{
|
||||
IDProperty *idprop;
|
||||
|
||||
for(idprop= ((IDProperty *)prop)->prev; idprop; idprop= idprop->prev) {
|
||||
if (strcmp(RNA_IDP_UI, idprop->name)==0)
|
||||
break;
|
||||
}
|
||||
|
||||
if(idprop==NULL) {
|
||||
for(idprop= ((IDProperty *)prop)->next; idprop; idprop= idprop->next) {
|
||||
if (strcmp(RNA_IDP_UI, idprop->name)==0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (idprop)
|
||||
return IDP_GetPropertyFromGroup(idprop, ((IDProperty *)prop)->name);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IDProperty *RNA_struct_idproperties(PointerRNA *ptr, int create)
|
||||
{
|
||||
StructRNA *type= ptr->type;
|
||||
@ -396,8 +419,17 @@ static const char *rna_ensure_property_description(PropertyRNA *prop)
|
||||
{
|
||||
if(prop->magic == RNA_MAGIC)
|
||||
return prop->description;
|
||||
else
|
||||
else {
|
||||
/* attempt to get the local ID values */
|
||||
IDProperty *idp_ui= rna_idproperty_ui(prop);
|
||||
|
||||
if(idp_ui) { /* TODO, type checking on ID props */
|
||||
IDProperty *item= IDP_GetPropertyFromGroup(idp_ui, "description");
|
||||
return item ? ((IDProperty*)prop)->name : item->data.pointer;
|
||||
}
|
||||
|
||||
return ((IDProperty*)prop)->name; /* XXX - not correct */
|
||||
}
|
||||
}
|
||||
|
||||
static const char *rna_ensure_property_name(PropertyRNA *prop)
|
||||
@ -668,6 +700,22 @@ void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, in
|
||||
{
|
||||
IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
|
||||
|
||||
if(prop->magic != RNA_MAGIC) {
|
||||
/* attempt to get the local ID values */
|
||||
IDProperty *idp_ui= rna_idproperty_ui(prop);
|
||||
IDProperty *item;
|
||||
|
||||
if(idp_ui) { /* TODO, type checking on ID props */
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "min");
|
||||
*hardmin= item ? item->data.val : INT_MIN;
|
||||
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "max");
|
||||
*hardmax= item ? item->data.val : INT_MAX;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(iprop->range) {
|
||||
iprop->range(ptr, hardmin, hardmax);
|
||||
}
|
||||
@ -682,6 +730,25 @@ void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin,
|
||||
IntPropertyRNA *iprop= (IntPropertyRNA*)rna_ensure_property(prop);
|
||||
int hardmin, hardmax;
|
||||
|
||||
if(prop->magic != RNA_MAGIC) {
|
||||
/* attempt to get the local ID values */
|
||||
IDProperty *idp_ui= rna_idproperty_ui(prop);
|
||||
IDProperty *item;
|
||||
|
||||
if(idp_ui) { /* TODO, type checking on ID props */
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
|
||||
*softmin= item ? item->data.val : INT_MIN;
|
||||
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
|
||||
*softmax= item ? item->data.val : INT_MAX;
|
||||
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "step");
|
||||
*step= item ? item->data.val : 1;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(iprop->range) {
|
||||
iprop->range(ptr, &hardmin, &hardmax);
|
||||
*softmin= MAX2(iprop->softmin, hardmin);
|
||||
@ -699,6 +766,22 @@ void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin
|
||||
{
|
||||
FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
|
||||
|
||||
if(prop->magic != RNA_MAGIC) {
|
||||
/* attempt to get the local ID values */
|
||||
IDProperty *idp_ui= rna_idproperty_ui(prop);
|
||||
IDProperty *item;
|
||||
|
||||
if(idp_ui) { /* TODO, type checking on ID props */
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "min");
|
||||
*hardmin= item ? *(double*)&item->data.val : FLT_MIN;
|
||||
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "max");
|
||||
*hardmax= item ? *(double*)&item->data.val : FLT_MAX;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(fprop->range) {
|
||||
fprop->range(ptr, hardmin, hardmax);
|
||||
}
|
||||
@ -713,6 +796,28 @@ void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *soft
|
||||
FloatPropertyRNA *fprop= (FloatPropertyRNA*)rna_ensure_property(prop);
|
||||
float hardmin, hardmax;
|
||||
|
||||
if(prop->magic != RNA_MAGIC) {
|
||||
/* attempt to get the local ID values */
|
||||
IDProperty *idp_ui= rna_idproperty_ui(prop);
|
||||
IDProperty *item;
|
||||
|
||||
if(idp_ui) { /* TODO, type checking on ID props */
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "soft_min");
|
||||
*softmin= item ? *(double*)&item->data.val : FLT_MIN;
|
||||
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "soft_max");
|
||||
*softmax= item ? *(double*)&item->data.val : FLT_MAX;
|
||||
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "step");
|
||||
*step= item ? *(double*)&item->data.val : 1.0f;
|
||||
|
||||
item= IDP_GetPropertyFromGroup(idp_ui, "precision");
|
||||
*precision= item ? *(double*)&item->data.val : 3.0f;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(fprop->range) {
|
||||
fprop->range(ptr, &hardmin, &hardmax);
|
||||
*softmin= MAX2(fprop->softmin, hardmin);
|
||||
|
@ -47,6 +47,10 @@ struct GHash;
|
||||
|
||||
#define RNA_MAX_ARRAY_DIMENSION 3
|
||||
|
||||
|
||||
/* store local properties here */
|
||||
#define RNA_IDP_UI "_RNA_UI"
|
||||
|
||||
/* Function Callbacks */
|
||||
|
||||
typedef void (*UpdateFunc)(struct bContext *C, struct PointerRNA *ptr);
|
||||
|
@ -3252,9 +3252,10 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
|
||||
PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
static char *kwlist[] = {"attr", "name", "description", "min", "max", "soft_min", "soft_max", "default", NULL};
|
||||
static char *kwlist[] = {"attr", "name", "description", "min", "max", "soft_min", "soft_max", "step", "precision", "default", NULL};
|
||||
char *id=NULL, *name="", *description="";
|
||||
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, def=0.0f;
|
||||
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f;
|
||||
int precision= 1;
|
||||
PropertyRNA *prop;
|
||||
StructRNA *srna;
|
||||
|
||||
@ -3269,10 +3270,11 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
}
|
||||
else if(srna) {
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssfffff:FloatProperty", kwlist, &id, &name, &description, &min, &max, &soft_min, &soft_max, &def))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssfffffif:FloatProperty", kwlist, &id, &name, &description, &min, &max, &soft_min, &soft_max, &step, &precision, &def))
|
||||
return NULL;
|
||||
|
||||
prop= RNA_def_float(srna, id, def, min, max, name, description, soft_min, soft_max);
|
||||
RNA_def_property_ui_range(prop, min, max, step, precision);
|
||||
RNA_def_property_duplicate_pointers(prop);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user