diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-09-16 10:02:56 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-09-16 10:02:56 +0400 |
commit | cc100eadc5386a55965bacfa22afbb23c1541be5 (patch) | |
tree | 66556e809571743cd8c5f9877f4c27d107473eb5 /source | |
parent | 8df1bb99f96fe9981a73c131b6637998fca8862f (diff) |
Operator cheat sheet (from the help menu)
writes all operators (including PyOperators) and their default values into a textblock.
Useful for an overview and checking consistancy.
eg. http://www.pasteall.org/7918/python
added rna functions text.clear() and text.write(str)
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_text.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 32 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_text.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_text_api.c | 49 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 54 |
6 files changed, 138 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index bd14053d121..07e05756ea3 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -48,6 +48,8 @@ int reopen_text (struct Text *text); struct Text* add_text (char *file, const char *relpath); struct Text* copy_text (struct Text *ta); void unlink_text (struct Main *bmain, struct Text *text); +void clear_text(struct Text *text); +void write_text(struct Text *text, char *str); char* txt_to_buf (struct Text *text); void txt_clean_text (struct Text *text); @@ -74,7 +76,7 @@ void txt_delete_selected (struct Text *text); void txt_sel_all (struct Text *text); void txt_sel_line (struct Text *text); char* txt_sel_to_buf (struct Text *text); -void txt_insert_buf (struct Text *text, char *in_buffer); +void txt_insert_buf (struct Text *text, const char *in_buffer); void txt_print_undo (struct Text *text); void txt_undo_add_toop (struct Text *text, int op, unsigned int froml, unsigned short fromc, unsigned int tol, unsigned short toc); void txt_do_undo (struct Text *text); diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index dac426de4eb..350b0acba9d 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -130,8 +130,10 @@ undo position static void txt_pop_first(Text *text); static void txt_pop_last(Text *text); static void txt_undo_add_op(Text *text, int op); -static void txt_undo_add_block(Text *text, int op, char *buf); +static void txt_undo_add_block(Text *text, int op, const char *buf); static void txt_delete_line(Text *text, TextLine *line); +static void txt_delete_sel (Text *text); +static void txt_make_dirty (Text *text); /***/ @@ -537,6 +539,30 @@ void unlink_text(Main *bmain, Text *text) text->id.us= 0; } +void clear_text(Text *text) /* called directly from rna */ +{ + int oldstate; + + oldstate = txt_get_undostate( ); + txt_set_undostate( 1 ); + txt_sel_all( text ); + txt_delete_sel(text); + txt_set_undostate( oldstate ); + + txt_make_dirty(text); +} + +void write_text(Text *text, char *str) /* called directly from rna */ +{ + int oldstate; + + oldstate = txt_get_undostate( ); + txt_insert_buf( text, str ); + txt_move_eof( text, 0 ); + txt_set_undostate( oldstate ); + + txt_make_dirty(text); +} /*****************************/ /* Editing utility functions */ @@ -1315,7 +1341,7 @@ char *txt_sel_to_buf (Text *text) return buf; } -void txt_insert_buf(Text *text, char *in_buffer) +void txt_insert_buf(Text *text, const char *in_buffer) { int i=0, l=0, j, u, len; TextLine *add; @@ -1544,7 +1570,7 @@ static void txt_undo_add_op(Text *text, int op) text->undo_buf[text->undo_pos+1]= 0; } -static void txt_undo_add_block(Text *text, int op, char *buf) +static void txt_undo_add_block(Text *text, int op, const char *buf) { int length; diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 7de80843f27..4d8ef7082b6 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -205,6 +205,7 @@ void RNA_api_main(struct StructRNA *srna); void RNA_api_mesh(struct StructRNA *srna); void RNA_api_object(struct StructRNA *srna); void RNA_api_scene(struct StructRNA *srna); +void RNA_api_text(struct StructRNA *srna); void RNA_api_ui_layout(struct StructRNA *srna); void RNA_api_wm(struct StructRNA *srna); diff --git a/source/blender/makesrna/intern/rna_text.c b/source/blender/makesrna/intern/rna_text.c index cd39c317bc5..22cf7e7aeae 100644 --- a/source/blender/makesrna/intern/rna_text.c +++ b/source/blender/makesrna/intern/rna_text.c @@ -223,6 +223,8 @@ static void rna_def_text(BlenderRNA *brna) prop= RNA_def_property(srna, "markers", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "TextMarker"); RNA_def_property_ui_text(prop, "Markers", "Text markers highlighting part of the text."); + + RNA_api_text(srna); } void RNA_def_text(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_text_api.c b/source/blender/makesrna/intern/rna_text_api.c new file mode 100644 index 00000000000..b048a6b59d0 --- /dev/null +++ b/source/blender/makesrna/intern/rna_text_api.c @@ -0,0 +1,49 @@ +/** + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdlib.h> +#include <stdio.h> + + +#include "RNA_define.h" +#include "RNA_types.h" + +#ifdef RNA_RUNTIME + +#else + +void RNA_api_text(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *prop; + + func= RNA_def_function(srna, "clear", "clear_text"); + RNA_def_function_ui_description(func, "clear the text block."); + + func= RNA_def_function(srna, "write", "write_text"); + RNA_def_function_ui_description(func, "write text at the cursor location and advance to the end of the text block."); + prop= RNA_def_string(func, "text", "Text", 0, "", "New text for this datablock."); + RNA_def_property_flag(prop, PROP_REQUIRED); +} + +#endif diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 0c1d974c978..69a7e554452 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -118,6 +118,58 @@ static PyObject *pyop_call( PyObject * self, PyObject * args) Py_RETURN_NONE; } +static PyObject *pyop_as_string( PyObject * self, PyObject * args) +{ + wmOperatorType *ot; + PointerRNA ptr; + + char *opname; + PyObject *kw= NULL; /* optional args */ + int all_args = 1; + int error_val= 0; + + char *buf; + PyObject *pybuf; + + bContext *C = BPy_GetContext(); + + if (!PyArg_ParseTuple(args, "s|O!i:bpy.__ops__.as_string", &opname, &PyDict_Type, &kw, &all_args)) + return NULL; + + ot= WM_operatortype_find(opname, TRUE); + + if (ot == NULL) { + PyErr_Format( PyExc_SystemError, "bpy.__ops__.as_string: operator \"%s\"could not be found", opname); + return NULL; + } + + /* WM_operator_properties_create(&ptr, opname); */ + /* Save another lookup */ + RNA_pointer_create(NULL, ot->srna, NULL, &ptr); + + if(kw && PyDict_Size(kw)) + error_val= pyrna_pydict_to_props(&ptr, kw, 0, "Converting py args to operator properties: "); + + if (error_val==0) + buf= WM_operator_pystring(C, ot, &ptr, all_args); + + WM_operator_properties_free(&ptr); + + if (error_val==-1) { + return NULL; + } + + if(buf) { + pybuf= PyUnicode_FromString(buf); + MEM_freeN(buf); + } + else { + pybuf= PyUnicode_FromString(""); + } + + return pybuf; +} + static PyObject *pyop_dir(PyObject *self) { PyObject *list = PyList_New(0), *name; @@ -162,6 +214,7 @@ static PyObject *pyop_getrna(PyObject *self, PyObject *value) PyObject *BPY_operator_module( void ) { static PyMethodDef pyop_call_meth = {"call", (PyCFunction) pyop_call, METH_VARARGS, NULL}; + static PyMethodDef pyop_as_string_meth ={"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL}; static PyMethodDef pyop_dir_meth = {"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL}; static PyMethodDef pyop_getrna_meth = {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL}; static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL}; @@ -171,6 +224,7 @@ PyObject *BPY_operator_module( void ) PyDict_SetItemString(PySys_GetObject("modules"), "bpy.__ops__", submodule); PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) ); + PyModule_AddObject( submodule, "as_string",PyCFunction_New(&pyop_as_string_meth,NULL) ); PyModule_AddObject( submodule, "dir", PyCFunction_New(&pyop_dir_meth, NULL) ); PyModule_AddObject( submodule, "get_rna", PyCFunction_New(&pyop_getrna_meth, NULL) ); PyModule_AddObject( submodule, "add", PyCFunction_New(&pyop_add_meth, NULL) ); |