Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-07-17 16:26:40 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-07-17 16:26:40 +0400
commita705f6424567873b64f6309311106ec1e918b4e0 (patch)
tree076fc80e7cdd8b19737a01a79c94c687dfca1b0f /source/blender/windowmanager
parent1ef729358517248888073be71ba5d3b6e3d723ee (diff)
python access to operators now hides the _OT_ syntax, eg. SOME_OT_operator -> some.operator
this works for the calling operators from python and using the RNA api. bpy.ops.CONSOLE_exec() is now bpy.ops.console.exec() eg. split.itemO("PARTICLE_OT_editable_set", text="Free Edit") becomes... split.itemO("particle.editable_set", text="Free Edit") For now any operator thats called checks if its missing _OT_ and assumes its python syntax and converts it before doing the lookup. bpy.ops is a python class in release/ui/bpy_ops.py which does the fake submodules and conversion, the C operator api is at bpy.__ops__ personally Id still rather rename C id-names not to contain the _OT_ text which would avoid the conversion, its called a lot since the UI has to convert the operators.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h2
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c58
2 files changed, 56 insertions, 4 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index c72da8fe593..a5e1df1669a 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -149,6 +149,8 @@ void WM_operator_properties_free(struct PointerRNA *ptr);
/* operator as a python command (resultuing string must be free'd) */
char *WM_operator_pystring(struct wmOperator *op);
+void WM_operator_bl_idname(char *to, char *from);
+void WM_operator_bl_idname(char *to, char *from);
/* default operator callbacks for border/circle/lasso */
int WM_border_select_invoke (struct bContext *C, struct wmOperator *op, struct wmEvent *event);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 4dbe26bb79f..57c090f29ed 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -30,6 +30,8 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
#include "DNA_ID.h"
#include "DNA_screen_types.h"
@@ -82,17 +84,21 @@ static ListBase global_ops= {NULL, NULL};
/* ************ operator API, exported ********** */
+
wmOperatorType *WM_operatortype_find(const char *idname, int quiet)
{
wmOperatorType *ot;
+ char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
+ WM_operator_bl_idname(idname_bl, idname);
+
for(ot= global_ops.first; ot; ot= ot->next) {
- if(strncmp(ot->idname, idname, OP_MAX_TYPENAME)==0)
+ if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
return ot;
}
if(!quiet)
- printf("search for unknown operator %s\n", idname);
+ printf("search for unknown operator %s, %s\n", idname_bl, idname);
return NULL;
}
@@ -101,8 +107,11 @@ wmOperatorType *WM_operatortype_exists(const char *idname)
{
wmOperatorType *ot;
+ char idname_bl[OP_MAX_TYPENAME]; // XXX, needed to support python style names without the _OT_ syntax
+ WM_operator_bl_idname(idname_bl, idname);
+
for(ot= global_ops.first; ot; ot= ot->next) {
- if(strncmp(ot->idname, idname, OP_MAX_TYPENAME)==0)
+ if(strncmp(ot->idname, idname_bl, OP_MAX_TYPENAME)==0)
return ot;
}
return NULL;
@@ -152,11 +161,51 @@ int WM_operatortype_remove(const char *idname)
return 1;
}
+/* SOME_OT_op -> some.op */
+void WM_operator_py_idname(char *to, char *from)
+{
+ char *sep= strstr(from, "_OT_");
+ if(sep) {
+ int i, ofs= (sep-from);
+
+ for(i=0; i<ofs; i++)
+ to[i]= tolower(from[i]);
+
+ to[ofs] = '.';
+ BLI_strncpy(to+(ofs+1), sep+4, OP_MAX_TYPENAME);
+ }
+ else {
+ /* should not happen but support just incase */
+ BLI_strncpy(to, from, OP_MAX_TYPENAME);
+ }
+}
+
+/* some.op -> SOME_OT_op */
+void WM_operator_bl_idname(char *to, char *from)
+{
+ char *sep= strstr(from, ".");
+
+ if(sep) {
+ int i, ofs= (sep-from);
+
+ for(i=0; i<ofs; i++)
+ to[i]= toupper(from[i]);
+
+ BLI_strncpy(to+ofs, "_OT_", OP_MAX_TYPENAME);
+ BLI_strncpy(to+(ofs+4), sep+1, OP_MAX_TYPENAME);
+ }
+ else {
+ /* should not happen but support just incase */
+ BLI_strncpy(to, from, OP_MAX_TYPENAME);
+ }
+}
+
/* print a string representation of the operator, with the args that it runs
* so python can run it again */
char *WM_operator_pystring(wmOperator *op)
{
const char *arg_name= NULL;
+ char idname_py[OP_MAX_TYPENAME];
PropertyRNA *prop, *iterprop;
@@ -165,7 +214,8 @@ char *WM_operator_pystring(wmOperator *op)
char *cstring, *buf;
int first_iter=1;
- BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", op->idname);
+ WM_operator_py_idname(idname_py, op->idname);
+ BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py);
iterprop= RNA_struct_iterator_property(op->ptr->type);