better blender doesnt look idiot for siggraph with tips wider then the screen.

only show operator args in the tooltip that are different from the defaults.
This commit is contained in:
Campbell Barton 2009-07-29 23:48:06 +00:00
parent 5896233564
commit 86cfc1966e
5 changed files with 41 additions and 8 deletions

@ -396,7 +396,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
char *str;
opptr= uiButGetOperatorPtrRNA(but); /* allocated when needed, the button owns it */
str= WM_operator_pystring(but->optype, opptr);
str= WM_operator_pystring(but->optype, opptr, 0);
/* operator info */
BLI_snprintf(data->lines[data->totline], sizeof(data->lines[0]), "Python: %s", str);

@ -172,7 +172,7 @@ void WM_operator_properties_free(struct PointerRNA *ptr);
void WM_operator_properties_filesel(struct wmOperatorType *ot, int filter);
/* operator as a python command (resultuing string must be free'd) */
char *WM_operator_pystring(struct wmOperatorType *ot, struct PointerRNA *opptr);
char *WM_operator_pystring(struct wmOperatorType *ot, struct PointerRNA *opptr, int all_args);
void WM_operator_bl_idname(char *to, const char *from);
void WM_operator_py_idname(char *to, const char *from);

@ -103,7 +103,7 @@ void wm_operator_register(bContext *C, wmOperator *op)
/* Report the string representation of the operator */
buf = WM_operator_pystring(op->type, op->ptr);
buf = WM_operator_pystring(op->type, op->ptr, 1);
BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf);
MEM_freeN(buf);

@ -362,7 +362,7 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, P
static void wm_operator_print(wmOperator *op)
{
char *buf = WM_operator_pystring(op->type, op->ptr);
char *buf = WM_operator_pystring(op->type, op->ptr, 1);
printf("%s\n", buf);
MEM_freeN(buf);
}

@ -345,7 +345,7 @@ void WM_operator_bl_idname(char *to, const char *from)
* When calling from an existing wmOperator do.
* WM_operator_pystring(op->type, op->ptr);
*/
char *WM_operator_pystring(wmOperatorType *ot, PointerRNA *opptr)
char *WM_operator_pystring(wmOperatorType *ot, PointerRNA *opptr, int all_args)
{
const char *arg_name= NULL;
char idname_py[OP_MAX_TYPENAME];
@ -355,7 +355,17 @@ char *WM_operator_pystring(wmOperatorType *ot, PointerRNA *opptr)
/* for building the string */
DynStr *dynstr= BLI_dynstr_new();
char *cstring, *buf;
int first_iter=1;
int first_iter=1, ok= 1;
/* only to get the orginal props for comparisons */
PointerRNA opptr_default;
PropertyRNA *prop_default;
char *buf_default;
if(!all_args) {
WM_operator_properties_create(&opptr_default, ot->idname);
}
WM_operator_py_idname(idname_py, ot->idname);
BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
@ -370,13 +380,36 @@ char *WM_operator_pystring(wmOperatorType *ot, PointerRNA *opptr)
buf= RNA_property_as_string(opptr, prop);
BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
ok= 1;
if(!all_args) {
/* not verbose, so only add in attributes that use non-default values
* slow but good for tooltips */
prop_default= RNA_struct_find_property(&opptr_default, arg_name);
if(prop_default) {
buf_default= RNA_property_as_string(&opptr_default, prop_default);
if(strcmp(buf, buf_default)==0)
ok= 0; /* values match, dont bother printing */
MEM_freeN(buf_default);
}
}
if(ok) {
BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf);
first_iter = 0;
}
MEM_freeN(buf);
first_iter = 0;
}
RNA_PROP_END;
if(all_args==0)
WM_operator_properties_free(&opptr_default);
BLI_dynstr_append(dynstr, ")");
cstring = BLI_dynstr_get_cstring(dynstr);