[Bf-blender-cvs] [231eac160ee] master: PyAPI: use C/RNA API for Text.from_string/to_string
Campbell Barton
noreply at git.blender.org
Fri Mar 11 05:26:16 CET 2022
Commit: 231eac160ee394d41c84e0cc36845facb7594ba5
Author: Campbell Barton
Date: Fri Mar 11 14:44:02 2022 +1100
Branches: master
https://developer.blender.org/rB231eac160ee394d41c84e0cc36845facb7594ba5
PyAPI: use C/RNA API for Text.from_string/to_string
Use faster C code for getting the buffer from text.
===================================================================
M release/scripts/modules/bpy_types.py
M source/blender/makesrna/intern/rna_text_api.c
===================================================================
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index 54fcc8faf46..e0e20d0f8c9 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -580,15 +580,6 @@ class MeshPolygon(StructRNA):
class Text(bpy_types.ID):
__slots__ = ()
- def as_string(self):
- """Return the text as a string."""
- return "\n".join(line.body for line in self.lines)
-
- def from_string(self, string):
- """Replace text with this string."""
- self.clear()
- self.write(string)
-
def as_module(self):
import bpy
from os.path import splitext, join
diff --git a/source/blender/makesrna/intern/rna_text_api.c b/source/blender/makesrna/intern/rna_text_api.c
index 67e93add549..0c0b8a85023 100644
--- a/source/blender/makesrna/intern/rna_text_api.c
+++ b/source/blender/makesrna/intern/rna_text_api.c
@@ -32,6 +32,17 @@ static void rna_Text_write(Text *text, const char *str)
WM_main_add_notifier(NC_TEXT | NA_EDITED, text);
}
+static void rna_Text_from_string(Text *text, const char *str)
+{
+ BKE_text_clear(text);
+ BKE_text_write(text, str);
+}
+
+static void rna_Text_as_string(Text *text, int *r_result_len, const char **result)
+{
+ *result = txt_to_buf(text, r_result_len);
+}
+
static void rna_Text_select_set(Text *text, int startl, int startc, int endl, int endc)
{
txt_sel_set(text, startl, startc, endl, endc);
@@ -60,6 +71,16 @@ void RNA_api_text(StructRNA *srna)
parm = RNA_def_string(func, "text", "Text", 0, "", "New text for this data-block");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ func = RNA_def_function(srna, "from_string", "rna_Text_from_string");
+ RNA_def_function_ui_description(func, "Replace text with this string.");
+ parm = RNA_def_string(func, "text", "Text", 0, "", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ func = RNA_def_function(srna, "as_string", "rna_Text_as_string");
+ RNA_def_function_ui_description(func, "Return the text as a string");
+ parm = RNA_def_string(func, "text", "Text", 0, "", "");
+ RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_OUTPUT);
+
func = RNA_def_function(
srna, "is_syntax_highlight_supported", "ED_text_is_syntax_highlight_supported");
RNA_def_function_return(func,
More information about the Bf-blender-cvs
mailing list